Day 07
This commit is contained in:
1000
day07/input.txt
Normal file
1000
day07/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
28
day07/part1.py
Normal file
28
day07/part1.py
Normal 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)))
|
||||||
31
day07/part2.py
Normal file
31
day07/part2.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/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("J23456789TQKA".index(char) for char in hand)
|
||||||
|
count = list(Counter(h for h in hand if h != 0).values())
|
||||||
|
num_j = sum(1 for h in hand if h == 0)
|
||||||
|
if len(count) <= 1:
|
||||||
|
hands.append((6, hand, int(bid)))
|
||||||
|
elif (4-num_j) in count:
|
||||||
|
hands.append((5, hand, int(bid)))
|
||||||
|
elif len(count) == 2 and 2 in count:
|
||||||
|
hands.append((4, hand, int(bid)))
|
||||||
|
elif (3-num_j) in count:
|
||||||
|
hands.append((3, hand, int(bid)))
|
||||||
|
elif list(count).count(2) == 2:
|
||||||
|
hands.append((2, hand, int(bid)))
|
||||||
|
elif (2-num_j) in count:
|
||||||
|
hands.append((1, hand, int(bid)))
|
||||||
|
else:
|
||||||
|
hands.append((0, hand, int(bid)))
|
||||||
|
|
||||||
|
hands.sort()
|
||||||
|
for h in hands:
|
||||||
|
print(h)
|
||||||
|
print(sum(bid * rank for rank, (_, _, bid) in enumerate(hands, 1)))
|
||||||
Reference in New Issue
Block a user