Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 13, 2011 01:11
Show Gist options
  • Select an option

  • Save jakedobkin/1469926 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1469926 to your computer and use it in GitHub Desktop.
Euler 53: Calculating Combinations
# http://projecteuler.net/problem=53
# python has a lot of useful math functions!
import math
# it also has itertools, which can give us the exact combinations of a set
# but here we're just calculating numbers, so i'll use the math factorial function
count = 0
for n in range (2,101):
for r in range (1,n):
# print "----------",n,r
nCr = math.factorial(n) / (math.factorial(r)*math.factorial(n-r))
if nCr > 1000000:
# print nCr
count += 1
print count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment