Dave's Notebook

Data Science, Machine Learning, Artificial Intelligence, Visualization, and Complex Systems.

Toggling Light Bulb Problem

February 28, 2023

The video published by numberphile a few days ago about the Toggling Light Bulb Problem is very interesting. Here's some code to visualize it in the console.

lights = [0]*100 print("".join(map(str,lights))) for person in range(1,101): prt = [chr(32)]*100 for l in range(1,101): if l % person == 0: lights[l-1]=1-lights[l-1] if lights[l-1]==1: prt[l-1] = chr(9608) print("".join(prt))