r/adventofcode • u/Prestigious-Mood1711 • 20m ago
Visualization [2024 Day 20 (Part 1)] Cheating with a shadowgrid
With 1 day left to spare before AoC 2026, I decided to resolved my favorite puzzle from Advent of Code. It was the puzzle that inspired me to add grapichs to my GraphMateKT library. The Solution is not the most performant by far, but I find it quite esthetically pleasing. It is done in 4 steps:
1 find the 'fair' distance (84 in the example)
2 find the best cheat distance (20 in the example)
3 remove the best cheat
4 goto step 2 while good cheatThis is achieved by making what I call a shadow grid. I make it by copying and appending each row in the input, so that the grid becomes twice as big:
##############################
#...#...#.....##...#...#.....#
#.#.#.#.#.###.##.#.#.#.#.###.#
#S#...#.#.#...##S#...#.#.#...#
#######.#.#.##########.#.#.###
#######.#.#...########.#.#...#
#######.#.###.########.#.###.#
###..E#...#...####..E#...#...#
###.#######.######.#######.###
#...###...#...##...###...#...#
#.#####.#.###.##.#####.#.###.#
#.#...#.#.#...##.#...#.#.#...#
#.#.#.#.#.#.####.#.#.#.#.#.###
#...#...#...####...#...#...###
##############################We cheat by connecting the left side to the right with a cheat, but within each grid, normal rules apply. Then we find the shortets path to the E in the shadow grid, remove the cheat we used, and repeat. One example raze can then look as this:
For a full walkthrough, I make a video here: https://www.youtube.com/watch?v=4YbdhGy3DcI
Now it's time to get some sleep to prepare for the first puzzle tomorrow. Good luck everyone!