Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Try to remove from deck with sorted hand solution in Clear category for Card Game by Phil15
def cards(deck_size: int, hand: list) -> bool:
"""Try to remove highest pair possible in deck for all card in sorted hand."""
hand.sort()
deck = {(card, card+1) for card in range(deck_size)}
while hand: # "It's easier to ask for forgiveness than permission."
card = hand.pop()
try:
deck.remove((card, card+1))
except KeyError:
try:
deck.remove((card-1, card))
except KeyError:
return False
return True
Sept. 22, 2018
Comments: