from math import factorial from itertools import combinations def product(xs): r = 1 for x in xs: r *= x return r def sub_odds(n_blue, n_total): odds = [n for n in range(1, n_total + 1)] return sum(map(product, combinations(odds, n_total - n_blue))) def euler_121(): n_turns = 15 n_to_win = n_turns // 2 + 1 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) if __name__ == "__main__": solution = euler_121() print("e121.py: " + str(solution)) assert(solution == 2269)