Introduction
Found the following interesting problem and made attempt in solving it. While there are some already existing posts describing quite analogical problem on MathStack Exchange platform (no duplication of already existing post):
- 26 light switches flipped by multiples of 1, 2, 3, 4 .... to 26. How many light switches are flipped on?
- A Drunken Prison Guard.
- The locker problem - why squares?
however I am fond of constructing rigorous solution in so-called "full glory of details" (i.e. with all intermediate steps shown). The point is that the replies attached to the above mentioned posts provide just outlines of solution. I would like to provide a detailed solution. This is going to differentiate between other posts related to similar, but not exaclty the same problem. This is the main motivation of establishment of new post from my side.
Description
There are $1,000$ light bulbs numbered from $1$ to $1000$. A switching mechanism changes state of some bulbs (from “on” to “off” and vice versa). If the switch is pressed for the $k$-th time, all bulbs, whose indices are divisible by $k$, change their states. At the beginning of experiment, all bulbs are off.
The experiment is initiated:
After pressing the switch for the 1st time ($k = 1$), all bulbs are “on.”
After pressing the switch for the 2nd time ($k = 2$), all bulbs with even indices are “off” and all bulbs with odd indices remain “on.”
After pressing the switch for the 3rd time ($k = 3$), all odd bulbs not divisible by 3, and all even bulbs divisible by 3 are “on”. Other bulbs are “off.”
etc.
The switching occured $1000$ times.
Which bulbs were “on” at this stage?
My extended attempt
Let $n \in [0, 1000] \cap \mathbb{N}$. Let $M_{2 \times 1000}(\mathbb{N})$ be a set of matrices having $2$ rows and $1000$ columns in which every entry is a natural number.
Let $A_{n} \in M_{2 \times 1000}(\mathbb{N})$ be a matrix representing encoded states of light bulbs in analysed network after $n$-th switch pressing. Let $A_{n}$ be represented in the following way:
- $1$st row represents numbers of indices of light bulbs
- $2$nd row represents states of light bulbs in the form of either $1$ (switched on) or $0$ (switched off).
The analysis of initial states yields the following conclusions:
-
- light bulb with index whose number has odd number of natural factors (including number $1$ and itself) has $1$ (switched on) as final state
-
- light bulb with index whose number has even number of natural factors (including number $1$ and itself) has $0$ (switched off) as final state
-
- Let $k \in \{ 1, \dots, 1000 \}$. Let $m \in \mathbb{N}$. Let $b_{k}^{m} \in \mathbb{Z}_{2}$ be a state of light bulb with index number $k$ after $m$-th switch pressing operation. Then $$ b_{k}^{m} = \big\lvert \{ l \in \mathbb{N} : l \leq m \land l|k \} \big\rvert \; (mod \; 2) $$
In other words, the state of light bulb with index $k$ after $m$-th switch pressing operation is equal to number of all natural divisors of $k$ that do not exceed value of $m$ and to this number is applied modulo $2$ operator.
-
- Let $S_{1000} \in \mathbb{N}$ be a number of light bulbs in analysed network that after $1000$-th switching press operation are switched on. Then $$ S_{1000} = \sum\limits_{k=1}^{1000}b_{k}^{1000} $$
It is required to inspect all natural divisors of every natural number from $1$ to $1000$ individually and apply formula derived in point (3). In this case there is a need of utilisation of computational power to do verifications for each considered natural number. The reason is a lack of explicit pattern of distribution of prime numbers. Hence, it is required to do verification for every natural number from $1$ up to $1000$ individually for each natural number.
For the above mentioned repetitive computations we use some programming stuff. The implementation of the above conclusions generates number 31.
For the above mentioned repetitive computations we use the following code snippet:
def get_number_of_natural_factors(input_number: int) -> int:
# each natural number is divisible by 1
# hence counter should start with 1
number_of_natural_divisors = 1
exclusive_upper_boundary = input_number + 1
for potential_divisor in range(2, exclusive_upper_boundary, 1):
if input_number % potential_divisor == 0:
number_of_natural_divisors += 1
return number_of_natural_divisors
def number_of_operating_light_bulbs(input_number_of_light_bulbs: int) -> int:
list_of_number_of_divisors_modulo_2
= [get_number_of_natural_factors(input_number=index) % 2 \
for index in range(1, input_number_of_light_bulbs + 1)]
initial_index = 0
exclusive_index = 1000
for index in range(initial_index, exclusive_index):
if list_of_number_of_divisors_modulo_2[index] == 1:
# index + 1 yields value of index of light bulb
index_with_odd_number_of_divisors = index + 1
print(index_with_odd_number_of_divisors)
return sum(list_of_number_of_divisors_modulo_2)
The inclusion of the following code snippet
print(get_number_of_operating_light_bulbs(input_number_of_light_bulbs=1000))
prints number 31 and the following numbers:
1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961.
Hence, after $1000$-th switch pressing operation there are $31$ light bulbs that are switched on.
Question
Do you think that my solution is fully explicit?
Hope this content will enrich MathStack Exchange platform further!