n! means n x (n − 1) x … x 3 x 2 x 1
Find the sum of the digits in the number 100!
Another one that had previously foxed me in CFML (on Coldfusion 5), but was simple in Python:
limit = 100 total = 0 product = 1 for i in range(limit, 1, -1): product = product * i prodStr = repr(product) length = len(prodStr) for i in range(length): total = total + int(prodStr[i]) print(total)
Similar code to problem 16. I work out 100!, then I turn the number into a string, work out the length of the string, loop through the string, adding up each digit.
This is only my second bit of Python ever, so I’d love some feedback from anyone with more experience of the language.