Project Euler Factorial Digit Sum

Factorial

The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 4! = 4 * 3 * 2 * 1.

Instructions

  • Write a method, factorial, that returns the factorial of the number passed in. It should work for arbitrarily large n (at least up to n = 100).

    Example

    factorial(4) would return 24:

    • 4 * 3 -> 12
    • 4 * 3 * 2 -> 24
    • 4 * 3 * 2 * 1 -> 24
  • Once the first test passes, write a method sum_of_digits that returns the sum of the digits of the number passed in: sum_of_digits(16) => 7.

  • Finally, using the first two methods you wrote as helpers, define a factorial_digit_sum method and make the last test pass.

Source

View Project Euler Factorial Digit Sum on Learn.co and start learning to code for free.