One of the most difficult questions I've ever seen, lol. You are in a train that consists of an unknown number or carriages. The train moves in a circle, with NO locomotive (the carriages are joined together to form a circle), so you can go round and round from one carriage to another forever. In each carriage there is a light. The lights in all carriages are randomly turned on or off. So for example there could be 1 carriage with a light on and the rest off or 5 carriages with a light on and the rest off.
You can switch on or off the light in the carriage that you are in. THIS IS THE ONLY ACTION PERMITTED. You can also move from one carriage to another. Find a METHOD to count the number of carriages
Is there any maximum limit on the number of carriages? I think that there absolutely must be for this problem to be solvable.
Yes, it's less than infinity. So such a number exists.
Yes, in order to find the answer there has to be a limit, or a range for the number of carriges.
Make sure the light is on in the carriage that you start on, and the one to your left. Now move to your right turning off every light you see, counting how many carriages you pass. At some point, you'll find two in a row that are on, and a bunch of them that are off Turn the first light off, and leave the second one on. If you think you've gone full circle, go back the same number of carriages that you first went. If the light that was to the left of your starting carriage is off, you've gone full circle, and know the number of carriages. If it's still on, try again. Eventually, you'll find how many carriages there are.
You could turn on the light in the carriage you are in, then go around turning of the rest, and count them until you get back to the lit one.
@summerainkisses that requires knowing what carriage was the first. How do you determine that? You might just be unlucky, have a train that's 1,000,000,000 carriages long, and there's a pattern in there where you have 1 light on, 9 lights off the entire way. You'll think there are 10 carriages, but there will actually be 1,000,000,000
Very true. I guess you would have to come up with a more complex pattern that would be unlikely to be repeated.
Or get of the train before you drive yourslef crazy....
But even choosing a more complex pattern, if we just wait for the pattern to be repeated, there's a chance, albeit very small, that that pattern repeats by itself some number of times. The solution I came up with doesn't rely on a repeating pattern. It relies on a known pattern changing. The tricky part is knowing exactly where that pattern is located. That's why I chose to create this known pattern at the first carriage. That we know what the pattern is, and where it's located relative to our current position. Then, we can guess when we've gone full circle, and we can test if that's true by returning to our original pattern.
Yeah i think that would be the best way to go here....there really is no way to come up with the perfect answer without having limitations to the number of carriages, so that would be the best way. That way, like you said, you can atleast test it when you think you have gone all the way around.
There is a slight problem with your answer @KingGeorge. What if there is only one carriage? With one end joined to another. It is not specified how big (long) the carriage is.
then you would know it was just one carriage..
right? lol
If we suspect there is one carriage, make sure the current light is on, go to the left, turn the light off. If we come back and the light is off, one carriage.
BRAVO!
If we suspect there are two or more carriages, my original pattern will work.
Actually scratch that. I didn't read your answer properly. Sorry lol. However there is no need to construct a pattern. turn the light on in the carriage you are in, start moving in any direction counting the carriages. as soon as you meet one with the light on - turn it off and go back. If the light in the original carriage is on, then repeat the process until it is off.
That also works, but for longer trains, you'll probably have to do a lot more walking.
Yes, but that doesn't matter. What matters is the method. You are right though, it is quicker if you use a pattern.
Join our real-time social learning platform and learn together with your friends!