Created
November 22, 2014 13:13
-
-
Save mattseymour/25d86505ff46729de5cf to your computer and use it in GitHub Desktop.
Python - 100 lightbulbs problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a simple bit of code which solves the 100 lightbulbs problem. | |
Its not the most efficient but it does the job. | |
""" | |
def switch(list_length, iterations): | |
switches_on = [] | |
switches = { i:False for i in range(1,list_length+1)} | |
for i in range(1, iterations+1): | |
for j in range(1, list_length+1): | |
if j % i == 0: | |
switches[j] = False if switches[j] else True | |
if i == list_length: | |
if switches[j]: | |
switches_on.append(j) | |
return switches_on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment