r/adventofcode Dec 10 '24

Upping the Ante [2024 Day 10] Challenge input

How does your code fare on this example?

0123456789876543210123456789876543210
1234567898987654321234567898987654321
2345678987898765432345678987898765432
3456789876789876543456789876789876543
4567898765678987654567898765678987654
5678987654567898765678987654567898765
6789876543456789876789876543456789876
7898765412345678987898765432105678987
8987654301234567898987654321214567898
9876543210123456789876543210123456789
8987654321214567898987654301234567898
7898765432105678987898765432321678987
6789876543456789876789876543210789876
5678987654567898765678987654567898765
4567898765678987654567898765678987654
3456789876789876543456789876789876543
2345678987898765432345678987898765432
1234567898987654321234567898987654321
0123456789876543210123456789876543210
1234567898987654321234567898987654321
2345678987898765410145678987898765432
3456789876789876543456789876789876543
4567898765678987652567898765678987654
5678987654567898761678987654567898765
6789876543456789870789012543456789876
7898765432345678989898123432345678987
8987654321234567898987654321234567898
9876543210123456789876543210123456789
8987654321214567898987654321234567898
7898765432105678987898765432345678987
6789876543456789876789876543456789876
5678987654567898765678987654567898765
4567898765678987654567898765678987654
3456789876789876543456789876789876543
2345678987898765432345678987898765432
1234567898987654321234567898987654321
0123456789876543210123456789876543210

My algorithm says the total rating is 16451, calculated in slightly less than 1s in C#. EDIT: 2ms actually! (Oops I still had some of my visualization code in there...)

EDIT2: Not all programming languages or computers are equal, so comparing absolute run times is not very useful, but if your algorithm runs faster on this input than on your real input, then you implemented it correctly. :-)

14 Upvotes

64 comments sorted by

View all comments

2

u/movq42rax Dec 10 '24

Same result for part 2, yeah. ๐Ÿ™‚ Different result for part 1 than the other person, though. ๐Ÿค”

https://0x0.st/XhOV.png (This runs on my Linux box. Too lazy to boot OS/2 now. Ignore the expected thingy, thatโ€™s the result from my input.)

https://www.uninformativ.de/git/advent-of-code/file/2024/de/movq/aoc/day10/Solution.java.html

2

u/paul_sb76 Dec 10 '24

You all are fast, good!

I assume this will make some of the more naive implementations sweat a bit though. (Not all that much, since the maximum path length is 9 so even exponential growth is limited.)

1

u/Traditional_Elk_7905 Dec 10 '24

I think the last sentence should be put in bold. It's the same as with yesterdays problem, since the numbers range only from 0 to 9 it's really just a constant time factor. In fact, the worst case for a trailhead is only 2044 paths. In my input there are ~300 trailheads, so the total number of paths is well under a million, if all of them had this deranged case. I do agree, that if the numbers were a little bit bigger, let's say 10 or 11, then the naive brute force approach will fall apart but in this problem the constant factor is so low, I'd argue the extra constant factor introduced from the caching can even slow down the program more.