-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path053.py
More file actions
45 lines (31 loc) · 1.04 KB
/
053.py
File metadata and controls
45 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Problem 53
==========
There are exactly ten ways of selecting three from five, 12345:
123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
In combinatorics, we use the notation, ^5C[3] = 10.
In general,
^nC[r] = n! ,where r ≤ n, n! = n×(n−1)×...×3×2×1, and 0! = 1.
r!(n−r)!
It is not until n = 23, that a value exceeds one-million: ^23C[10] =
1144066.
How many, not necessarily distinct, values of ^nC[r], for 1 ≤ n ≤ 100,
are greater than one-million?
Answer: e3b21256183cf7c2c7a66be163579d37
"""
from common import check
from itertools import combinations
from math import factorial
PROBLEM_NUMBER = 53
ANSWER_HASH = "e3b21256183cf7c2c7a66be163579d37"
def choose(n, r):
n_f = factorial(n)
r_f = factorial(r)
nmr_f = factorial(n-r)
return n_f / (r_f * nmr_f)
total = 0
for n in range(1, 101):
for r in range(1, n):
if choose(n, r) > 1_000_000:
total += 1
check(total, PROBLEM_NUMBER, ANSWER_HASH)