This commit is contained in:
Sebastian Seedorf
2023-12-07 18:20:06 +01:00
parent 7efacbda5b
commit af244ce50b
3 changed files with 1059 additions and 0 deletions

28
day07/part1.py Normal file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env python3
from collections import Counter
lines = (x.strip() for x in open("input.txt"))
hands = []
for line in lines:
hand, bid = line.split(" ")
hand = tuple("23456789TJQKA".index(char) for char in hand)
count = Counter(hand).values()
if 5 in count:
hands.append((6, hand, int(bid)))
elif 4 in count:
hands.append((5, hand, int(bid)))
elif 3 in count and 2 in count:
hands.append((4, hand, int(bid)))
elif 3 in count:
hands.append((3, hand, int(bid)))
elif list(count).count(2) == 2:
hands.append((2, hand, int(bid)))
elif 2 in count:
hands.append((1, hand, int(bid)))
else:
hands.append((0, hand, int(bid)))
hands.sort()
print(sum(bid * rank for rank, (_, _, bid) in enumerate(hands, 1)))