parent
acc56c9ab1
commit
90f1ab857a
1 changed files with 55 additions and 0 deletions
@ -0,0 +1,55 @@ |
||||
hands = [l.split() for l in open("input.txt", 'r').read().splitlines()] |
||||
sort1 = [[] 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) |
||||
|
||||
if handSetLen == 1: |
||||
sort1[0].append(hand) # 5oak |
||||
elif handSetLen == 2: |
||||
for card in handSet: |
||||
if handSet[card] == 4: |
||||
sort1[1].append(hand) # 4oak |
||||
break |
||||
elif handSet[card] == 3: |
||||
sort1[2].append(hand) # fh |
||||
break |
||||
elif handSetLen == 3: |
||||
for card in handSet: |
||||
if handSet[card] == 3: |
||||
sort1[3].append(hand) # 3oak |
||||
break |
||||
elif handSet[card] == 2: |
||||
sort1[4].append(hand) # 2pair |
||||
break |
||||
elif handSetLen == 4: |
||||
for card in handSet: |
||||
if handSet[card] == 2: |
||||
sort1[5].append(hand) # 1pair |
||||
break |
||||
elif handSetLen == 5: |
||||
for card in handSet: |
||||
sort1[6].append(hand) # highcard |
||||
break |
||||
|
||||
|
||||
score = 0 |
||||
scoreIndex = 1 |
||||
cards = "AKQJT98765432"[::-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): |
||||
score += scoreIndex * sortTemp[index] |
||||
scoreIndex += 1 |
||||
|
||||
print(score) |
Loading…
Reference in new issue