2017-08-16 22:54:45 +08:00

50 lines
1.2 KiB
Python

def is_order(num):
mini = min(num)
return list(range(mini, mini + len(num))) == list(num)
def anlz_num(num):
anlz = {1: [], 2: [], 3: [], 4: []}
for n in set(num):
anlz[num.count(n)].append(n)
if len(anlz[4]):
return (8, max(anlz[4]))
if len(anlz[3]):
if len(anlz[2]):
return (7, max(anlz[3]))
else:
return (4, max(anlz[3]))
if len(anlz[2]) == 2:
return (3, max(anlz[2]))
elif len(anlz[2]):
return (2, max(anlz[2]))
return (1, max(anlz[1]))
def score(p):
follow = set(p[1::3])
number = list(sorted(map(lambda x: '23456789TJQKA'.find(x), p[0::3])))
if is_order(number):
if len(follow) == 1:
return (9, max(number))
else:
return (5, max(number))
if len(follow) == 1:
return (6, max(number))
return anlz_num(number)
def seek_file(fn):
with open(fn, 'r') as f:
l = f.readline()
while l:
yield l[:14], l[15:-1]
l = f.readline()
def judge():
count = 0
for p, q in seek_file('../resource/poker.txt'):
if score(p) > score(q):
count += 1
return count
print(judge())