Comment detail
ポーカーの役判定 (Nested Flatten)こういうときに便利なスライスの記法を思い出したのと 文字の置換も必要なかったので、ちょっと書き直しました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import sys
def f(c):
s = len(set(c[0::2])) == 1
r = ''.join(sorted(c[1::2]))
l = len(set(r))
if l == 2:
print 'Four of a kind' if r.count(r[0]) in [1,4] else 'Full house'
elif l == 5:
if '2345A23456789T789JT89JQT9JKQTAJKQT'.find(r) >= 0:
print ('Royal flush' if r == 'AJKQT' else 'Straight flush') if s else 'Straight'
elif s:
print 'Flush'
else:
print 'No pair'
elif s:
print 'Flush'
elif l == 3:
print 'Three of a kind' if [i for i in set(r) if r.count(i) >= 3] else 'Two pair'
else:
print 'One pair'
f(sys.argv[1])
|





匿名
#5185()
[
Python
]
Rating3/3=1.00
Rating3/3=1.00-0+
1 reply [ reply ]