I have a solution that involves moving back and forth across the loop. You pick a starting point, car 0, and move +1 car right and ensure the light is on, then go left to car −1 and ensure the light is off; then go to car +2: ON, car −2: off, etc.
The first time you travel more than half way around the loop, you’ll toggle a switch from the “other branch”, which you’ll then discover when you reverse. That will allow you to compute the total size of the loop.
Well done, however it’s one of the more convoluted correct answers that I’ve seen.
I have a solution that involves moving back and forth across the loop. You pick a starting point, car 0, and move +1 car right and ensure the light is on, then go left to car −1 and ensure the light is off; then go to car +2: ON, car −2: off, etc.
The first time you travel more than half way around the loop, you’ll toggle a switch from the “other branch”, which you’ll then discover when you reverse. That will allow you to compute the total size of the loop.