Fork me on GitHub
#adventofcode
<
2023-12-21
>
alekszelark18:12:55

Day 21 — Solutions :face_with_spiral_eyes:

alekszelark19:12:13

Uhhh! Finally I nailed it. My code is dirty, I’m not sure if I want to post it at all. I believe it’s the toughest day so far

rjray19:12:01

https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day21.clj I finished last night, after (shamefully) just translating a Python solution to Clojure. As if to taunt me, the Clojure takes 2x time to run that the Python did. I look forward to seeing other solutions, because I want to understand it better than I do from just cribbing Python. 😞. (Part 1 just took me ~30 min to solve, and about 1.3s to run.)

alekszelark19:12:33

Part 1 is pretty simple, not fast but a simple solution:

(defn reached-plots [adjecent start limit]
  (->> (iterate #(set (mapcat adjecent %)) [start])
       (drop limit)
       (first)))

👍 1
genmeblog19:12:35

I'm still at part two. First part was memoized recursive function in my case. But I like above solution, which is much simpler.

bhauman05:12:46

Well that was hard! Part 2 is solved I have pages of doodles and drawings that I used to figure it out. https://github.com/bhauman/adv2023/blob/main/src/adv2023/day21/sol.clj

bhauman05:12:34

I’m glad other folks struggled too. I didn’t want to look and see that people had done this in 5 minutes 🙂

jurjanpaul13:12:37

Calculated the number for a couple of board widths (relying on the fact that each generation’s number is equal to the number for the generation before the last + the number of new positions taking steps from the last ‘frontier’ that were not in the ‘frontier’ before that) and then derived the corresponding quadratic formula (not programming, so does feel like cheating) which gave me the solution.