How to Cheat with Math – The Russian Cards Problem(winux-arch.github.io) |
How to Cheat with Math – The Russian Cards Problem(winux-arch.github.io) |
import itertools import functools
for eve_card in range(7): cards_left = set(range(7)) cards_left.remove(eve_card)
mod_to_cards = [[], [], [], [], [], [], []]
for c in itertools.combinations(cards_left, 3):
mod = sum(c) % 7
mod_to_cards[mod].append(set(c))
for combs in mod_to_cards:
i = functools.reduce(lambda x, y: x.intersection(y), combs)
if len(i) != 0:
print("intersection", eve_card, combs, i)
u = functools.reduce(lambda x, y: x.union(y), combs)
if len(u) != 6:
print("union", eve_card, combs, u)Problem solved!