Day 4: Ceres Search
Megathread guidelines
- Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
- You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL
FAQ
- What is this?: Here is a post with a large amount of details: https://programming.dev/post/6637268
- Where do I participate?: https://adventofcode.com/
- Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465
32 Comments
VegOwOtenks@lemmy.world · 4 pts · 1y
I struggled a lot more when doing list slices that I would've liked to
Haskell
mykl@lemmy.world · 4 pts · 1y
Uiua
Just part1 for now as I need to walk the dog :-)
[edit] Part 2 now added, and a nicer approach than Part 1 in my opinion, if you're able to keep that many dimensions straight in your head :-)
[edit 2] Tightened it up a bit more.
urquell@lemm.ee · 3 pts · 1y
I'm not even sure how to write most of these characters
mykl@lemmy.world · 2 pts · 1y
The operators have all got ascii names you can type, and the formatter converts them to the symbols. It's a bit odd but really worthwhile, as you get access to the powerful array handling functionality that made solving today's challenges so much more straightforward than in other languages.
urquell@lemm.ee · 2 pts · 1y
It looks quite functional indeed
janAkali@lemmy.one · 4 pts · 1y
Nim
Could be done more elegantly, but I haven’t bothered yet.
Codeberg repo
lwhjp@lemmy.sdf.org · 4 pts · 1y
Haskell
Popular language this year :)
I got embarrassingly stuck on this one trying to be clever with list operations. Then I realized I should just use an array...
LeixB@lemmy.world · 3 pts · 1y
Haskell
Andy@programming.dev · 2 pts · 1y
Factor
::: spoiler spoiler
:::
Better viewed on GitHub.
Quant@programming.dev · 2 pts · 1y
Uiua
This one was nice. The second part seemed quite daunting at first but wasn't actually that hard in the end.
Run with example input here
zarlin@lemmy.world · 2 pts · 1y
Nim
Part 1 was done really quickly. Part 2 as well, but the result was not accepted...
Turns out +MAS isn't actually a thing :P
Deebster@programming.dev · 2 pts · 1y
Rust
I had a hunch about part two that didn't pay off, so I over-coded this instead of just using an array of arrays.
TunaCowboy@lemmy.world · 2 pts · 1y
python
::: spoiler solution
:::
Sparrow_1029@programming.dev · 2 pts · 1y
Rust
Ugh. Spent way too long on today's. Should have just used my own grid structure from last year. I will likely refactor to use that. Even though it's likely a super slow implementation, the convenience of dealing with it is better than shoehorning in the
grid::Grid<T>from that crate.::: spoiler solution (no supporting code)
::: And here's a link to the Github if you care to see the gross supporting code :D
hades@lemm.ee · 2 pts · 1y
sjmulder@lemmy.sdf.org · 2 pts · 1y
C
What can I say, bunch of for loops! I add a 3 cell border to avoid having to do bounds checking in the inner loops.
::: spoiler Code
:::
https://github.com/sjmulder/aoc/blob/master/2024/c/day04.c
SteveDinn@lemmy.ca · 1 pts · 1y
C#
Rin@lemm.ee · 1 pts · 1y
wer2@lemm.ee · 1 pts · 1y
Lisp
Not super happy with the code, but it got the job done.
::: spoiler Part 1 and 2
:::
vole@lemmy.world · 1 pts · 1y
Raku
Oof, my struggle to make custom index walking paths for part 1 did not pay off for part 2.
::: spoiler Solution
:::
github
proved_unglue@programming.dev · 1 pts · 1y
Kotlin
hosaka@programming.dev · 1 pts · 1y
Zig
ace@lemmy.ananace.dev · 1 pts · 1y
I tried to think of some clever LINQ to do this one, but was blanking entirely.
So naïve search it is.
::: spoiler C#
:::
CameronDev@programming.dev · 1 pts · 1y
I haven't quite started yet, and this one does feel like a busy work kinda problem. I was wondering if I could write something to rotate the board and do the search, but I think that might be not worth the effort
Karmmah@lemmy.world · 1 pts · 1y
Julia
Had some time to clean up the code today since the solution was quite straight forward after making a plan on how to approach it.
::: spoiler spoiler
:::
Gobbel2000@programming.dev · 1 pts · 1y
Rust
One of those with running through tricky grid indices. The vector types from the euclid crate helped in dealing with positions.
::: spoiler Code
:::
(also on github)
Tessellecta@feddit.nl · 1 pts · 1y
Python
::: spoiler
:::
Hammerheart@programming.dev · 1 pts · 1y
Part 1:
Part 2:
I actually found part two A LOT easier than part 1.
landreville@lemmy.world · 1 pts · 1y
Rust
Blunt force grid navigation https://gitlab.com/landreville/advent-of-code-2024/-/blob/main/src/bin/04.rs
reboot6675@sopuli.xyz · 1 pts · 1y
Go
Just a bunch of ifs and bounds checking. Part 2 was actually simpler.
::: spoiler Code
:::
Chais@sh.itjust.works · 1 pts · 1y
Python
Essentially I'm extracting strings from the word search and compare them to the desired value. For part one that means extracting from an X in eight directions. Because I'm reading from the central X outwards, I don't need to reverse any of them.
Part two reads two strings in an X-shape around the coordinates of each X. The resulting strings are filtered down to include only "MAS" and "SAM". If there are exactly two strings we found an X-MAS.
morrowind@lemmy.ml · 1 pts · 1y
Smalltalk
I could have done it in 2 fns if I made them more generic, but couldn't be bothered
Part 2
aurele@sh.itjust.works · 1 pts · 1y
Elixir
sleeplessone@lemmy.ml · 0 pts · 1y
Rust
I'm a day behind on this one due to a lot of work with my job and school.
The standard library
windowsmethod and pattern matching have been carrying me this year so far.