Fork me on GitHub
#adventofcode
<
2023-12-08
>
norman05:12:48

Day 8 - Solutions

norman06:12:42

https://gitlab.com/maximoburrito/advent2023/-/blob/main/src/day08/main.clj After getting tricked by not trying the brute force approach, this time I wasted time on a brute force solution. When it was clear it wouldn't work, I wrote some code to explore the data a bit. Thankfully all the cycles repeated exactly, so it it was easy to calculate the solution and math where they all meet.

erdos06:12:57

solution: https://github.com/erdos/advent-of-code/blob/master/2023/day08.clj went with counting reductions over the cycle of the instructions and using reduced to shortcut.

👍 1
Andrew Belo07:12:25

https://gist.github.com/andrewbelo/7d0ae27b04da17da2b44081fc81f985c Pretty much the same solution, using reduce over the cycle

Piotr Kaznowski09:12:08

(Was lazy and added numeric-tower to deps...)

👍 1
Michaël Salihi00:12:50

Nice solution @UA2U3KW0L! mapcat would be a good candidate on line 11:

;;(into {} (comp (map parse-mapping) cat) mappings)
VS
(into {} (mapcat parse-mapping) mappings)

bhauman00:12:22

mapcat isn’t a transducer though?

Ivana00:12:06

Not sure about transduser (need chek at clojredocs), but it is definitelly List monads bind, so that is why it widelly used in algorythms based on lists 😀

bhauman00:12:14

oh wait mapcat is a transducer it’s definition is (comp (map f) cat)

👍 1
alpox10:12:23

I guess that wouldn’t have been solvable without proper data inspection 👀

cdpjenkins07:01:31

I just did day 8 In Clojure, having previously done it Kotlin. I'm pretty proud of how much more succinct my Clojure solution (very functional) is than my Kotlin one (which is a bit more OO). https://github.com/cdpjenkins/advent-of-code/blob/main/2023/clj-aoc-2023/src/clj_aoc_2023/day08.clj