# 2024 Day 20: Race Condition

**URL:** <https://forum.ada-lang.io/t/2024-day-20-race-condition/1656>\
**Category:** Advent of Code\
**Tags:** spoilers\
**Created:** [December 30, 2024, 6:16am UTC](https://forum.ada-lang.io/t/2024-day-20-race-condition/1656 "2024-12-30T06:16:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)\
**Post date:** [December 30, 2024, 6:16am UTC](https://forum.ada-lang.io/t/2024-day-20-race-condition/1656/1 "2024-12-30T06:16:03Z")

</div>

“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. 😁

---

<div class="post-metadata">

**Author:** ![zertovitch](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/zertovitch/32/90_2.png) [@zertovitch](https://forum.ada-lang.io/u/zertovitch)\
**Post date:** [December 30, 2024, 4:37pm UTC](https://forum.ada-lang.io/t/2024-day-20-race-condition/1656/2 "2024-12-30T16:37:01Z")

</div>

I am cu

> [@cantanima](#):
>
> I was pretty proud of it until I visited Reddit, where I found much more clever solutions

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

---

<div class="post-metadata">

**Author:** ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)\
**Post date:** [December 31, 2024, 4:05am UTC](https://forum.ada-lang.io/t/2024-day-20-race-condition/1656/3 "2024-12-31T04:05:13Z")

</div>

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.
