Skip to content

Commit eb40f43

Browse files
Solution to Problem 53
1 parent 68e5bb4 commit eb40f43

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Project Euler/Problem 53/sol1.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#-.- coding: latin-1 -.-
2+
from __future__ import print_function
3+
from math import factorial
4+
'''
5+
Combinatoric selections
6+
Problem 53
7+
8+
There are exactly ten ways of selecting three from five, 12345:
9+
10+
123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
11+
12+
In combinatorics, we use the notation, 5C3 = 10.
13+
14+
In general,
15+
16+
nCr = n!/(r!(n−r)!),where r ≤ n, n! = n×(n−1)×...×3×2×1, and 0! = 1.
17+
It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.
18+
19+
How many, not necessarily distinct, values of nCr, for 1 ≤ n ≤ 100, are greater than one-million?
20+
'''
21+
try:
22+
xrange #Python 2
23+
except NameError:
24+
xrange = range #Python 3
25+
26+
def combinations(n, r):
27+
return factorial(n)/(factorial(r)*factorial(n-r))
28+
29+
total = 0
30+
31+
for i in xrange(1, 101):
32+
for j in xrange(1, i+1):
33+
if combinations(i, j) > 1e6:
34+
total += 1
35+
36+
print(total)

0 commit comments

Comments
 (0)