Rules: no spoilers.

The other rules are made up as we go along.

Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.

  • swlabr@awful.systems
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    11 months ago

    Day 20: Pulse Propagation

    It feels weird to kick one of these threads off, but hey, here we go.

    Code as always: https://github.com/Fluxward/aoc2023/blob/main/20.dart

    a,b

    A

    So following from yesterday where I was punished by not going full OO, I decided, hey, this is a problem in which I can do some OOP, so I did. This took very long to do but I regret nothing. If you look at my code, feel free to click your tongue and shake your head at every opportunity I missed to use a design pattern.

    Anyway, after a slight snafu with misunderstanding the FF logic and not spotting that some modules can be dummy modules, it all just worked, and I got my answer.

    B

    This was a bit of a headscratcher, but the answer was surprisingly simple.

    First, the answer. Here’s how to do it:

    • Look for the “rx” module in your input.
    • If the module that outputs to rx is a conjunction, keep track of how many button presses it takes for each input of the conjunction to change. The answer is the LCM of all those numbers.
    • If the module is a FF, you can also work backwards to get it, but this was not my input so I didn’t need to try this.

    Getting here was a bit weird. I hoped that I could just run the code from A and spit out the answer when rx went low, but as of time of writing I’ve been running it now on a separate machine for about an hour and still no result.

    My next instinct was to simply work it out from pen and paper. I thought it might be possible (it probably is) but decided to at least experimentally see if the states of the modules connected to rx were cyclic first. I did, and that was enough for me to get to the answer.

    My answer was about 230 trillion BPs, which, extrapolating on how long execution is taking on my other machine, might take just under 137 years to calculate naively. Fun!

    • gerikson@awful.systemsOP
      link
      fedilink
      English
      arrow-up
      4
      ·
      11 months ago

      I’m having a hard time modeling the network at the moment, there’s too much shit to keep track of. Objects might be the solution!

      • swlabr@awful.systems
        link
        fedilink
        English
        arrow-up
        4
        ·
        11 months ago

        Yeah, I mean it’s always possible to do without all the OO stuff, I just didn’t want to mentally keep tabs on what each variable or method did what. That’s what the code is for!