This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-21
Channels
- # adventofcode (8)
- # announcements (20)
- # babashka (43)
- # beginners (8)
- # biff (12)
- # calva (2)
- # cider (5)
- # clerk (6)
- # clj-commons (12)
- # clj-kondo (16)
- # clojure (20)
- # clojure-denver (1)
- # clojure-europe (14)
- # clojure-nl (1)
- # clojure-norway (105)
- # clojure-uk (2)
- # clojuredesign-podcast (5)
- # clojurescript (29)
- # datomic (2)
- # hyperfiddle (13)
- # jackdaw (1)
- # jobs (4)
- # jobs-discuss (4)
- # lsp (2)
- # malli (12)
- # pathom (2)
- # pedestal (1)
- # re-frame (22)
- # shadow-cljs (37)
- # squint (28)
- # xtdb (28)
- # yamlscript (4)
Day 21 — Solutions :face_with_spiral_eyes:
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
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.)
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)))
I'm still at part two. First part was memoized recursive function in my case. But I like above solution, which is much simpler.
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
I’m glad other folks struggled too. I didn’t want to look and see that people had done this in 5 minutes 🙂
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.