This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
My https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2023/day_16_mirrors.clj. It’s not optimized. Part 2 takes almost 8 seconds to run, but I’m not too bothered by that.
solution: https://github.com/erdos/advent-of-code/blob/master/2023/day16.clj
it is just a flood fill. I was playing with multimethods to dispatch on the cell type but the embedded case
expressions were shorter at the end.
I haven't been posting my solutions this year, but they're all in my https://github.com/abyala/advent-2023-clojure. https://github.com/abyala/advent-2023-clojure/blob/main/src/advent_2023_clojure/day16.clj, as well as my https://github.com/abyala/advent-2023-clojure/blob/main/docs/day16.md (for non-Clojurians).
@UTFAPNRPT Hehe, my part 2 takes ~2 minutes even with pmap
. I know how it could be optimized, but too lazy to do that. Maybe later ^_^
My take https://github.com/gveres/advent-of-code-2023-clojure/blob/main/src/day16.clj Very simulation-ish as opposed to "think about a good algorithm", has a lot of conds... would like to clean it up, but gets the job done. 3.4 seconds on an M1 Pro Mac.
Figured out how it could be optimized. We can detect a beam loop. Once it’s detected, we eliminate the beam. Finally, once the all beams eliminated we can count energized tiles ⚡. It makes my solution 10-15 times faster. So part 1 takes only 41 msecs, and part 2 takes 1353 msecs ☺️ https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2023/day_16.clj
That's kind of what I'm also doing: keep a log of all [position incoming-direction] tuples, and if one comes up again, I drop that ray from my active rays set. I actually do an infinite lazy seq, and just drop-while until I have any rays. By the time all rays are gone (either left the grid or went into a loop), we're done. BUT, mine is still half as fast, so I'll need to look again .
And mine finally, 1.5s for part-2 (with pmap
) https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2023/day16.clj
First try: 1.6 seconds on my M1 - I did not attempt to optimize but something could probably be done with transient collections or similar.
I went with a breath-first-traversal using a queue in a loop
.
Day 16 — Question Guys, what do you think is there a way to find the best point to start the beam by analyzing a layout? or just bruteforce for rescue? Haven’t seen other’s solutions yet.
Nice, I need to study your solution when I have time. I confess I did try something like this but my idea was quite unsophisticated and I just tried to memoise everything (which blew up my JVM heap because there are too many states).