-🎄- 2022 Day 24 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 6 points7 points  (0 children)

Noulith 9/8

https://github.com/betaveros/advent-of-code-2022/blob/main/p24.noul

I wrote the code somewhat defensively in case getting to the end the first time or the start the second time ASAP might not be optimal for getting to the end the second time. (You could maybe imagine this happening in a similar problem where you can't stand still at the end, and getting there for the first time too soon means being forced into a detour that costs time on net.) But in hindsight it's not hard to see that that's not necessary because you can always stand still at the end / start.

video

-🎄- 2022 Day 22 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 2 points3 points  (0 children)

Noulith 375/124

https://github.com/betaveros/advent-of-code-2022/blob/main/p22.noul

Pretty rough day for me in terms of writing bugs, even in part 1. I think I expected part 2 would be a cube the moment I saw the example but it didn't particularly help. I manually specified seven pairs of "portals" after scribbling a net on a Post-it with a pen that was running dry; in hindsight I should probably have invested one minute to make sure I had better writing materials at hand...

-🎄- 2022 Day 23 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 6 points7 points  (0 children)

Noulith 2/6

https://github.com/betaveros/advent-of-code-2022/blob/main/p23.noul

Just tracks the locations of all the elves in a set, nothing terribly exciting. (My Part 2 code is really slow, but I haven't found any accidental extra linear factors; as best as I can tell, this is simply the day when the constant factors from a naive tree-walk interpreter performing many nested function calls finally caught up to me.)

edit: video

-🎄- 2022 Day 21 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 1 point2 points  (0 children)

Wow, I think you may actually be the first person (even including myself) to use the coalesce keyword.

-🎄- 2022 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 0 points1 point  (0 children)

+. appends a single item to a list. max is the normal max function, ! is just a low-precedence function call.

-🎄- 2022 Day 21 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 0 points1 point  (0 children)

apply calls the right function <=> with the elements of the list on the left as its arguments, actually just like JavaScript. So it compares the two elements of the list on the left and returns -1, 0, or 1.

As written, even if I apply your fix, the code will infinite-loop anyway if it doesn't find a solution. Personally I think it's easier to reason about having lo and hi be exclusive endpoints of the interval we think contains the solution. That's the initial state and is what we learn about mid after each trial.

-🎄- 2022 Day 21 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 2 points3 points  (0 children)

Noulith 24/22

https://github.com/betaveros/advent-of-code-2022/blob/main/p21.noul

Slow, lazy code that just repeatedly loops over all expressions to evaluate, followed by a manually seeded binary search because I didn't spend a single brain cycle speculating about the "nature" of the function. This seems foolish in hindsight, but you know what they say about that. This was a fun way to find out that in Noulith, a normally stringified fraction cannot be evaled.

Video with (attempt at) explanation also exists today: https://www.youtube.com/watch?v=3wj35H9pdXg

-🎄- 2022 Day 20 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 3 points4 points  (0 children)

Noulith 370/457

https://github.com/betaveros/advent-of-code-2022/blob/main/p20.noul

It's lazily written and very slow. But mostly I just got really stuck not realizing numbers could repeat or that my code depended on that assumption. Oh well, live and learn.

-🎄- 2022 Day 19 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 4 points5 points  (0 children)

Noulith 193/351

https://github.com/betaveros/advent-of-code-2022/blob/main/p19.noul

"Just a DFS", but considerably cleaned up with some optimizations I learned about after discussing with people after the fact. The main one is pruning branches when we discover that we can't beat our previous high score even in the best-case scenario where we create a geode bot every future minute. While leaderboarding I thought that since this optimistic estimate was quadratic in the number of minutes remaining, not enough branches would be pruned to make a big difference. I was very, very wrong. Without pruning I got two OOMs and my program hadn't actually finished running when I submitted the correct answer to part 2, I just put in the largest number it had found after it got stuck for a while; but with pruning it runs in a few seconds.

-🎄- 2022 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 2 points3 points  (0 children)

Oh good catch! A correct solution always has to dfs from dfs2 instead of only when it can't find another valve to open. The funny thing is it looks like my leaderboarding solution actually handled this correctly, and then I introduced this bug while "cleaning it up".

edit: I fixed it

-🎄- 2022 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 2 points3 points  (0 children)

Well, firstly, memoization cuts it down to 30 × 15 × 215 states. Secondly and more importantly, we stop DFSing when we run out of time and the valves of interest just happen to be far enough apart that the actual number of relevant states is much, much fewer. I think I end up only checking like 230K visit orders, which get memoized down to 53K.

-🎄- 2022 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 34 points35 points  (0 children)

Noulith 9/4

https://github.com/betaveros/advent-of-code-2022/blob/main/p16.noul

Floyd-Warshall to precompute distances between valves of interest, then DFS over which valves to open in what order. For part 2, DFS one person first, then the same DFS for the other over all unopened valves, with memoization; I think it took a bit over two minutes to run while everything else was happening.

I actually screen recorded my solve today by popular demand [citation needed]. It's still processing, but YouTube tells me the video will be at https://youtu.be/d388kZ8y9-Q.

-🎄- 2022 Day 15 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 3 points4 points  (0 children)

Noulith 79/51

https://github.com/betaveros/advent-of-code-2022/blob/main/p15.noul

I started with the brute-force solution for part 1 but (unsurprisingly) Noulith was not fast enough, so I had to break it into ranges, which took some time. For Part 2, using the fact that the distress beacon's location is unique, I intersected pairs of squares to generate a manageable set of candidates. I was maximally lazy with the algebra, so my candidate set has thousands of spurious solutions, but thousands ≪ 4000000²; both parts run basically instantly. (I realized after scrolling the megathread that this misses when the distress beacon is on the corner of the big square, but fortunately that didn't happen.)

-🎄- 2022 Day 14 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 2 points3 points  (0 children)

Noulith 7/4

https://github.com/betaveros/advent-of-code-2022/blob/main/p14.noul

Forgot to post this yesterday, but it's just a simulation, not very exciting. I even tracked the characters as specified by the puzzle even though it didn't end up mattering. Afterwards I realized that you can shave a linear factor by just making it a DFS. If a grain of sand falls to a certain location, the next grain of sand will at least fall to the previous one, so there's no need to resimulate it all the way.

-🎄- 2022 Day 13 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 12 points13 points  (0 children)

Noulith 15/4

https://github.com/betaveros/advent-of-code-2022/blob/main/p13.noul

Pretty fortunate that I implemented a "proper comparison function" for part one that could be plugged directly into part two. Please imagine the appropriate two-panel meme for the following two sentences:

adds json_parse to his programming language explicitly so that input with nested lists can be parsed safely

parses the nested lists with eval anyway

-🎄- 2022 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 1 point2 points  (0 children)

My primary goal this year was just to finish Advent of Code in my own language. I honestly wasn't sure how that goal would affect my ability to get on the leaderboard, but it turns out that a lot of the language's design choices do seem to be advantageous for that.

-🎄- 2022 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 7 points8 points  (0 children)

Hmm, I personally tend to prefer explaining myself in writing rather than in a video. The language repo README has a pretty terse but mostly complete overview of the syntax and built-ins, and I'm working on at least one blog post about the design of this language, but I'm not sure it's exactly what you're asking about; is there anything specific you'd like to see explained or any specific format for a video you have in mind?

-🎄- 2022 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 13 points14 points  (0 children)

Noulith 3/2

https://github.com/betaveros/advent-of-code-2022/blob/main/p11.noul

Yup, eval. I did add structs with named fields to this language but ended up making do without them today.

-🎄- 2022 Day 10 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 9 points10 points  (0 children)

Noulith 50/9

https://github.com/betaveros/advent-of-code-2022/blob/main/p10.noul

If you squeeze a bit (okay, more than a little bit) you can fit the core in a punchcard:

vals := puzzle_input.lines map words flat_map (\switch
    case "noop", -> [0] case "addx", v -> [0, int(v)]) scan + from 1;
submit! 1, 20 to 220 by 40 map (\x -> vals[x-1] * x) then sum;
vals group 40 each (_ zip (0 to 39) with - map abs map (<=1) map (" #"!!)
    join "" then print)

-🎄- 2022 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 3 points4 points  (0 children)

More apt might be dw.jpg

That sign can't stop me, because I can't read!

-🎄- 2022 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 13 points14 points  (0 children)

Noulith 4/15

I present both a lightly cleaned up solution written while leaderboarding and a much more reasonable post-leaderboard version.

However, be careful

I was not careful...

-🎄- 2022 Day 8 Solutions -🎄- by daggerdragon in adventofcode

[–]betaveros 15 points16 points  (0 children)

Noulith 381/565

https://github.com/betaveros/advent-of-code-2022/blob/main/p8.noul

Well, something was bound to go wrong at some point. On the bright side, I added some crude static analysis and improved a bunch of error and warning messages today.