adventofcode

2022-12-20T06:11:23.088819Z

Day 20 - Solutions

Aleks 2022-12-21T09:27:16.599389Z

@bhauman how long will it calculate?

bhauman 2022-12-21T11:45:00.073459Z

forever?

bhauman 2022-12-21T11:45:25.347849Z

a few minutes for sure

oddsor 2022-12-21T11:59:37.694659Z

I used a mutable list to perform the reordering to cut down the runtime from 80 seconds to 2 in my solution 🫢 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
2022-12-20T06:11:47.578689Z

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

rjray 2022-12-20T06:12:00.906929Z

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

2022-12-20T06:20:06.774429Z

The edges were a pain to get correct.

rjray 2022-12-20T06:22:02.418429Z

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

2022-12-20T07:28:24.358519Z

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 @alexalemi 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.

stephenmhopper 2022-12-25T16:34:25.966979Z

> 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.

Aleks 2022-12-20T12:01:13.343379Z

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 Oakley 2022-12-20T13:26:52.342129Z

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 Oakley 2022-12-20T13:57:55.397999Z

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

Aleks 2022-12-20T15:24:29.216219Z

@norman 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.

bhauman 2022-12-20T17:48:32.136899Z

@norman I made this mistake as well

bhauman 2022-12-20T18:06:48.905109Z

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

bhauman 2022-12-20T18:07:16.467999Z

I had such a nice solution though 🙂

bhauman 2022-12-20T18:21:11.797699Z

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

rjray 2022-12-20T19:11:33.455919Z

Finally, a solution I'm happy with. https://github.com/rjray/advent-2022-clojure/blob/master/src/advent_of_code/day20.clj

👍 1
bhauman 2022-12-20T19:12:21.970299Z

@rjray congrats I’m still poking away here

rjray 2022-12-20T19:14:34.567619Z

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

bhauman 2022-12-20T21:51:18.781759Z

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

bhauman 2022-12-20T22:30:47.605929Z

Here it is finally: https://github.com/bhauman/advent-of-code-2022/blob/main/src/adv2022/day20/sol.clj

bhauman 2022-12-20T22:32:05.104329Z

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

bhauman 2022-12-21T04:18:53.721059Z

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)))))

Eugene Huang 2022-12-24T00:55:56.812929Z

> 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. 🙏

Aleks 2022-12-20T18:57:10.047899Z

Btw, who remembers this? 🦀 🎲 https://www.reddit.com/r/adventofcode/comments/zqh272/2022_day_20_flashbacks/

Miķelis Vindavs 2022-12-20T20:14:33.129829Z

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