AnnouncementsFunnyVideosMusicAncapsTechnologyEconomicsPrivacyGIFSCringeAnarchyFilmPicsThemesIdeas4MatrixAskMatrixHelpTop Subs
1

https://adventofcode.com/2023/day/1

Try to work out the problem yourself before looking at other people's solutions.

Comment preview
[-]x0x7
0(+0|0)

I'm still working out part 2 of day one myself. I should have it up in a bit now that I've identified a better strategy. But I may as well share my part 1 now:

https://lab.gvid.tv/x0x7/AdventOfCodeSolutions/src/branch/main/2023/Day+1/part1.js

i like this idea. i am very tired, and very busy. but i will try!

[-]x0x7
0(+0|0)

This is my part 2:

https://lab.gvid.tv/x0x7/AdventOfCodeSolutions/src/branch/main/2023/Day+1/part2.js

The key thing that made my first attempt fail was overlap between words. eightwo.

This is a problem because it wants the first and last valid word. My first attempt was destructively translating the text to the format that the part 1 code would handle. eightwo -> 8wo.

So the working solution I ended up with translates each line into a list of all valid numbers in the line and their position. We then sort by position, take the first and last, and the rest is math.

Here is the failed version: https://lab.gvid.tv/x0x7/AdventOfCodeSolutions/src/branch/main/2023/Day+1/part2_first_attempt.js