Skip to content

Instantly share code, notes, and snippets.

@emadshaaban92
Created February 21, 2014 18:51
Show Gist options
  • Save emadshaaban92/9140730 to your computer and use it in GitHub Desktop.
Save emadshaaban92/9140730 to your computer and use it in GitHub Desktop.
MAXN = 100
MAXNCR = 1000000
import time
before = time.time()
def nCrs(maxn):
n = r = ncr = 1
while n <= maxn :
if n == r :
n += 1
r, ncr = 1, n
else :
r += 1
ncr = ncr / r * (n-r+1)
yield ncr
ncrs_above_max = filter(lambda x : x > MAXNCR, nCrs(MAXN))
print len(ncrs_above_max)
print time.time()-before
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment