adventofcode

2024-12-24T05:34:39.761019Z

Day 24 - Solutions

bhauman 2024-12-26T23:30:17.727869Z

Here’s some clojure.core.logic that prints out potential bad outputs given a bit location.

1
bhauman 2024-12-26T23:37:34.671269Z

This definitely could be improved especially the linear gate look up. But dang its a concise way to find bad outputs that can be swapped. I’m sure you could write it so that the the logic system itself reports out all the good or bad bits OR even find all the specific swaps that repair the system as well…

bhauman 2024-12-26T23:40:42.232989Z

I don’t think this is as accessible or as straight forward as the continuations based matcher I made above. But if there is an interest in core.logic this a nice entry point …

bhauman 2024-12-25T23:59:47.334069Z

Here’s day 24: https://github.com/bhauman/adv2024/blob/main/src/adv2024/day24/sol.clj Part 2 runs in 10ms

bhauman 2024-12-26T00:01:12.787519Z

I wrote a little continuations based DSL to match the adder logic graph and then report the errors back. It was a fun puzzle for sure.

1
bhauman 2024-12-26T00:03:42.002529Z

I almost used core logic and then I thought better of it.

Aleks 2024-12-24T08:27:03.676059Z

For part 2 I drew my graph and solved it visually by examining the output

Maravedis 2024-12-24T08:30:58.781749Z

Oh, that's a WAY better presentation than mine lmao

Aleks 2024-12-24T08:32:29.633379Z

You can label nodes like this "z31" [label="z31\n\nXOR"]

Maravedis 2024-12-24T08:33:28.606589Z

Eh. I managed. And I'll probably forget before next year's aoc ^^;

😅 1
roklenarcic 2024-12-24T09:20:37.190029Z

I gave up trying to code this and just did it by hand lol

Maravedis 2024-12-24T09:21:27.191519Z

I don't think anyone did it "code first", even scrolling other solution threads.

roklenarcic 2024-12-24T09:21:42.737839Z

wasted a lot of time lol

roklenarcic 2024-12-24T09:22:06.216789Z

Only 2500 people solved it yet

roklenarcic 2024-12-24T09:22:51.459919Z

Nah I wrote a validator in the end but I had to look by hand how to change it to make it pass

Maravedis 2024-12-24T09:22:56.162509Z

Yeah. I ranked 659, which is by far my best ranking ever.

Maravedis 2024-12-24T09:23:47.202149Z

> I wrote a validator in the end but I had to look by hand That's exactly what I did. Code the "detect bad", then solve by hand.

Maravedis 2024-12-24T09:24:39.605269Z

I had an idea of a "validate each step" for each bit and detect as soon as a step was wrong, but it's a chore and a half to write and now that I have the answer, I'm not motivated to write it.

roklenarcic 2024-12-24T09:26:17.050219Z

Yeah I wrote the validator for each step, but the output was cryptic enough that the benefit isn’t big enough

roklenarcic 2024-12-24T10:13:37.253639Z

hm looks like still only 3 solved on clojurians leaderboard

tildedave 2024-12-24T14:53:47.203369Z

got it, mostly via REPL experiment. wrote a validator to output which bits were bad which zeroed in on the issues, then brute forced fixing the connectors. in some cases I brute forced all possible swaps to see which ones had worked (e.g. if you know bit N is bad when you just add 1<<N + 1<<N you can find all the swaps that fix it).

tildedave 2024-12-24T14:55:21.244949Z

lots of stuff like this

tildedave 2024-12-24T14:55:36.943419Z

could have been more efficient at it, had fun futzing :-)

tildedave 2024-12-24T15:02:49.038909Z

https://github.com/tildedave/advent-of-code/blob/main/src/advent2024/day24.clj mostly REPL notes

Aleks 2024-12-24T16:11:35.723389Z

https://academo.org/demos/logic-gate-simulator/

rjray 2024-12-25T00:08:14.479009Z

