using System;
using System.Diagnostics;
using System.Numerics;

namespace ConsoleApp38
{
  class Program
  {
    static void Main(string[] args)
    {
      Stopwatch clock = Stopwatch.StartNew();
      int numberOfLetters = 0;

      for (int number = 1; number < 1001; number++)
        numberOfLetters += CountLetters(number);

      clock.Stop();
      Console.WriteLine("Number of letters: " + numberOfLetters);
      Console.WriteLine("Answer reached in {0} ms.", clock.ElapsedMilliseconds);
      Console.ReadKey();

    }

    static int CountLetters(int number)
    {
      string[] units = new string[] { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
      string[] units10 = new string[] { "", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
      string[] tens = new string[] { "", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

      if (number == 1000)
        return "onethousand".Length;
      string numberString = "";
      int[] digits = new int[3];

      digits[0] = number / 100;
      digits[1] = (number / 10) % 10;
      digits[2] = number % 10;

      if (digits[0] > 0)
      {
        numberString += units[digits[0]] + "hundred";
        if (digits[1] != 0 || digits[2] != 0)
          numberString += "and";
      }

      if (digits[1] == 1)
      {
        if (digits[2] == 0)
          numberString += tens[digits[1]];
        else
          numberString += units10[digits[2]];
      }
      else
        numberString += tens[digits[1]] + units[digits[2]];

      return numberString.Length;

    }
  }
}


{'avg_line_length': 26.919354838709676, 'max_line_length': 148, 'alphanum_fraction': 0.5500299580587178, 'licenses': ['MIT'], 'repository_name': 'hraverkar/Coding_Problem', 'path': 'Eular Problem/EularProblem-17.cs', 'size': 1669, 'lang': 'C#'}