Update readme and clean up day 20.

This commit is contained in:
felixm 2023-12-27 13:26:40 -05:00
parent c5813e168b
commit 9fcc902703
2 changed files with 22 additions and 12 deletions

View File

@ -2,7 +2,8 @@
- Day 1: 40:00 (I don't know what I am doing.)
- Day 2: 14:15 (Okay, but far way from leaderboard.)
- Day 3: 1st 20:00, 2nd 70:00... (I had a logic error that took me a while to find.)
- Day 3: 1st 20:00, 2nd 70:00... (I had a logic error that took me a while to
find.)
- Day 4: 1st 9:06, 2nd 22:31; it wasn't hard but I didn't think quick enough :/
- Day 5: 1st 25:00, 2nd 1:55:00; Required patience and accuracy
- Day 6: 13:54; I was slow because I thought it is much harder?
@ -10,8 +11,10 @@
- Day 8: 25:00; I was doing pretty decent here.
- Day 9: 57:00; my input parse function did not consider negative values...
- Day 10: 180:00; this one was hard for me.
- Day 11: 68:00; okay but not elegant and way too slow ofc; x-ray solution would have been neat
- Day 12: 52:00 and 22:00 for leaderboard; had the right idea and I am good at this type of problem
- Day 11: 68:00; okay but not elegant and way too slow ofc; x-ray solution
would have been neat
- Day 12: 52:00 and 22:00 for leaderboard; had the right idea and I am good at
this type of problem
- Day 13: 90:00; pretty straightforward but way too slow
- Day 14: 5:55 for first and then 48:00; straightforward but slow, ofc
- Day 15: 4:30 and 31:20; more reading comprehension than programming
@ -22,4 +25,11 @@
but didn't realize that I have to compute the outer edges for a while and
after I did, I still got clockwise/counter-clockwise issues. They could have
made it meaner by using different clock directions for example and input.
- Day 19:
- Day 19: This one was pretty straightforward and required the interval
technique we applied earlier.
- Day 20: Part 2 was tough. I had the right idea of printing out the periods of
the input conjunction gate pretty early, but then messed up the
implementation and thought it wasn't gonna work. Spent a half day thinking up
something else before returning to the idea and it worked flawlessly.
- Day 21:
- Day 22:

16
d20.py
View File

@ -1,5 +1,6 @@
from lib import *
from math import lcm
from collections import deque
EXAMPLE = """
broadcaster -> a, b, c
@ -25,10 +26,9 @@ def visualize(modules):
f.write(" " + m[1] + ' -> ' + cm + "\n")
f.write("}")
def solve(i: Input, second=False):
res = 0
def solve(input: Input, second=False):
modules = {}
for line in i.lines():
for line in input.lines():
if not line: continue
src, dsts = line.split(" -> ")
dsts = dsts.split(", ")
@ -48,17 +48,17 @@ def solve(i: Input, second=False):
if second:
# visualize(modules)
periods = {d: [] for d in modules["kh"][2].keys()}
(feed,) = [m[1] for m in modules.values() if "rx" in m[3]]
periods = {d: [] for d in modules[feed][2].keys()}
BUTTON_PUSHES = 10000
else:
BUTTON_PUSHES = 1000
lo, hi = 0, 0
for i in range(BUTTON_PUSHES):
qs = [("button module", "broadcaster", 0)]
qs = deque([("button module", "broadcaster", 0)])
while qs:
src, dst, sig = qs[0]
qs = qs[1:]
src, dst, sig = qs.popleft()
if sig == 0:
lo += 1
@ -87,7 +87,7 @@ def solve(i: Input, second=False):
if new_pulse is not None:
for nxtdst in m[3]:
if second and nxtdst == "kh" and new_pulse == 1:
if second and nxtdst == feed and new_pulse == 1:
# print(f"{i:>4}: {dst[:4]:>4} -{new_pulse}> {nxtdst}")
periods[dst].append(i)
qs.append((dst, nxtdst, new_pulse))