Unable to load image

rDrama Advent of Code Day 20: Fashionably Late Edition

Summary for those just joining us:

Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!

Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app

What did you think about today's problem?

https://adventofcode.com/2023

Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)

28
Jump in the discussion.

No email address required.

Questions that require looking at the input should be illegal. You solve for example, you change filename, it just werks.

Jump in the discussion.

No email address required.

You should be able to anticipate edge cases not in the example but otherwise I agree

Jump in the discussion.

No email address required.

I managed to quickly identify that part 2 was another LCM question but then I got stuck for like an hour due to an off-by-one issue (needed to add +1 to the cycle lengths because I iterated from 0)

https://i.rdrama.net/images/17030663068056839.webp

Jump in the discussion.

No email address required.

My friend who wakes up to do them texted me "wtf" so I'm pretty scared. Looks OK though? Just a stack and storing a boolean state on each node...

Jump in the discussion.

No email address required.

:#marseyraging:

First the text for the example for part 1 makes it seem like you should multiply the final answer by 1000.

Then for part 2, apparently you aren't supposed to code a general solution, but instead look at the input, and once again assume that lcm works? The computer's supposed to do the work, not me.

Jump in the discussion.

No email address required.

:marseyitsallsotiresome:

https://i.rdrama.net/images/170311861758005.webp

Jump in the discussion.

No email address required.

i really like this one

Jump in the discussion.

No email address required.

Part 1 was neat, part 2 sucked. Got distracted by the 2 layers of conjs as if it wasn't tedious enough already.

⎕PP←20
r←(⊂'%rx ->'),⍨⊃⎕NGET'20.in'1
l←⊃¨t←(∊∘(⎕C⎕A)⊆⊢)¨r ⋄ e←1↓¨l∘⍳∘⊂¨¨t ⋄ y←'b%&'⍳⊃¨r
m←{⍵≡1:⍬ ⋄ ⍵≡2:0 ⋄ 0⍴⍨≢y}¨y ⋄ jl←+/e(∘.∊)⍨⍳≢y ⋄ b←y⍳1
f←{(⍵⊃m)⊢←v←~⍵⊃m ⋄ (⍵⊃e),¨v,¨⍵}
j←{i v o←⍵ ⋄ (o⊃i⊃m)⊢←v ⋄ (i⊃e),¨((i⊃jl)≢+/i⊃m),¨i}
p←{i v o←⍵ ⋄ t d←i⊃¨y e ⋄ 1≡t:d,¨v,¨i ⋄ (~v)∧2≡t:f i ⋄ 3≡t:j ⍵ ⋄ ⍬}
cl←0 ⋄ ch←0
g←{0≡≢⍵:⍵ ⋄ v←2⊃¨⍵ ⋄ ch⊢←ch++/v ⋄ cl⊢←cl++/~v ⋄ ⍵}
⎕←cl×ch⊣{cl⊢←1+cl ⋄ {g⊃,/p¨⍵}⍣{0≡≢⍺}⊢⊂b 0 0}⍣1E3⊢0

m←{⍵≡1:⍬ ⋄ ⍵≡2:0 ⋄ 0⍴⍨≢y}¨y
w←⍸∊(x←⍸∨/¨∊∘(≢r)¨e)(∘.∊)e ⋄ c←0 ⋄ t←0 0 0 0
q←{i v o←⍵ ⋄ (v=1)∧(x=i):(p ⍵)⊣((w⍳o)⊃t)⊢←c ⋄ p ⍵}
⎕←∧/t⊣{c⊢←1+c ⋄ {⊃,/q¨⍵}⍣{0≡≢⍺}⊢⊂b 0 0}⍣5E3⊢0
Jump in the discussion.

No email address required.

Make that three days in a row where the trick was something seen in a previous challenge.

When my random test answer of 100 billion returned too low I knew it would be more LCM frickery, and the example it gives very heavily hints toward "you only reach the end node when all parents are sending a high pulse" so I assumed there must be regular cycles.

https://i.rdrama.net/images/17030975590539038.webp

Jump in the discussion.

No email address required.

Part 1 is nice, Part 2 is a bit rough today. Trying to brute force it is unwise.

I don't see an obvious way of universally solving Part 2 without inspecting the graph. It's only by doing that that you're able to spot the single conjunction node above the target node, allowing you to find cycles for each input and lcm the result. Not really much of a coding challenge so much as a test of graph theory, which I kinda suck at.

Jump in the discussion.

No email address required.

Bad day today. I spent more time fighting compilation errors than I did figuring out the problem.

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.