100 Doors

This is an animated demonstration of the 100 Doors coding challenge - there is also a Python version without the animation if you're interested in the coding.

All the doors start off in the closed position.  First you visit every door and toggle its position (i.e. if it's open then close it, and if it's closed then open it).  Then you visit every second door and toggle it, then every third door, every fourth door, and so on, until you visit only the hundredth door and then you stop.  Which doors remain open?  Click the doors to toggle their position to attempt this yourself - press O to open, C to close or T to toggle all doors, and press S (or tap with two fingers) for the process to run automatically.

A number is the product of two factors, so does that mean that all integers have an even number of factors?  No, because for square numbers, one of the factors is multiplied by itself - i.e. there is an odd number of factors.

What does it mean if the door is selected (i.e. has a border around it)?  It means that the number on the door is a multiple of the step size - or that the step size is a factor of the number on the door.  The number of times a door is selected is the number of factors it has, and as it is opened or closed when it is selected, doors selected an even number of times will be closed, and those selected an odd number of times will be open. Towards the end of the process, when it looks like every door is being toggled, it's really every 50th door, then every 51st door, then every 52nd, etc. - as there is only one multiple of 51 below 100 then only a single door is selected.

By default there are one hundred doors, but the number can be changed with the ?doors querystring.  You can also change the speed of the animation using the ?freq querystring and giving a period in milliseconds.  For example, to have fifty doors toggling every second, add ?doors=50&freq=1000 to the end of the URL.