# Laser and mirrors on a 4x4 grid

You are given an empty 4x4 grid. You can place some diagonal mirrors into the cells of the grid. You then fire a laser from some location outside of the grid. The laser travels in a straight line. When it hits a mirror it bounces off at a right angle and spins the mirror by 90 degrees. The same mirror can be hit and spun multiple times.

Consider the following example. We place 4 mirrors in the centre of the grid and fire the laser below the second column. It hits the mirrors like so:

The mirrors spin around and the laser continues hitting another 2 mirrors before exiting the grid. In total it had 6 mirror hits:

What is the most number of mirror hits you can obtain on a 4x4 grid?

• Do the mirrors spin instantaneously? eg. Would there be a sliver of laser reflecting upwards from the top-left mirror and to the right of the top-right mirror? Nov 30 '21 at 2:36
• First the laser bounces then the mirror spins. So it is not instant. Nov 30 '21 at 2:57
• Note in the final configuration, the bottom two mirrors will be in their starting orientation. Nov 30 '21 at 2:59
• Isn't this just Langton's ants with possible empty cells. Nov 30 '21 at 9:12
• @WhatsUp Not quite Langton's ants. In this, turning right or left also depends on where the ant is coming from. Dec 10 '21 at 0:21

Proving a solution to be optimal will require programmatically checking all possible mirror placements, let's go ahead and do that.

The results are in, and the winner is:

This layout, which scores 49 hits!

This optimal solution is essentially unique. Aside from reflections and rotations, the only other optimal solution is the inverse, which follows the same path in reverse and has as it's initial position the final position of the above solution with all mirrors rotated.

• @DmitryKamenetsky An infinite loop is impossible on any finite grid. Every mirror involved in the loop will be hit an infinite number of times. Consider the left-most column containing such mirrors, and then the top-most mirror in that column. That mirror will deflect the laser to the top or left in one of its orientations, sending the laser out into space and breaking the loop. Nov 30 '21 at 10:09
• @RossPresser My argument holds for all four corners, so you need at least four. You could of course have them arranged on the corners of a rectangle, with the laser going looping around in that rectangle. There is however no way to set it up without the laser gun being in the way, even with additional spinning mirrors. The reason is that everything is time-reversible. If you film it going through one of the loops, you could play that backwards repeatedly and it would still be a valid looped path. That path loops, so could never go back to the laser gun that supposedly started it. Nov 30 '21 at 15:53
• @Stef No, that will take a bit more effort. I could probably create an animation in Blender, but that may take a while as I have no prior experience with the software. Nov 30 '21 at 16:47
• @FirstName 4x4 has just over 43 million possible grids. 5x5 has nearly 20 thousand times as many. Run time for 4x4 is under a minute. For 5x5, could be over a week. Nov 30 '21 at 21:44
• @FirstName Easy enough. Optimal solution for 3x3 has 18 hits. With the added condition that all cells must contain a mirror, optimal solutions have 17, 46, and 85 hits. Allowing exactly one vacant cell limits the search space enough that 5x5 is still feasible (~450 million grids). In that case optimal solutions have 18, 49, and 102 hits. Dec 1 '21 at 0:03

This is not an answer but here is an animation showing Daniel Mathias's answer.

• I love this! Thank you for making it. Dec 2 '21 at 23:46