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 |
from itertools import permutations from partition_unique import partition_unique # the player's labels and the cards A, B, C, D = players = range(4) cards = range(1, 7) # given the 4-tuple of cards held by A, B, C and D, return the # card held by player P def card(P): return lambda t: t[P] # given the 4-tuple of cards held by A, B, C and D, return the # 3-tuple of cards seen by player P def seen(P): return lambda t: tuple(x for x in t if x != t[P]) # find the set of all possible four card arrangements for (A, B, C, D) ca_abcd = set(permutations(cards, 4)) # find the set of arrangements for which A can declare a sum of six ca_abcd = set(x for x in ca_abcd if 6 in (x[B] + x[C], x[B] + x[D], x[C] + x[D])) # remove arrangements for which any player can announce their number at this point t = set() for P in players: t.update(partition_unique(ca_abcd, seen(P), card(P))[0]) ca_abcd.difference_update(t) # find the set of arrangements for which B can declare a sum of five ca_abcd = set(x for x in ca_abcd if 5 in (x[A] + x[C], x[A] + x[D], x[C] + x[D])) # remove arrangements for which any player can announce their number at this point t = set() for P in players: t.update(partition_unique(ca_abcd, seen(P), card(P))[0]) ca_abcd.difference_update(t) # output arrangements that remain unresolved for s in ca_abcd: t = set(cards).difference(s) print(f'(A, B) = ({s[A]}, {s[B]}), (C, D) = ({s[C]}, {s[D]}), table = {t}') |