48 lines
899 B
Python
48 lines
899 B
Python
import sys
|
|
from pprint import pp
|
|
from collections import Counter
|
|
|
|
input_f = sys.argv[1]
|
|
|
|
cards = {}
|
|
|
|
with open(input_f) as file:
|
|
for line in file:
|
|
tmp = line.split()
|
|
cards[tmp[0]] = int(tmp[1])
|
|
|
|
def value(card):
|
|
return 'AKQJT98765432'.index(card)
|
|
|
|
def score(card):
|
|
tmp = sorted(list(Counter(card).values()),reverse=True)
|
|
if tmp == [5]:
|
|
return 1
|
|
elif tmp == [4,1]:
|
|
return 2
|
|
elif tmp == [3,2]:
|
|
return 3
|
|
elif tmp == [3,1,1]:
|
|
return 4
|
|
elif tmp == [2,2,1]:
|
|
return 5
|
|
elif tmp == [2,1,1,1]:
|
|
return 6
|
|
elif tmp == [1,1,1,1,1]:
|
|
return 7
|
|
|
|
|
|
scores = []
|
|
tmp = []
|
|
for i in cards:
|
|
tmp.append(tuple((score(i),tuple(value(c) for c in i),i)))
|
|
|
|
|
|
tmp = sorted(tmp, key=lambda x: (x[0], x[1]),reverse=True)
|
|
result = 0
|
|
|
|
for idx,i in enumerate(tmp):
|
|
result += cards[i[2]]*(idx+1)
|
|
print()
|
|
print(result)
|