Skip to content

Instantly share code, notes, and snippets.

@mattseymour
Created November 22, 2014 13:13
Embed
What would you like to do?
Python - 100 lightbulbs problem
"""
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