18
submitted 1 year ago* (last edited 1 year ago) by gerikson@awful.systems to c/notawfultech@awful.systems

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.

you are viewing a single comment's thread
view the rest of the comments
[-] swlabr@awful.systems 3 points 11 months ago* (last edited 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,bA

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.systems 4 points 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 4 points 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!

[-] zogwarg@awful.systems 3 points 11 months ago

[Language: jq]https://github.com/zogwarg/advent-of-code/blob/main/2023/jq/20-b.jq

Completed when waiting for the second leg of my Christmas holidays flight. (It was a long wait, can I blame jet-lag?).

Have a more compact implementation of LCM/GCD, something tells me it will come in handy In future editions. (I’ve also progressively been doing past years)

this post was submitted on 01 Dec 2023
18 points (100.0% liked)

NotAwfulTech

367 readers
1 users here now

a community for posting cool tech news you don’t want to sneer at

non-awfulness of tech is not required or else we wouldn’t have any posts

founded 1 year ago
MODERATORS