Created
December 13, 2011 01:11
-
-
Save jakedobkin/1469926 to your computer and use it in GitHub Desktop.
Euler 53: Calculating Combinations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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