TDD the 100 Doors Kata

TDD in C#

Lance wanted to pair up and review his C# knowledge. So we joined up on Cyber-Dojo. And he chose the 100 Doors problem on the Dojo's platform. Cyber-Dojo has lots of Kata to start you off. It also has many programming languages and various test frameworks.

We are live streaming every Tue & Thur at 3pm CT. Come join us and learn TDD from a master practitioner on YouTube TDD.Academy.

In the first episode, Lance ventured a 50/50 split for the number of doors left open after the 100 passes. I could not verbalize my reasoning but felt that was wrong - my prediction was it would be very lop-sided, either most open or closed. But I could not back that intuition up with logic/reason.

It took me days to reason out my intuition... and a walk with my dog Malibu. The problem was one of the factors of the numbers from 1 - 100. A door would be left open only if it had an ODD number of factors.

I then searched the list of 1 - 100 numbers and their factors. Then counting the factor list with only an odd number of factors I came up with my prediction, TEN doors left open.

We will have to finish the kata to see if my answer (10 doors open) is correct.


There is a complete play list over on YouTube TDD.Academy.

You're not required to watch #3 twice... but YouTube thinks its good practice.

Lance pushed the code up to GitHub if you want to look.

100 doors in a row are all initially closed. You make 100 passes by the doors. The first time through, you visit every door and toggle the door (if the door is closed, you open it; if it is open, you close it).

The second time you only visit every 2nd door (door #2, #4, #6, ...).

The third time, every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door.


Question: What state are the doors in after the last pass? Which are open, which are closed?