Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Magic with 5 cards solution in Clear category for Magic with 5 cards by JimmyCarlos
RANKS = 'A 2 3 4 5 6 7 8 9 10 J Q K'.split()
DECK = [f'{r} {s}' for r in RANKS for s in '♣♦♥♠']
def bot(*cards, n=1):
"""Determine four cards the bot has to say to the magician."""
A,B = [(a,b) for a in cards for b in cards if a[0] != b[0] and a[-1] == b[-1]][0]
delta = (RANKS.index(B.split()[0]) - RANKS.index(A.split()[0])) % 13
if delta >= 7: A,B,delta = B,A,(-delta)%13
C1,C2,C3 = sorted([card for card in cards if card not in (A,B)],key=lambda x:DECK.index(x))
cardsToReturn = ["*",[C3,C1,C2],[C3,C2,C1],[C2,C1,C3],[C2,C3,C1],[C1,C2,C3],[C1,C3,C2]][delta]
cardsToReturn.insert((n-1)%4,A)
return cardsToReturn
def magician(*cards, n=1):
"""Determine the fifth card with only four cards."""
A = cards[(n-1)%4]
C = [card for card in cards if card != A]
C1,C2,C3 = sorted(C,key=lambda x:DECK.index(x))
delta = ["*",[C3,C1,C2],[C3,C2,C1],[C2,C1,C3],[C2,C3,C1],[C1,C2,C3],[C1,C3,C2]].index(C)
missingRank = RANKS[(RANKS.index(A.split()[0]) + delta) % 13]
missingSuit = A[-1]
return f"{missingRank} {missingSuit}"
Dec. 31, 2019
Comments: