# Lockers Puzzle

You are given a row of 100 lockers, initially all closed.

On the first pass, every locker is opened.

On the second pass, every second locker is closed.

On the third pass, the state of every third locker is toggled from open to closed or closed to open.

**If this continues for 100 passes, how many lockers are open?**

**Solution:**

Note that after the k’th pass, the first k lockers stop changing.

Before taking on the challenge of 100 lockers, let’s look at the first 12 lockers after the 12’th pass.

They are closed except for 1,4, and 9.

On pass k, locker numbers that are a multiple of k are toggled.

A locker number with an even number of integer multiples is toggled open then closed.

For a locker to remain open, it must have an odd number of integer multiples.

This occurs for numbers that are the squares of integers.

For 100 lockers, there are 10 numbers that are squared integers: 1,4,9,16,25,36,49,64,81, and 100.

**For k lockers, floor(sqrt(k)) will be open.**