Skip to content

Files

Latest commit

8cc94d7 · Jun 3, 2018

History

History
This branch is up to date with kennyledet/Algorithm-Implementations:master.

100_Doors_Problem

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Mar 27, 2017
Mar 27, 2017
May 27, 2014
Mar 27, 2017
Mar 5, 2015
Jan 14, 2015
Jul 22, 2014
Aug 12, 2014
Mar 22, 2014
Mar 27, 2017
Jun 25, 2015
Jun 3, 2018
Jan 3, 2015
Apr 4, 2014
Mar 22, 2014

Puzzle:

There are 100 doors in a long hallway. They are all closed. The first time you walk by each door, you open it. The second time around, you close every second door (since they are all opened). On the third pass you stop at every third door and open it if it’s closed, close it if it’s open. On the fourth pass, you take action on every fourth door. You repeat this pattern for 100 passes.

At the end of 100 passes, what doors are opened and what doors are closed?

Solution:

This soution is focused on high memory optimization on the cost of processing time.

An array of four 32 bit integer is used to store status of 100 doors. Each bit in a integer represents a door. Set bit (1) represents open door and reset bit (0) represents closed door. Bitwise shifting is used to access each bit.