Well, finally finished both parts: https://github.com/rjray/advent-2024-clojure/blob/master/src/advent_of_code/day24.clj I was able to solve part 2 without using any graphing tools. I did get mixed up and had to have a look at a Python solution that was taking the same approach I was, at one point. I became confused when the second test-set from part 1 produced many more swap-pairs than I was expecting (spoiler: it doesn't work as test input for part 2). Even after making some adjustments, i realized I had no effective test-data for part 2. But it running it on the puzzle input did result in exactly eight connections, so I took a leap of faith and submitted it. It was correct.

1
bhauman 2024-12-28T23:15:50.768049Z

I couldn’t leave it be. Complete clojure.core.logic solution for part 2 https://github.com/bhauman/adv2024/blob/main/src/adv2024/day24/logic.clj

bhauman 2024-12-28T23:16:40.256749Z

As usual logic programming requires a completely different way of thinking. Very very fun stuff.

1
Maravedis 2024-12-29T06:17:18.188289Z

This is very impressive. This doesn't feel that far from my solution, but the syntax is very very different. Do you have a recommendation on how to approach core.logic ? I never even looked at the package, but your code makes it look very interesting.

roklenarcic 2024-12-27T19:02:43.764819Z

Love the continuations, the elegance of this kind of stuff drew me to functional programming. But I have to say I don’t ever use things like this in my code, because as neat as it is, it is inferior to just representing this thing in data and running code on top of it. Sure, continuations code results in some short code, but continuations are opaque and hard to debug. Representing something like this with data + code that runs over the data is much better for production code: • the data part is easy to inspect • data can be serialized/deserialized • you can write multiple sets of functions that operate on same data, e.g. if you have multiple versions of a server or something • you can sometimes tweak behavior by tweaking data, instead of changing the code I am sad that these neat functional constructs are not better than plain old boring data + data processing functions, but it is what it is.

2024-12-24T05:37:18.071919Z

This is the second time today when I thought I as working on problem N but I was actually working on problem N-1.... Well, at least I'm not ON the current day 🙂

rjray 2024-12-24T06:39:38.393209Z

I have part 1 done, but I'm going to sleep on part 2, I think. It seems like I'd have to either reverse-engineer the circuit or iterate over roughly 128795283347445 different combinations...

misha 2024-12-24T06:43:53.181129Z

maybe it'd be faster to build classic adder, label its wires, and diff with puzzle input

misha 2024-12-24T06:46:20.255559Z

or test pairs of bits for faulty paths.

rjray 2024-12-24T06:46:40.904439Z

Might be, but not at 10:45PM 🙂.

roklenarcic 2024-12-24T06:49:11.238399Z

I have a solution but I’ve got other errands 😞

misha 2024-12-24T06:53:40.877289Z

Maravedis 2024-12-24T06:56:40.961329Z

I got it 😄 Have to clean up the code a bit, but what I did was build a "validate adder" function, then just look for the faulty ones in graph viz

🔥 3
Maravedis 2024-12-24T06:57:01.634899Z

So misha's approach.

rjray 2024-12-24T07:02:17.352709Z

Puzzles that can't be done in 100% code annoy me...

Maravedis 2024-12-24T07:02:39.423899Z

I think it can be 100% in code, but you need to reverse engineer the input first.

Maravedis 2024-12-24T07:02:56.948019Z

I'm working on a 100% code approach, it's just much easier to solve it visually first.

💯 1
Maravedis 2024-12-24T07:52:52.880279Z

Here is mine. It's not complete by any means, the detect-swap might need more entries in its cond for other inputs. But it works for mine.

bhauman 2024-12-29T16:18:04.501859Z

https://mitpress.mit.edu/9780262535519/the-reasoned-schemer/ is really the best way to start. Or go to http://minikanren.org. There is also a little tutorial on the clojure.core.logic github wiki. It’s basically pattern matching all the way down. My biggest problem when coming back to it, is that my mind always reverts my non-logic programming ways, when in logic programming you kinda just need to state the problem.