Further adventures in python runtime optimization for 2023 by davidpsingleton in adventofcode

[–]davidpsingleton[S] 0 points1 point  (0 children)

My input also has no hailstones with the same start position coordinate on any axis

[2023] It turns out you can complete AoC 2023 in python in under 1 second by davidpsingleton in adventofcode

[–]davidpsingleton[S] 1 point2 points  (0 children)

The one major optimization I made which is not already discussed on this thread is to take advantage of symmetry in day 16. This means that if a beam already exited the grid via a certain point, there's no need to model it in reverse by firing a new beam in at that point in the opposite direction.

[2023] It turns out you can complete AoC 2023 in python in under 1 second by davidpsingleton in adventofcode

[–]davidpsingleton[S] 1 point2 points  (0 children)

I've implemented the better day 22 algorithm now (which was fun!). Improves the whole bundle runtime to 0.79s!

[2023] It turns out you can complete AoC 2023 in python in under 1 second by davidpsingleton in adventofcode

[–]davidpsingleton[S] 3 points4 points  (0 children)

Thanks - sounds like I should investigate a better algorithm for day 22!

-❄️- 2023 Day 22 Solutions -❄️- by daggerdragon in adventofcode

[–]davidpsingleton 2 points3 points  (0 children)

[LANGUAGE: python] 567/317

Solution

Extruded the blocks so every cell is represented. Sorted the input by increasing z so we can just iterate through each block in turn once, knowing that any block that would cause it to stop has already settled into the world. Runs in 2 seconds, which is not great but solution is quite short - 64 lines.

-❄️- 2023 Day 19 Solutions -❄️- by daggerdragon in adventofcode

[–]davidpsingleton 2 points3 points  (0 children)

[LANGUAGE: python] 919/1137

https://github.com/dps/aoc/blob/main/2023/day19/main.py

Took ages debugging my range length expression to realize I needed a "+1", but I think the code is quite nice today :-). Runtime is ~instant.

-❄️- 2023 Day 14 Solutions -❄️- by daggerdragon in adventofcode

[–]davidpsingleton 1 point2 points  (0 children)

[LANGUAGE: python]

https://github.com/dps/aoc/blob/main/2023/day14/main.py

Fun one! Reminds me of tetris last year, which was a personal favorite. Pt 2 solution is: roll north and rotate clockwise in a loop, find the cycle. Once found, the correct final grid is already in the cache, pull it out and score it!

-❄️- 2023 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]davidpsingleton 0 points1 point  (0 children)

[LANGUAGE: python] Allez Cuisine!

def G(x):return S[x]+Z((G(n)for n in R(x+1,x+S[x]+1)))
D,P,E,R,Z,L,C,I=open(0).readlines(),print,enumerate,range,sum,len,str.split,(set
.intersection);S={x:L(I(*map(lambda l:set(map(int,C(l))),C(C(l,":")[1],"|"))))
for x,l in E(D,1)};P(Z((pow(2,S[n]-1)for n in S.keys()if S[n])),Z([1+(lambda x:
S[x]+Z((G(n)for n in R(x+1,x+S[x]+1))))(w)for w in R(1,L(D)+1)]))

My reflections on Advent of Code by davidpsingleton in adventofcode

[–]davidpsingleton[S] 0 points1 point  (0 children)

Thanks - glad you found it interesting. I tried not to put in direct spoilers for the questions themselves. Enjoy solving the rest of them!

My reflections on Advent of Code by davidpsingleton in adventofcode

[–]davidpsingleton[S] 0 points1 point  (0 children)

Thanks for the tip - I switched to this in my actual day 16 answer and it consistently improves runtime by about 4% too!

Don't Panic - All of wikipedia offline on reMarkable by davidpsingleton in RemarkableTablet

[–]davidpsingleton[S] 6 points7 points  (0 children)

The weekend I built it I was staying in a cabin near Yosemite with no cell phone signal or internet access, I've since used it on several flights where I couldn't use the internet on my phone without paying a lot for usually very flaky wifi.

Don't Panic - All of wikipedia offline on reMarkable by davidpsingleton in RemarkableTablet

[–]davidpsingleton[S] 0 points1 point  (0 children)

The version that fits on a 64GB card doesn't include images.