From 90f1ab857a024aabeb13f12d5eb24ffbb6279559 Mon Sep 17 00:00:00 2001 From: kwout Date: Thu, 7 Dec 2023 12:55:42 -0500 Subject: [PATCH] 2023 day 7 part 1 solved --- 2023/7.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 2023/7.py diff --git a/2023/7.py b/2023/7.py new file mode 100644 index 0000000..14bdfb3 --- /dev/null +++ b/2023/7.py @@ -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) \ No newline at end of file