|
|
|
@ -1,48 +1,58 @@ |
|
|
|
|
hands = [l.split() for l in open("input.txt", 'r').read().splitlines()] |
|
|
|
|
sort1 = [[] for i in range(7)] |
|
|
|
|
sort2 = [[] for i in range(7)] |
|
|
|
|
|
|
|
|
|
for hand in hands: |
|
|
|
|
handSet = {} |
|
|
|
|
for card in set(hand[0]): |
|
|
|
|
handSet[card] = hand[0].count(card) |
|
|
|
|
handSetLen = len(handSet) |
|
|
|
|
jCount = hand[0].count('J') |
|
|
|
|
|
|
|
|
|
if handSetLen == 1: |
|
|
|
|
sort1[0].append(hand) # 5oak |
|
|
|
|
sort2[0].append(hand) |
|
|
|
|
elif handSetLen == 2: |
|
|
|
|
for card in handSet: |
|
|
|
|
if handSet[card] == 4: |
|
|
|
|
sort1[1].append(hand) # 4oak |
|
|
|
|
sort2[0 if jCount > 0 else 1].append(hand) |
|
|
|
|
break |
|
|
|
|
elif handSet[card] == 3: |
|
|
|
|
sort1[2].append(hand) # fh |
|
|
|
|
sort2[0 if jCount > 0 else 2].append(hand) |
|
|
|
|
break |
|
|
|
|
elif handSetLen == 3: |
|
|
|
|
for card in handSet: |
|
|
|
|
if handSet[card] == 3: |
|
|
|
|
sort1[3].append(hand) # 3oak |
|
|
|
|
sort2[1 if jCount > 0 else 3].append(hand) |
|
|
|
|
break |
|
|
|
|
elif handSet[card] == 2: |
|
|
|
|
sort1[4].append(hand) # 2pair |
|
|
|
|
sort2[(2 if jCount == 1 else 1) if jCount > 0 else 4].append(hand) |
|
|
|
|
break |
|
|
|
|
elif handSetLen == 4: |
|
|
|
|
for card in handSet: |
|
|
|
|
if handSet[card] == 2: |
|
|
|
|
sort1[5].append(hand) # 1pair |
|
|
|
|
sort2[3 if jCount > 0 else 5].append(hand) |
|
|
|
|
break |
|
|
|
|
elif handSetLen == 5: |
|
|
|
|
for card in handSet: |
|
|
|
|
sort1[6].append(hand) # highcard |
|
|
|
|
break |
|
|
|
|
sort2[5 if jCount > 0 else 6].append(hand) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cards1 = "AKQJT98765432"[::-1] |
|
|
|
|
cards2 = "AKQT98765432J"[::-1] |
|
|
|
|
|
|
|
|
|
def findScore(cards, hands): |
|
|
|
|
score = 0 |
|
|
|
|
scoreIndex = 1 |
|
|
|
|
cards = "AKQJT98765432"[::-1] |
|
|
|
|
cards2 = "AKQT98765432J"[::-1] |
|
|
|
|
for i in range(7): |
|
|
|
|
sortTemp = {} |
|
|
|
|
for hand in sort1[-i-1]: |
|
|
|
|
for hand in hands[-i-1]: |
|
|
|
|
converted = "" |
|
|
|
|
for c in hand[0]: |
|
|
|
|
converted += hex(cards.find(c))[2:] |
|
|
|
@ -51,5 +61,7 @@ for i in range(7): |
|
|
|
|
for index in sorted(sortTemp): |
|
|
|
|
score += scoreIndex * sortTemp[index] |
|
|
|
|
scoreIndex += 1 |
|
|
|
|
return score |
|
|
|
|
|
|
|
|
|
print(score) |
|
|
|
|
print(findScore(cards1, sort1)) |
|
|
|
|
print(findScore(cards2, sort2)) |