File size: 588 Bytes
497f2f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace ConsoleApplication1
{
    using System;
    class Program
    {
        static void Main()
        {
            bool[] doors = new bool[100];

            //The number of passes can be 1-based, but the number of doors must be 0-based.
            for (int p = 1; p <= 100; p++)
                for (int d = p - 1; d < 100; d += p)
                    doors[d] = !doors[d];
            for (int d = 0; d < 100; d++)
                Console.WriteLine("Door #{0}: {1}", d + 1, doors[d] ? "Open" : "Closed");
            Console.ReadKey(true);
        }
    }
}