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="Jon Clements, post: 3990964"] Even though you've worked it out -- a couple of tips: numpy/scipy etc... are quite useful for Euler :) They contain a function to do factorials (and loads more). This to one of the readable uses of 'reduce': def fac(n): reduce(operator.mul, xrange(2, n+1), n) The builtin str object can take integers and return it as a string. def decimals(x): return map(int, str(x)) decimals(145) == [1, 4, 5] And join the two: print sum(fac(n) for n in decimals(145)) You might also find it useful to write generators (esp. for primes and factorials). Cheers, Jon. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Sum of the factorial of the digits of a number - wierd behaviour
Top