Click here to Skip to main content
15,037,662 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
The Snapper is a clever little device that, on one side, plugs its input plug into an output socket, and, on the other side, exposes an output socket for plugging in a light or other device.
When a Snapper is in the ON state and is receiving power from its input plug, then the device connected to its output socket is receiving power as well. When you snap your fingers
-- making a clicking sound
-- any Snapper receiving power at the time of the snap toggles between the ON and OFF states.
In hopes of destroying the universe by means of a singularity, I have purchased N Snapper devices and chained them together by plugging the first one into a power socket, the second one into the first one, and so on. The light is plugged into the Nth Snapper.
Initially, all the Snappers are in the OFF state, so only the first one is receiving power from the socket, and the light is off. I snap my fingers once, which toggles the first Snapper into the ON state and gives power to the second one. I snap my fingers again, which toggles both Snappers and then promptly cuts power off from the second one, leaving it in the ON state, but with no power. I snap my fingers the third time, which toggles the first Snapper again and gives power to the second one. Now both Snappers are in the ON state, and if my light is plugged into the second Snapper it will be on.
I keep doing this for hours. Will the light be on or off after I have snapped my fingers K times? The light is on if and only if it's receiving power from the Snapper it's plugged into.
The first line of the input gives the number of test cases, T. T lines follow. Each one contains two integers, N and K.
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is either "ON" or "OFF", indicating the state of the light bulb
1 <= T <= 1000.
1 <= N <= 10
0 <= K <= 100


1 0
1 1
4 0
4 47	         Case #1: OFF
         Case #2: ON
         Case #3: OFF
         Case #4: ON
Updated 22-Dec-13 22:17pm

Sorry, this is not a valid question. We do not do your work, whether commercial or academic. Writing this program is designed to test your skills and knowledge not those of some strangers.
My Friend,

Is this your homework question?
You should have to do the maths to figure out the concept and it's barely any maths but just a little logic. I will encourage you to take a paper and a pen. Do the few tests on notebook and based on those results, you have to figure out a logic. Then that logic is made into a flowchart or pseudo code and that pseudo code is converted in real syntax of any given language. This is how it works my dear friend.

For the moment being, I will not be giving you any hint unless you show me what have you tried and then only will I help you. BTW, I have given you the pointers to get back and start working.

With Regards
Tushar Srivastava

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900