Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
29-liner: lambda classmate solution in Clear category for Magic with 5 cards by przemyslaw.daniel
class Card:
RANKS = 'A 2 3 4 5 6 7 8 9 10 J Q K'.split()
SUITS = '♣♦♥♠'
__init__ = lambda self, rank, suit: \
vars(self).update({'rank': self.RANKS.index(rank), 'suit': self.SUITS.index(suit)})
__lt__ = lambda self, other: (self.rank, self.suit) < (other.rank, other.suit)
__repr__ = lambda self: f'{self.RANKS[self.rank]} {self.SUITS[self.suit]}'
__rshift__ = lambda self, value: \
Card(self.RANKS[(self.rank + value) % len(self.RANKS)], self.SUITS[self.suit])
distance = lambda self, other: (self.rank - other.rank) % len(self.RANKS)
order = lambda c1, c2, c3: [[c3, c1, c2], [c3, c2, c1], [c2, c1, c3],
[c2, c3, c1], [c1, c2, c3], [c1, c3, c2]]
def magician(*cards, n=1):
cards = [Card(*c.split()) for c in cards]
base = cards.pop((n-1) % 4)
result = Card.order(*sorted(cards)).index(cards)+1
return str(base >> result)
def bot(*cards, n=1):
cards = [Card(*c.split()) for c in cards]
most = max(suits:=[c.suit for c in cards], key=suits.count)
a, b, *_ = [c for c in cards if c.suit == most]
result = sorted(set(cards) - {a, b})
result = Card.order(*result)[min(a.distance(b), b.distance(a))-1]
result.insert((n-1) % 4, [a, b][a.distance(b) < b.distance(a)])
return map(str, result)
Jan. 1, 2020
Comments: