lud
Gosh this one took me sooo much time.
At first I was trying to iterate each digit independently on the input A number to make digits change in the output. (iterating on a base-8 representation of the input). It looks likes it is kind of possible but I am not sure how.
So finally I just wen another way by trying more numbers. But it takes 3ms in the end so I guess it’s okay ![]()
I wrote a big comment block if it can be useful to some !
https://github.com/lud/adventofcode/blob/main/lib/solutions/2024/day17.ex
Trending in Challenges
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 8 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ken-kost
I put functions into maps.
So I solved part 1 on my own because it was fun.
I did try to get the solution for part 2 with naive method (incrementing by 1) but that failed spectacularly. I even tried leaving the laptop running over night but forgot to turn off automatic sleep.
Perhaps better even, my poor computer shouldn’t go through such treatment. 
Used @bjorng shifting algorithm for part 2. I don’t think I would figure this one out on my own.
Aetherus
Part 2 was fun!
I rewrote the “program” as a pure Elixir function, then started cracking the register A from there.
This is my code (with some explanation of the “program” according to my input).
A,BandCin the markdown are the whole number in registers A, B, and C.a,bandcare the lowest 3 bits ofA,BandC.https://github.com/Aetherus/advent-of-code/blob/2f04a699725e42fa9df6a874de9bc5ca441bb49d/2024/day-17.livemd
igorb
This took me quite a long time..! But probably my favorite puzzle this year so far: advent-of-code-2024/lib/advent_of_code2024/day17.ex at main · ibarakaiev/advent-of-code-2024 · GitHub
rvnash
Part 1: 7,3,5,7,5,7,4,3,0 in 0.012ms
Part 2: 105734774294938 in 56.83ms
https://github.com/rvnash/aoc2024/blob/main/lib/d17.ex
The way I solved part 2 is also by noticing that A is right-shifted 3-bits on each iteration. So, starting at the end of the list I find all initial values of A in 0..7 that produces the last byte of the program. Then moving up the list to the last 2 bytes, left-shift all the existing values of A 3-bits, and add in 0..7, and record the list of A’s which produce the last two bytes. …and so on up to include the whole program. Then take the min of that list. It executes quite fast.
Fun fact: for my puzzle there were 84 possible solutions.
antoine-duchenet
Here are the main parts of my solution :
For part 2, once you understand that the final
3, 0means that the program restarts from the beginning whileA != 0and thatAis independant ofBandC, it opens many doors.The most important part is the
untrunc/2function which takes advantage of the static division of A by2^3at every loop (for my input).I had to keep track of every possible predecessor (
Enum.filter, notEnum.find) because some outputs are related to multiple inputs and some outputs cannot exist with inputs in thepredecessor..(predecessor + 7)range if only the lowest predecessor is kept. For example0and1inputs both output a5but the4output needs at least an11(which gives it very specific conditions of appearance that could be precluded by keeping only the lower predecessor).At the end, the
backtrackfunction takes 4ms to find 3 possible startingA(with the lowest being the solution).liamcmitchell
This was a good one. I’ve never played so much with bits.
I used Stream.resource produce output from the initial state.
I figured out that all operations could be done with
Bitwise:ANDwith 7 (only keeping lowest 3 bits)https://github.com/liamcmitchell/advent-of-code/blob/773628863a81553bea3e40ff536127bed8f5df5e/2024/17/1.exs#L17-L48
Part2: In the example and my input (prob for everyone else), on every iteration, A is divided by 8 (bitshift right 3 bits) and B and C are generated from A. Looking at the max values, each output is produced from XORing 3-10 of the least significant bits of A.
Many hours later I figured out to iterate over most significant bits first, looking for match with last output, then moving down and checking more affected outputs.
This was really hard to think about, not sure if writing this helps others
https://github.com/liamcmitchell/advent-of-code/blob/773628863a81553bea3e40ff536127bed8f5df5e/2024/17/1.exs#L63-L89
Less than 100 LOC in the end!
bjorng
I tried a few ways to solve part 2 before I found an approach that would terminate.
My solution seems to be similar to @lud’s, in that I construct possible values for the A register and discard values that don’t work. It’s a little bit different in that I don’t reverse the list of program digits.
https://github.com/bjorng/advent-of-code/blob/main/2024/day17/lib/day17.ex
sevenseacat
Part 1 was pretty straightforward, part 2 is one of those reverse engineering nightmare puzzles D: