Project Euler Problem 53

//

I wrote a bunch of these but never posted them up, so I'm just uploading them in bulk now. Not much to say about them at this point.

  1. #!/usr/bin/python
  2.  
  3. import math
  4.  
  5. memo = {}
  6.  
  7. def c(n, r):
  8.     if not n in memo:
  9.         memo[n] = math.factorial(n)
  10.    
  11.     if not r in memo:
  12.         memo[r] = math.factorial(r)
  13.  
  14.     if not n-r in memo:
  15.         memo[n-r] = math.factorial(n-r)
  16.  
  17.     n_r = memo[n-r]
  18.     n   = memo[n]
  19.     r   = memo[r]
  20.     return n/(r*(n_r))
  21.  
  22. count = 0
  23. for n in range(23, 101):
  24.     for r in range(1, n):
  25.         if c(n, r) > 1000000:
  26.             count+=1
  27. print count