import sys
def bulb(lights,i,steps):
print(lights)
if i == len(lights):
i = 0
while lights[i] =="0":
i += 1
if i == len(lights):
print(steps)
input()
sys.exit(0)
if i == len(lights)-2:
if lights[i+1] == "1":
if lights[i] == "0":
lights = lights[:i]+"1"+lights[i+1:]
else:
lights = lights[:i]+"0"+lights[i+1:]
steps += 1
i += 1
bulb(lights,i,steps)
elif i < len(lights)-2 and lights[i+1] == "1" and "1" not in lights[i+2:]:
if lights[i] == "0":
lights = lights[:i]+"1"+lights[i+1:]
else:
lights = lights[:i]+"0"+lights[i+1:]
i+= 1
steps += 1
bulb(lights,i,steps)
if steps %2 == 0:
if lights[-1] == "0":
lights = lights[:-1]+"1"
else:
lights = lights[:-1]+"0"
steps += 1
bulb(lights,i,steps)
else:
i += 1
bulb(lights,i,steps)
bulb("10110",0,0))
i = 0
steps = 0
light = input("code? ")
check = True
while check:
print(light)
if i >= len(light):
i = 0
while light[i] =="0":
i += 1
if i == len(light):
check = False
print(steps)
break
if steps%2 == 0:
if light[-1] == "0":
light = light[:-1] +"1"
else:
light = light[:-1] +"0"
i += 1
steps += 1
elif i == len(light)-2:
if light[i] == "0":
light = light[:i] +"1"+light[i+1:]
else:
light = light[:i] +"0"+light[i+1:]
i+= 1
steps += 1
elif i < len(light)-2 and light[i+1] =="1" and "1" not in light[i+2:]:
if light[i] == "0":
light = light[:i] +"1"+light[i+1:]
else:
light = light[:i] +"0"+light[i+1:]
i += 1
steps += 1
else:
i+=1
i = 0
steps = 0
light = "100101111100"
check = True
while check:
print(light)
if i >= len(light):
i = 0
while light[i] =="0":
i += 1
if i == len(light):
check = False
print(steps)
break
if i == len(light)-2 and light[-1] == "1":
if light[i] == "0":
light = light[:i] +"1"+light[i+1:]
else:
light = light[:i] +"0"+light[i+1:]
i+= 1
steps += 1
elif i < len(light)-2 and light[i+1] =="1" and "1" not in light[i+2:]:
if light[i] == "0":
light = light[:i] +"1"+light[i+1:]
else:
light = light[:i] +"0"+light[i+1:]
i += 1
steps += 1
elif len(light)-1 == i:
if light[-1] == "0":
light = light[:-1] +"1"
else:
light = light[:-1] +"0"
i += 1
steps += 1
else:
i+=1
i = 0
steps = 0
light = "101110"
id = -2
while light[id] =="1":
id -= 1
if id%2 == 0:
if light[-1] =="0":
steps += 1
light = light[:-1]+"1"
else:
if light[-1] == "1":
steps+= 1
light = light[:-1] +"0"
check = True
while check:
print(light)
if i >= len(light):
i = 0
while light[i] =="0":
i += 1
if i == len(light):
check = False
print(steps)
break
if i == len(light)-2 and light[-1] == "1":
if light[i] == "0":
light = light[:i] +"1"+light[i+1:]
else:
light = light[:i] +"0"+light[i+1:]
i+= 1
steps += 1
elif i < len(light)-2 and light[i+1] =="1" and "1" not in light[i+2:]:
if light[i] == "0":
light = light[:i] +"1"+light[i+1:]
else:
light = light[:i] +"0"+light[i+1:]
i += 1
steps += 1
elif len(light)-1 == i:
if light[-1] == "0":
light = light[:-1] +"1"
else:
light = light[:-1] +"0"
i += 1
steps += 1
else:
i+=1
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.