parent
b7de7999c8
commit
aa3d90d771
1 changed files with 27 additions and 15 deletions
@ -1,55 +1,67 @@ |
|||||||
hands = [l.split() for l in open("input.txt", 'r').read().splitlines()] |
hands = [l.split() for l in open("input.txt", 'r').read().splitlines()] |
||||||
sort1 = [[] for i in range(7)] |
sort1 = [[] for i in range(7)] |
||||||
|
sort2 = [[] for i in range(7)] |
||||||
|
|
||||||
for hand in hands: |
for hand in hands: |
||||||
handSet = {} |
handSet = {} |
||||||
for card in set(hand[0]): |
for card in set(hand[0]): |
||||||
handSet[card] = hand[0].count(card) |
handSet[card] = hand[0].count(card) |
||||||
handSetLen = len(handSet) |
handSetLen = len(handSet) |
||||||
|
jCount = hand[0].count('J') |
||||||
|
|
||||||
if handSetLen == 1: |
if handSetLen == 1: |
||||||
sort1[0].append(hand) # 5oak |
sort1[0].append(hand) # 5oak |
||||||
|
sort2[0].append(hand) |
||||||
elif handSetLen == 2: |
elif handSetLen == 2: |
||||||
for card in handSet: |
for card in handSet: |
||||||
if handSet[card] == 4: |
if handSet[card] == 4: |
||||||
sort1[1].append(hand) # 4oak |
sort1[1].append(hand) # 4oak |
||||||
|
sort2[0 if jCount > 0 else 1].append(hand) |
||||||
break |
break |
||||||
elif handSet[card] == 3: |
elif handSet[card] == 3: |
||||||
sort1[2].append(hand) # fh |
sort1[2].append(hand) # fh |
||||||
|
sort2[0 if jCount > 0 else 2].append(hand) |
||||||
break |
break |
||||||
elif handSetLen == 3: |
elif handSetLen == 3: |
||||||
for card in handSet: |
for card in handSet: |
||||||
if handSet[card] == 3: |
if handSet[card] == 3: |
||||||
sort1[3].append(hand) # 3oak |
sort1[3].append(hand) # 3oak |
||||||
|
sort2[1 if jCount > 0 else 3].append(hand) |
||||||
break |
break |
||||||
elif handSet[card] == 2: |
elif handSet[card] == 2: |
||||||
sort1[4].append(hand) # 2pair |
sort1[4].append(hand) # 2pair |
||||||
|
sort2[(2 if jCount == 1 else 1) if jCount > 0 else 4].append(hand) |
||||||
break |
break |
||||||
elif handSetLen == 4: |
elif handSetLen == 4: |
||||||
for card in handSet: |
for card in handSet: |
||||||
if handSet[card] == 2: |
if handSet[card] == 2: |
||||||
sort1[5].append(hand) # 1pair |
sort1[5].append(hand) # 1pair |
||||||
|
sort2[3 if jCount > 0 else 5].append(hand) |
||||||
break |
break |
||||||
elif handSetLen == 5: |
elif handSetLen == 5: |
||||||
for card in handSet: |
for card in handSet: |
||||||
sort1[6].append(hand) # highcard |
sort1[6].append(hand) # highcard |
||||||
break |
sort2[5 if jCount > 0 else 6].append(hand) |
||||||
|
|
||||||
|
|
||||||
score = 0 |
cards1 = "AKQJT98765432"[::-1] |
||||||
scoreIndex = 1 |
|
||||||
cards = "AKQJT98765432"[::-1] |
|
||||||
cards2 = "AKQT98765432J"[::-1] |
cards2 = "AKQT98765432J"[::-1] |
||||||
for i in range(7): |
|
||||||
sortTemp = {} |
|
||||||
for hand in sort1[-i-1]: |
|
||||||
converted = "" |
|
||||||
for c in hand[0]: |
|
||||||
converted += hex(cards.find(c))[2:] |
|
||||||
sortTemp[int('0x' + converted, 16)] = int(hand[1]) |
|
||||||
|
|
||||||
for index in sorted(sortTemp): |
def findScore(cards, hands): |
||||||
score += scoreIndex * sortTemp[index] |
score = 0 |
||||||
scoreIndex += 1 |
scoreIndex = 1 |
||||||
|
for i in range(7): |
||||||
|
sortTemp = {} |
||||||
|
for hand in hands[-i-1]: |
||||||
|
converted = "" |
||||||
|
for c in hand[0]: |
||||||
|
converted += hex(cards.find(c))[2:] |
||||||
|
sortTemp[int('0x' + converted, 16)] = int(hand[1]) |
||||||
|
|
||||||
print(score) |
for index in sorted(sortTemp): |
||||||
|
score += scoreIndex * sortTemp[index] |
||||||
|
scoreIndex += 1 |
||||||
|
return score |
||||||
|
|
||||||
|
print(findScore(cards1, sort1)) |
||||||
|
print(findScore(cards2, sort2)) |
Loading…
Reference in new issue