Subfield: Combinatorics


Question: Elizabeth is in an "escape room" puzzle. She is in a room with one door which is locked at the start of the puzzle. The room contains $n$ light switches, each of which is initially off. Each minute, she must flip exactly $k$ different light switches (to "flip" a switch means to turn it on if it is currently off, and off if it is currently on). At the end of each minute, if all of the switches are on, then the door unlocks and Elizabeth escapes from the room.

Let $E(n, k)$ be the minimum number of minutes required for Elizabeth to escape, for positive integers $n, k$ with $k \leq n$. For example, $E(2,1)=2$ because Elizabeth cannot escape in one minute (there are two switches and one must be flipped every minute) but she can escape in two minutes (by flipping Switch 1 in the first minute and Switch 2 in the second minute). Define $E(n, k)=\infty$ if the puzzle is impossible to solve (that is, if it is impossible to have all switches on at the end of any minute).

For convenience, assume the $n$ light switches are numbered 1 through $n$.
Prove that if $k$ is odd and $k \leq \frac{n}{2}$, then either $E(n, k)=\left\lceil\frac{n}{k}\right\rceil$ or $E(n, k)=\left\lceil\frac{n}{k}\right\rceil+1$.

Solution:
First we prove that if $n$ and $k$ are both even and $k \leq \frac{n}{2}$, then $E(n, k)=\left\lceil\frac{n}{k}\right\rceil$.

Proof. First, if $k$ divides $n$, then $E(n, k)=\frac{n}{k}=\left\lceil\frac{n}{k}\right\rceil$. Assume then that $k$ does not divide $n$. Then let $r=\left\lceil\frac{n}{k}\right\rceil$, which implies $(r-1) k<n<r k$.

Because $(r-1) k<n$, it follows that $r-1$ minutes are not enough to flip each switch once, so $E(n, k) \geq r$.

Because $n$ and $k$ are even, it follows that $r k$ and $r k-n$ are also even. Then $r k-n=2 b$ for some integer $b \geq 1$, and note that $b<k$ because $r k-k<n$. Then the following strategy turns all of the lights on in $r$ minutes.

- In each of the first three minutes, flip switches 1 through $b$, along with the next $k-b$ switches that have not yet been flipped. This leaves $b+3(k-b)$ lights on, and the rest off. Note that $b+3(k-b)=3 k-2 b=3 k-(r k-n)=n-k(r-3)$.
- In each of the remaining $r-3$ minutes, flip the first $k$ switches that have never been flipped before.

This strategy turns on the remaining $k(r-3)$ lights, and Elizabeth escapes the room after $r$ minutes.


First, if $k$ divides $n$, then $E(n, k)=\frac{n}{k}=\left\lceil\frac{n}{k}\right\rceil$. Assume then that $k$ does not divide $n$. Then let $r=\left\lceil\frac{n}{k}\right\rceil$, which implies $(r-1) k<n<r k$.

Because $(r-1) k<n$, it follows that $r-1$ minutes are not enough to flip each switch once, so $E(n, k) \geq r$.



Exactly one of $r k-n$ and $(r+1) k-n$ is even. There are two cases.

Case 1: Suppose $r k-n=2 b$ for some integer $b \geq 1$. As in the proof above, b<k$. Then the following strategy turns all of the lights on in $r$ minutes.

- In each of the first three minutes, flip switches 1 through $b$, along with the next $k-b$ switches that have not yet been flipped. This leaves $b+3(k-b)$ lights on, and the rest off. Note that $b+3(k-b)=3 k-2 b=3 k-(r k-n)=n-k(r-3)$.
- In each of the remaining $r-3$ minutes, flip the first $k$ switches that have never been flipped before.

This strategy turns on the remaining $k(r-3)$ lights, and Elizabeth escapes the room after $r$ minutes.

Case 2: Suppose $(r+1) k-n=2 b$ for some integer $b \geq 1$. As in the solution to proof above, b<k$. Then the following strategy turns all of the lights on in $r+1$ minutes.

- In each of the first three minutes, flip switches 1 through $b$, along with the next $k-b$ switches that have not yet been flipped. This leaves $b+3(k-b)$ lights on, and the rest off. Note that $b+3(k-b)=3 k-2 b=3 k-(r k+k-n)=n-k(r-2)$.
- In each of the remaining $r-2$ minutes, flip the first $k$ switches that have never been flipped before.

This strategy turns on the remaining $k(r-2)$ lights, and Elizabeth escapes the room after $r+1$ minutes.