If you're new, I take this opportunity by looking at the Euler nature project to give an encoding alternative that is self-contained and demonstrates a matching table approach to speed up recursive functions and save dictionary responses and use len as a counter.
I hope 4075 is the right answer!
from __future__ import division factorials={} def factorial(n): """ factorial from lookup table ready or generate it to there """ if n not in factorials: factorials[n]=1 if n==0 else n*factorial(n-1) return factorials[n] def ncr(n,r): return (factorial(n)/(factorial(r)*factorial(nr))) bigones= [(x,y) for x in range(1,1+100) for y in range(x) if ncr(x,y) > 1000000 ] print len(bigones)
Tony Veijalainen Jul 29 '10 at 10:28 2010-07-29 10:28
source share