Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Magic with 5 cards by kazuki.h
RANKS = tuple('A 2 3 4 5 6 7 8 9 10 J Q K'.split())
SUITS = tuple('♣♦♥♠')
from random import choice
import math
import itertools
deck = [f'{r} {s}' for r in RANKS for s in SUITS]
def bot(*cards, n = 1):
n = (n - 1) % 4
cards_info = [tuple(card.split()) for card in cards]
card_pairs = list(itertools.combinations(cards_info, 2))
for card_pair in card_pairs:
card_1 = card_pair[0]
card_2 = card_pair[1]
if card_1[1] == card_2[1]:
card_A = card_1
card_B = card_2
card_A_rank = RANKS.index(card_A[0])
card_B_rank = RANKS.index(card_B[0])
distance = (card_A_rank - card_B_rank) % 13
if distance > 13 - distance:
suit_info_card=' '.join(card_A)
delta = 13 - distance
else:
suit_info_card=' '.join(card_B)
delta = distance
break
remaining_cards = [card for card in cards_info if card != card_A and card != card_B]
remaining_cards_join = [' '.join(card) for card in remaining_cards]
remaining_cards_sorted = sorted(remaining_cards_join, key = lambda card: deck.index(card))
result = []
if delta == 5 or delta == 6:
first_card = remaining_cards_sorted[0]
result.append(first_card)
del remaining_cards_sorted[0]
elif delta == 3 or delta == 4:
first_card = remaining_cards_sorted[1]
result.append(first_card)
del remaining_cards_sorted[1]
else:
first_card = remaining_cards_sorted[2]
result.append(first_card)
del remaining_cards_sorted[2]
if delta%2 == 1:
result += remaining_cards_sorted
else:
remaining_cards_sorted.reverse()
result += remaining_cards_sorted
result.insert(n, suit_info_card)
return result
def magician(*cards, n=1):
n = (n - 1) % 4
cards_index = [deck.index(card) for card in cards]
suit = SUITS[cards_index[n] % 4]
card_B_rank = math.ceil(cards_index[n] // 4) + 1
del cards_index[n]
origin_cards = cards_index
cards_sorted = sorted(cards_index)
first = cards_sorted.index(origin_cards[0])
second = cards_sorted.index(origin_cards[1])
third = cards_sorted.index(origin_cards[2])
if second < third:
delta = [1,3,5]
else:
delta = [2,4,6]
delta = delta[2 - first]
rank = (card_B_rank + delta) % 13
rank = RANKS[rank - 1]
return rank+" "+suit
Jan. 27, 2020
Comments: