adventofcode

2022-12-24T06:53:55.810089Z

Day 24 - Solutions

Miķelis Vindavs 2022-12-24T08:01:58.619999Z

nice! i think i don’t make enough assumptions about previously visited positions

Aleks 2022-12-24T09:13:49.573459Z

The key point is we don’t care how we came in same position at a certain minute, so we can reduce the space by applying set.

Miķelis Vindavs 2022-12-24T09:14:24.007269Z

but we do care, because the winds might be different?

Miķelis Vindavs 2022-12-24T09:15:03.916989Z

they do repeat every lcm(width,height) steps, but besides that

Miķelis Vindavs 2022-12-24T09:17:06.797359Z

i fixed my occupied function, now it all runs in 2s 😄

⚡ 1
Miķelis Vindavs 2022-12-24T09:17:58.032319Z

i was caching whether a position is occupied it at a particular time. instead it makes a lot more sense to cache the position of all blizzards at a particular time, because it can be reused for all positions at that time

Aleks 2022-12-24T09:18:15.001479Z

For a certain minute wind is always the same, so if we came at position [2 2] by 10 ways, we can go with only one [2 2].

Miķelis Vindavs 2022-12-24T09:19:21.473169Z

yep, but the cache key has to be [(mod time cycle-length) position] not just position

Miķelis Vindavs 2022-12-24T09:19:50.542069Z

of course in norman’s solution all times are considered in the same iteration, so I think we’re actually talking about the same thing

Aleks 2022-12-24T09:24:10.033979Z

Yeah, I’m polishing my solution, but basically it’s similar to @norman ’s

Miķelis Vindavs 2022-12-24T09:31:23.243889Z

and actually a priority queue isn’t need either, so switching to a regular queue made it even faster 🎉

Aleks 2022-12-24T09:33:24.079659Z

Exactly, first I thought I need something like astar

Aleks 2022-12-24T10:46:44.599689Z

https://github.com/zelark/AoC-2022/blob/master/src/zelark/aoc_2022/day_24.clj Part 2 runs ~ 2,5 sec

Miķelis Vindavs 2022-12-24T10:58:39.130189Z

mod1 seems like a useful function

👍🏻 1
Aleks 2022-12-24T13:10:23.790239Z

misha 2022-12-24T13:39:29.424089Z

p2 "Elapsed time: 3514.53702 msecs" https://github.com/akovantsev/adventofcode/blob/master/src/adventofcode/y2022/day24.clj#L60-L129

misha 2022-12-24T13:44:24.430259Z

more memoization gives "Elapsed time: 2843.663069 msecs" since wind-map loops every 600 steps

Aleks 2022-12-24T14:03:32.048959Z

My answer for part 3 is 4666929 minutes. It’s just 77782 hours, or approximately 8 years of dodging blizzards. Without sleep of course.

wevrem 2023-01-01T23:44:28.161459Z

Slowly wrapping up AoC before vacation is over. I didn’t remap all the blizzards each time step. Instead I used modulo arithmetic to check if any blizzards would be at a certain spot at a certain time. https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_24_blizzards.clj

👏🏻 1
2022-12-24T07:09:52.468759Z

https://gitlab.com/maximoburrito/advent2022/-/blob/main/src/day24/main.clj I did my state management a bit differently than I normally do and ended up messing up the co-ordinates several times because of it. Probably at least a solid 30 minutes of extra debugging because of it.

Miķelis Vindavs 2022-12-24T07:46:37.588909Z

Missed my alarm clock and overlept for 90mins 😭 Today’s solution is the slowest one in terms of runtime for me, it takes 5 minutes to run. I wonder if I’m missing something real obvious about pruning the search space. @norman how fast does your solution run? it seems like you’re storing a collection of winds for each round, whereas I’m just storing the original position and checking whether a position is occupied by adding time modulo (lcm width, height) , but it’s a linear search over the winds. I wonder if your way could actually be faster

Miķelis Vindavs 2022-12-24T07:47:05.492029Z

hmm i could memoize the occupied function

Miķelis Vindavs 2022-12-24T07:53:33.160989Z

well that cut the runtime down to 2mins 😅

2022-12-24T07:58:37.423259Z

day24.main> (time (part2 full-input))
"Elapsed time: 6188.766655 msecs"
859

👍 1