2021-07-04 03:28:47 +02:00
|
|
|
from math import factorial
|
2021-07-04 02:34:45 +02:00
|
|
|
from itertools import combinations
|
|
|
|
|
|
|
|
|
2021-07-04 03:28:47 +02:00
|
|
|
def product(xs):
|
2021-07-04 02:34:45 +02:00
|
|
|
r = 1
|
|
|
|
for x in xs:
|
|
|
|
r *= x
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
|
|
def sub_odds(n_blue, n_total):
|
2021-07-04 03:28:47 +02:00
|
|
|
odds = [n for n in range(1, n_total + 1)]
|
|
|
|
return sum(map(product, combinations(odds, n_total - n_blue)))
|
2021-07-04 02:34:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def euler_121():
|
|
|
|
n_turns = 15
|
|
|
|
n_to_win = n_turns // 2 + 1
|
2021-07-04 03:28:47 +02:00
|
|
|
odds = sum([sub_odds(n_blue, n_turns)
|
|
|
|
for n_blue in range(n_to_win, n_turns + 1)])
|
|
|
|
return int(factorial(n_turns + 1) / odds)
|
2021-07-04 02:34:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
solution = euler_121()
|
|
|
|
print("e121.py: " + str(solution))
|
|
|
|
assert(solution == 2269)
|
|
|
|
|