adventofcode

2023-12-08T05:59:48.997979Z

Day 8 - Solutions

alpox 2023-12-09T10:43:23.894139Z

I guess that wouldn’t have been solvable without proper data inspection πŸ‘€

Ryan Martin 2023-12-14T15:51:55.893189Z

here's my solution: https://github.com/rmrt1n/advent-of-code-2023-clj/blob/main/src/aoc/day08.clj

2023-12-08T06:11:42.055659Z

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.

erdos 2023-12-08T06:20:57.731309Z

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
2023-12-08T07:12:25.399149Z

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

2024-01-22T07:14:31.876309Z

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

Arnaud Geiser 2023-12-08T08:51:07.546219Z

Thank you norman for the hint. https://github.com/arnaudgeiser/advent-of-code/blob/master/2023/clojure/src/advent_of_code/day8.clj

karlis 2023-12-08T08:54:56.089779Z

https://github.com/skazhy/advent/blob/master/src/advent/2023/day8.clj nice and easy πŸ™‚

2023-12-08T09:32:08.006739Z

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

πŸ‘ 1
Casey 2023-12-08T11:56:30.110979Z

wasted quite some time on the brute force approach for part2 before I actually looked at the size of the problem space and noped out. i reached for lcm because there's always a gcd/lcm puzzle in AOC and all the emphasis on "simultaneously" walking part2 made me think I probably shouldn't actually do that. Why LCM works though is pretty untuitive for me. https://github.com/Ramblurr/advent-of-code/blob/main/src/aoc/2023/day08.clj

genmeblog 2023-12-08T12:20:15.288449Z

cycle, reductions, take-while and lcm https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2023/day08.clj

πŸ‘ 2
tschady 2023-12-08T12:55:25.759479Z

iterate and take-upto , no reduce. https://github.com/tschady/advent-of-code/blob/main/src/aoc/2023/d08.clj

Ivana 2023-12-08T15:37:54.354669Z

Second part is waaay goood! I enjoyed and feel fun!

(defn f [i n]
  (cond
    (> (* i i) n) [n]
    (zero? (mod n i)) (conj (f i (quot n i)) i)
    :else (f (inc i) n)))

(let [[path m] (str/split input #"\n\n" 2)
      m (->> (str/split m #"\n")
             (keep (fn [s] (-> s
                               (str/replace #"[A-Z0-9]+" #(str "\"" % "\""))
                               (str/split #"\=" 2)
                               (->> (mapv read-string)))))
             (into {}))
      lr (fn [i p] (let [[l r] (get m p)
                         i (mod i (count path))]
                     (if (= \L (get path i)) l r)))
      g (fn [p-start]
          (loop [p p-start
                 i 0]
            (let [p (lr i p)]
              (if (= \Z (get p 2))
                (inc i)
                (recur p (inc i))))))]
  (->>  m
        keys
        (filter #(= \A (get % 2)))
        (map (comp frequencies (partial f 2) g))
        (apply merge-with max)
        (mapcat identity)
        (apply *)))

rjray 2023-12-08T17:25:31.979319Z

https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day08.clj I also (briefly) tried to brute-force part 2, and also figured out the cycles. Used clojure.math.numeric-tower/lcm for the math.

Ivana 2023-12-08T17:34:05.186719Z

Lcm is easy to implement - look at f (efficient fast factorization, although it may be even more faster - by stepping in 2 or by prime numbers) in my code above, and last 3 strings - for combining factors in lcm

πŸ‘ 1
Sam Ferrell 2023-12-08T20:19:26.033239Z

https://github.com/samcf/advent-of-code/blob/main/2023-08-haunted-wasteland.clj Finding where sequences converge is an aoc classic and I always trip up on it

🀯 1
bhauman 2023-12-08T20:40:17.916009Z

Day 8 part 2 almost tricked me into implementing LCM. But then I looked closer at the inputs. https://github.com/bhauman/adv2023/blob/main/src/adv2023/day08/sol.clj

bhauman 2023-12-08T20:49:16.072989Z

So the length of the directions string β€œLRLR …” is most likely a prime factor, because all the paths contain it. If you divide all the cycle-lengths (distance to first Z ending location) of the different paths followed by that factor you may end up with a set of unique prime factors, so the ultimate number of steps is (* dir-length (/ cycle-length-1 dir-length) ...

bhauman 2023-12-08T21:09:35.390999Z

how did I not remember clojure.math.numeric-tower?

Sam Ferrell 2023-12-08T21:12:08.854659Z

@bhauman I did end up dividing each steps count by my directions count and thought something fun could be done with that idea but wasn't quite sure so I abandoned it

πŸ‘ 1
Sam Ferrell 2023-12-08T21:12:16.027379Z

Nice solution!

bhauman 2023-12-08T21:14:23.798109Z

Thanks! but now I wish I’d done the numeric-tower/lcm route. It would have made my second answer very brief.

bhauman 2023-12-08T21:35:35.218179Z

I’m really enjoying reading everyone’s solutions. This is my kind of fun. πŸŽ„

Felipe 2023-12-08T23:08:37.656589Z

really happy with mine! https://github.com/FelipeCortez/advent-of-code/blob/master/2023/08.clj

πŸ‘ 2
2023-12-09T00:49:50.597679Z

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

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

bhauman 2023-12-09T00:51:22.968119Z

mapcat isn’t a transducer though?

Ivana 2023-12-09T00:55:06.900499Z

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 πŸ˜€

bhauman 2023-12-09T00:55:14.578729Z

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

πŸ‘ 1
2023-12-08T17:13:14.197659Z

This gave me a chuckle.

πŸ˜‚ 9
πŸ˜† 3
πŸ’ͺ 2
5
2023-12-08T20:56:53.265739Z

I got that. The odd thing is that if you ask it to translate the input to English, it does change it

2023-12-08T21:15:39.015959Z

Yeah, it translates to, "HELP! I'M TRAPPED INSIDE A GRAPH TRAVERSAL PROBLEM!"

πŸ˜‚ 1