[Community Puzzle] Mirror Rotation - Puzzle discussion

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Delicious31415,validated by @DeanTheMachine,@NicknamedTwice and @TBali.
If you have any issues, feel free to ping them.

Good fun puzzle.
Please note instruction

The mirrors should be listed in reading order.

had further description

(top to bottom, left to right)

in the contributions page (in case anyone else isn’t clear :grinning:)

FYI
If you solve this via DFS, then the last validator seems to be the only one that will catch you out for taking the last valid solution instead of the one with the least flips.
I was passing all test cases without ever reducing the the best flip count from INT_MAX.

1 Like

Not really sure why I’m only failing the Shortest Path Validator.

My general process:

I’m using a DFS where every time the path reaches a mirror, it first tries to continue the path to the end (the target, a wall, out of bounds, or an infinite loop). If the path found the target in 1 or less flips OR this mirror can’t be flipped because it is still in use in this current path, I return the result. Otherwise, I try flipping the mirror to look for a potentially shorter path. If the target was found with less flips on this new path (plus this mirror), I return the result, adding this mirror to my list of flips. If not, I fix the mirror back to the way it was and return the first path’s results instead.

This works for all the test cases and the other validators, so I don’t really understand where my bug is.