I might not even do part 2 today. My brain is having a rest day.
with open("input.txt", "r") as f:
input = f.readlines()
high_card = []
one_pair = []
two_pair = []
three_of_a_kind = []
full_house = []
four_of_a_kind = []
five_of_a_kind = []
for line in input:
cards, bid = line.split()
cards = list(cards)
hand = []
type = 1
hand_as_text = ""
for card in cards:
card = (
card.replace("2", "02")
.replace("3", "03")
.replace("4", "04")
.replace("5", "05")
.replace("6", "06")
.replace("7", "07")
.replace("8", "08")
.replace("9", "09")
.replace("T", "10")
.replace("J", "11")
.replace("Q", "12")
.replace("K", "13")
.replace("A", "14")
)
hand_as_text += card
card = int(card)
hand.append(card)
count = hand.count(card)
match count:
case 5:
type = 7
case 4:
type = 6
case 3:
if type == 3:
type = 5
else:
type = 4
case 2:
if type == 2:
type = 3
elif type == 4:
type = 5
else:
type = 2
hand = dict(cards=int(hand_as_text), bid=int(bid))
match type:
case 1: high_card.append(hand)
case 2: one_pair.append(hand)
case 3: two_pair.append(hand)
case 4: three_of_a_kind.append(hand)
case 5: full_house.append(hand)
case 6: four_of_a_kind.append(hand)
case 7: five_of_a_kind.append(hand)
hands = []
hands.append(high_card)
hands.append(one_pair)
hands.append(two_pair)
hands.append(three_of_a_kind)
hands.append(full_house)
hands.append(four_of_a_kind)
hands.append(five_of_a_kind)
rank = 1
total = 0
for i in range(len(hands)):
hands[i] = sorted(hands[i], key=lambda x: x['cards'])
for hand in hands[i]:
total += hand["bid"] * rank
rank += 1
print(total)syntax highlighting by codehost