Skip to content

Instantly share code, notes, and snippets.

@EightAndAHalfTails
Last active August 29, 2015 14:08
Show Gist options
  • Save EightAndAHalfTails/7fb7e31da36e9f9e5250 to your computer and use it in GitHub Desktop.
Save EightAndAHalfTails/7fb7e31da36e9f9e5250 to your computer and use it in GitHub Desktop.
size = 9
top = "63742AKRT"
bot = "3547RAQKT"
def score(t, b):
#print t
#print b
# No remaining cards to match
if len(t) == 0 or len(b) == 0:
#print "End"
return 0
# Only one possible pairing
elif len(t) == 1 and len(b) == 1:
if t != b and t != 'R' and b != 'R':
#print "Mismatch"
return 0
elif t == b == 'R':
#print "Joker Match"
return 50
else:
#print "Match"
return{
'A' : 20,
'2' : 2,
'3' : 3,
'4' : 4,
'5' : 5,
'6' : 6,
'7' : 7,
'8' : 8,
'9' : 9,
'T' : 10,
'J' : 15,
'Q' : 15,
'K' : 15,
}[t if t != 'R' else b]
# Next card on top is Joker -> choose whether to discard bottom or match.
elif t[0] == 'R':
#print "Discard"
s1 = score(t, b[1:])
#print "Match"
s2 = score(t[0], b[0]) + score(t[1:], b[1:])
return max(s1, s2)
# Next card on bottom is Joker -> choose whether to discard top or match.
elif b[0] == 'R':
#print "Discard"
s1 = score(t[1:], b)
#print "Match"
s2 = score(t[0], b[0]) + score(t[1:], b[1:])
return max(s1, s2)
# First cards match -> always better to do so
elif t[0] == b[0]:
#print "Match"
return score(t[0], b[0]) + score(t[1:], b[1:])
# No matches possible -> must discard either top or bottom
else:
#print "Discard top"
s1 = score(t[1:], b)
#print "Discard bot"
s2 = score(t, b[1:])
#print s1, s2
return max(s1, s2)
print 2*score(top, bot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment