Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Sum of the factorial of the digits of a number - wierd behaviour
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="SiWi, post: 3990846"] Dear python community, I've got a wierd problem and I hope you can help me out at it. I wrote the following code to find the Sum of the factorial of the digits of a number (this is for Project Euler 74): def fac(n): x=1 for i in range(2,n+1): x*=i return x t=tuple(fac(n) for n in range(1,10)) def decimals(x): i=1 d=[] while x>0: d.append(x%10) x=x/10 return d def sumfac(x): return sum(t[n-1] for n in decimals(x)) The problem is that i get the following results, for which I can't see any reason: sumfac(145)->145 (1!+4!+5!=1 + 24 +120 = 145) - ok sumfac(1454)-> 169 - ok sumfac(45362) -> 872 - ok sumfac(363600) -> 727212 - wrong, should be1454 Greetings, SiWi. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Sum of the factorial of the digits of a number - wierd behaviour
Top