2024 Day 20: Race Condition

“Today”'s puzzle (in reality I’m 10 days behind…) was nice. “Obvious” methods that work for part 1 don’t necessarily work for part 2: I BFS’d my way through part 1 with a solution that took 4 minutes to determine the answer. That won’t work for part 2 without some serious improvement…!

My revised approach was to count how many steps each position lay from the start and from the end. (The original maze has but one path, so this is well-defined.) For each potential cheat, sum the cheat entrance’s distance from the start, the cheat exit’s distance from the end, and the cheat’s length (Manhattan distance, hence all the hemming and hawing about different cheats being equivalent when they start & end in the same point). That gives you the length of the resulting path – no BFSing around needed! – and you can compare to the baseline etc.

I was pretty proud of it until I visited Reddit, where I found much more clever solutions. … though to be honest I’m still proud of it. :grin:

2 Likes

I am cu

I am curious: what are those even more clever solutions, roughly?

I check for cheats by going through each row and column of the map, checking to see if you’re at a wall, and if not, then checking every row and column within a Manhattan distance of . So I have some massively nested for loops. The smarter (IMHO) approaches enumerate the path steps into an array, which saves time and space.