Created
June 22, 2011 16:57
-
-
Save diogobaeder/1040553 to your computer and use it in GitHub Desktop.
Soma dos dígitos do fatorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import factorial | |
from operator import add | |
def factorial_digits_sum(number): | |
return reduce( | |
add, | |
[int(string_digit) for string_digit in str( | |
factorial(number) | |
)] | |
) | |
if __name__ == '__main__': | |
assert factorial_digits_sum(1) == 1 | |
assert factorial_digits_sum(2) == 2 | |
assert factorial_digits_sum(3) == 6 | |
assert factorial_digits_sum(4) == 6 | |
print factorial_digits_sum(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment