Question: Need help with this coding question in Python Language 100 doors in a row are all initially closed. You make 100 passes by the doors.

Need help with this coding question in Python Language

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?

[Source http://rosettacode.org]

## Pass 1 through 100 doors

Assumption:

First pass all doors are closed

if I visit each door it will be toggled open

## Pass 2 through 100 doors

every other door is closed

So, 50 open 50 closed

## Pass 3

50 doors are still closed and 50 still open

visiting every third door and toggling it closed/open

since only visiting every third door we could collect that indice, toggle it and update the those

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!