Fork me on GitHub
#adventofcode
<
2022-12-20
>
Alex Alemi06:12:23

Day 20 - Solutions

Alex Alemi06:12:47

Relatively straight forward once I realized numbers were repeated in the input: https://github.com/alexalemi/advent/blob/main/2022/clojure/p20.clj

rjray06:12:00

I'm struggling with the actual "mix" operation. The rest I've got working.

Alex Alemi06:12:06

The edges were a pain to get correct.

rjray06:12:02

It's my lack of experience with Clojure and FP. I can see several ways to do it, but not with immutable data structures.

norman07:12:24

https://gitlab.com/maximoburrito/advent2022/-/blob/main/src/day20/main.clj Wow. I 100% was stumped for well over an hour before I discovered the non-unique numbers in the input. The lengths of the lists really made that annoying to debug and discover. Once I eventually got that, I apparently was so mentally out of it that I decided to store the original index in metadata rather than just add it to the data like @U02P133R2SZ did above. I guess this why I shouldn't feed my code after midnight.... On the topic of edges, I originally spent at least 15 minutes of my first pass worrying about how to get things at the front or back of the cycle to work before I realized it didn't matter as long as order was maintained. When you start from "0" it's all the same.

alekszelark12:12:13

Used my prev implementation of circular list, but now a bit tuned it https://github.com/zelark/AoC-2022/blob/master/src/zelark/aoc_2022/day_20.clj

Callum Oakley13:12:52

https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2022/20.clj store prev and next index in vectors and update those rather than moving things around. thought it would be faster to make the vectors transient but doesn't actually make much of a difference 🤷 . part 1 1s, part 2 10s

Callum Oakley13:12:55

can cut the runtime in half by never moving more than halfway round the ring (move in the other direction instead)

alekszelark15:12:29

@U0954HGDQ you are not only one, on Reddit people complain about it. I also was bitten by this assumption, but almost immediately realized what went wrong.

bhauman17:12:32

@U0954HGDQ I made this mistake as well

bhauman18:12:48

hmmm but my answer is still off … and so it begins

bhauman18:12:16

I had such a nice solution though 🙂

bhauman18:12:11

sure it could be a hash collision I’m sure thats it (sarcasm) ……. otherwise I’ll have to write an alternative simple/slow implementation of the move function to test it against my main one to see if there is a disparity

bhauman19:12:21

@UEF091BP0 congrats I’m still poking away here

rjray19:12:34

I had to (literally) sleep on it (the puzzles unlock at 9PM in my time zone).

bhauman21:12:18

yeah this feels pretty mean, the example doesn’t cover several of the edge cases

bhauman22:12:05

I used a priority map, so there was no need to renumber indexes

bhauman04:12:53

I really thought about this and I think I got it down to nothing using some lazy trickery to simulate a circular list.

(defn item-mover [lst [index-diff _ :as item-a]]
  (if (zero? index-diff)
    lst
    (let [new-size (dec (count lst))]
      (->> (cycle lst)
           (drop-while #(not= item-a %))
           rest
           (take new-size)
           cycle
           (drop (mod index-diff new-size))
           (take new-size)
           (cons item-a)))))

alekszelark09:12:16

@U064J0EFR how long will it calculate?

bhauman11:12:25

a few minutes for sure

oddsor11:12:37

I used a mutable list to perform the reordering to cut down the runtime from 80 seconds to 2 in my solution :face_with_open_eyes_and_hand_over_mouth: Not too happy with that, but I couldn’t think of something more clever than just moving the numbers around in a data structure! https://github.com/Oddsor/advent-of-code-clj/blob/master/src/y2022/d20.clj

👏 1
Eugene Huang00:12:56

> On the topic of edges, I originally spent at least 15 minutes of my first pass worrying about how to get things at the front or back of the cycle to work before I realized it didn’t matter as long as order was maintained. When you start from “0” it’s all the same. omg… coming back to days i missed and i spent much more than 15 minutes trying to understand the edges until i saw this. 🙏

stephenmhopper16:12:25

> once I realized numbers were repeated in the input Yeah, this set me back quite awhile. None of the sample inputs were repeats, so this was unexpected.

Miķelis Vindavs20:12:33

yep, the mod off by 1 error was what cost me the most time today 😞