Skip to main content

Probability Riddle Using Python: Lights on a Christmas Tree

 Riddle:

For the holidays, a Christmas tree was adorned with 100 lights. The lights were numbered from 1 through 100. A controller was programmed to apply a switching algorithm on every step: the light that was on is turned off, and vice versa. The algorithm works in a sequence. First, it turned all lights on. It then applied to the even numbers, then to the multiples of 3, next to the multiples of 4, and so on. What is the probability that a randomly selected light will be on after 100 steps of the algorithm?


Python Solution:






Visualization of the outcome



Riddle source:

https://www.cut-the-knot.org/Probability/LightsOnAChristmasTree.shtml