Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import itertools
import time
def finish_off(cards, deck1, deck2):
while len(deck1) != 0 and len(deck2) != 0:
try:
cards.insert(0, deck1.pop())
cards.insert(0, deck2.pop())
except IndexError:
pass
def clean_cards(old_cards):
new_cards = []
for card in old_cards:
card = card.rstrip("SDHC")
if card == "K":
card = 13
elif card == "Q":
card = 12
elif card == "J":
card = 11
elif card == "A":
card = 14
else:
card = int(card)
new_cards.append(card)
return new_cards
my_cards = clean_cards(raw_input().split(" "))
their_cards = clean_cards(raw_input().split(" "))
my_cards.reverse()
their_cards.reverse()
while len(my_cards) > 0 and len(their_cards) > 0:
my_card = my_cards.pop()
their_card = their_cards.pop()
if my_card > their_card:
my_cards.insert(0, my_card)
my_cards.insert(0, their_card)
elif their_card > my_card:
their_cards.insert(0, their_card)
their_cards.insert(0, my_card)
else:
my_ties = []
their_ties = []
while True:
try:
my_ties.insert(0, my_cards.pop())
my_ties.insert(0, my_cards.pop())
my_ties.insert(0, my_cards.pop())
my_ties.insert(0, my_cards.pop())
their_ties.insert(0, their_cards.pop())
their_ties.insert(0, their_cards.pop())
their_ties.insert(0, their_cards.pop())
their_ties.insert(0, their_cards.pop())
except IndexError:
break
if my_ties[0] > their_ties[0]:
finish_off(my_cards, my_ties, their_ties)
break
elif their_ties[0] > my_ties[0]:
finish_off(their_cards, their_ties, my_ties)
break
if len(my_cards) > 0:
print "I win!"
else:
print "I lose...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.