Fork me on GitHub
#adventofcode
<
2023-12-16
>
wevrem06:12:06

Day 16 - Solutions

wevrem06:12:24

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.

erdos06:12:59

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.

alekszelark12:12:54

@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 ^_^

gabor.veres11:12:34

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.

alekszelark18:12:58

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

😺 1
gabor.veres18:12:58

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 facepalm.

alpox20:12:49

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.

alekszelark14:12:32

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.

cdpjenkins18:12:23

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).