There are n bulbs in a circle, each bulb has one switch associated with it, on operating the switch, it toggles the state of the corresponding bulb as well as two bulbs adjacent to that one. Given all bulbs are in off state initially, give a plan to turn all bulbs on finally.

Note: n >= 1.

Click here to see the plan

**Case 1: when n%3 = 0, bulbs are complete multiple of 3**

This is the simplest case, here assume n/3 pairs of bulbs and operate the middle bulb from each pair, ultimately all n bulbs will be on.

**Case 2: when n%3 = 1, case 1 + one extra bulb**

In this case, if we reach to a state where only one bulb is on and remaining n-1 bulbs are off, we can turn on remaining n-1 bulbs easily as (n-1) is complete multiple of 3.

Lets assume n =7, and do as described in step 1 to 5.

**Step 1**: Toggle bulbs in pair of 3, 2nd, 5th, till n-2th bulb. at this stage only nth bulb will be off and rest all will be in on state.

**Step 2**: Toggle 1st bulb, it will make 1st and 2nd bulb off and nth bulb(7th for our example) ON.

**Step 3**: Toggle 3rd bulbs, it will make 1st, 2nd and 4th bulbs off and remaining bulbs ON.

**Step 4**: Leave 1st,2nd,3rd and 4th bulbs as it is and turn off remaining (n-4) bulbs in pair of 3’s. as (n-4) is complete power of 3 this can be done easily as in case 1. after this only 2nd bulbs will be ON.

**Step 5**: Leave 2nd bulb and turn on remaining (n-1) bulbs in pair of 3’s, again as (n-1) is complete multiple of 3, this can be done easily as in case 1. at this point all bulbs will be ON.

**Case 3: when n%3 = 2, case 1 + two extra bulbs**

In this case, if we reach to a state where only two bulbs are on and remaining n-2 bulbs are off, we can turn on remaining n-2 bulbs easily as (n-2) is complete multiple of 3.

Lets assume n =8, and do as described in step 1 to 5.

**Step 1**: Toggle bulbs in pair of 3, 2nd, 5th, till (n-3)th bulb. at this stage only nth and (n-1)th bulbs will be off and rest all will be in on state.

**Step 2**:Toggle nth bulb, (8th for our case), this will leave only 1st bulb off, rest all ON.

**Step 3**: Leave 1st and nth bulb and turn off remaining (n-2) bulbs in pair of 3’s, as (n-2) is complete multiple of 3

**Step 4**: Toggle nth bulb again, this will turn on 1st and 2nd bulb and remaining all will be off.

**Step 5**: Leave 1st and 2nd bulb and turn on remaining (n-2) bulbs in pair of 3’s, as (n-2) is a complete power of 3, it can be done easily as in case 1.

jack says

switch alternative bulbs at certain point of time all bulbs will be in on state.

Arun Srinivaas says

It works only when n is multiples of 3. Note that switching one will toggle the state of adjacent. So if the adjacent is already on, it will switch it off.

Qasim says

n/3 if n is divisible by 3 else n steps are required….:)

Qasim says

n/3 if n is divisible by 3 else (n/3)+1 for every n > 3….

മൂസ Moosa says

“There are n bulbs in a circle,”

—

“in a circle” ?? i would have assumed the bulbs are inside the circle based on that

Omkar says

Simplest solution:

1, 2, 3, 4, 5, …, n

Dont believe? just try it.

sonal jha says

There is a simpler solution, if n is a multiple of 3 do it as done by author, first 1 the 1+3=4 then 4+3=7 and so on upto n/3 the number of steps taken will be n/3

otherwise, start from bulb number 1 and keep switching it on till the last bulb i.e switch on 1, then 2 then 3 and so on upto n, it will take n steps and all bulbs will be in the on state finally

(The solution given by author is also taking n steps in both the cases n=7 and n=8 if you observe closely)