static void Main(string[] args) { Stopwatch sw = new Stopwatch(); sw.Start(); Factorial f = new Factorial(); long sum = 0; for (int n = 3; n < UpperBound; n++) { long total = 0; long remainder = n; while (remainder > 0) { long digit = remainder % 10; total += f.CalculateFactorial(digit); remainder /= 10; } if (total == n) { sum += total; Console.WriteLine("Found {0}", n); } } sw.Stop(); Console.WriteLine("Sum {0} in {1}", sum, sw.ElapsedMilliseconds); Console.ReadKey(); }
public void CalculateFactorialOf5() { Factorial f = new Factorial(); Assert.AreEqual(120, f.CalculateFactorial(5)); }
public void CalculateFactorialOf20() { Factorial f = new Factorial(); Assert.AreEqual(2432902008176640000, f.CalculateFactorial(20)); }
public void CalculateFactorialOf3WithCache() { Factorial f = new Factorial(); Assert.AreEqual(6, f.CalculateFactorial(3)); Assert.AreEqual(6, f.CalculateFactorial(3)); }
public void CalculateFactorialOf1() { Factorial f = new Factorial(); Assert.AreEqual(1, f.CalculateFactorial(1)); }