Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #Problem: You have 100 doors in a row that are all initially closed. You make 100 passes by the doors.
  2. #The first time through, you visit every door and toggle the door (if the door is closed, you open it; if it is open,
  3. #you close it). The second time you only visit every 2nd door (door #2, #4, #6, ...). The third time, every 3rd door
  4. #(door #3, #6, #9, ...), etc, until you only visit the 100th door.
  5.  
  6. #Question: What state are the doors in after the last pass? Which are open, which are closed?
  7.  
  8.  
  9. doors = 100 * [False]
  10.  
  11. for i in range(0,99):
  12. for y in range(i, 99, i+1):
  13. doors[y] = not doors[y]
  14. if doors[y] is False:
  15. print("Closed")
  16. else:
  17. print("Open")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement