Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The ` ` N Doors Puzzle is a great challenge to explore various aspects of algorithmic thinkingand Python programming. Imagine you have N doors in

The ``N Doors Puzzle is a great challenge to explore various aspects of algorithmic thinkingand Python programming.
Imagine you have N doors in a row that are all initially closed.
You make N pass by each of these doors
The first time through, visit every door and toggle the door (if the door is closed, open
it; if it is open, close it).
The second time, only visit every 2 nd door (i.e., door #2, #4, #6,...) and toggle it.
The third time, visit every 3 rd door (i.e., door #3, #6, #9,...), etc., until you only visit the
N th door on the N th pass.
Implement your algorithmic thinking using Python programming to determine the state of the
doors after the last pass. That is which doors are open and which are closed after the last pass?
Looking at the N doors puzzle we can make the following observations:
There are doors numbered 1 through N that start closed. You can assume a list of
Boolean variables. Initially, they are all going to be set to False, with false representing a
closed door and true representing an open door.
We will iterate over the range N times, toggling the doors open/closed (represented by
true/false)
Each iteration over the range the gap between toggles increases by a multiple,
incremented by one.
On the last iteration, only the N th door will be toggled
Sample I/O:
Run 1:
Enter the number of Doors (N): 10
i: 1; j:1; step size: 1. Toggling door number 1.
i: 1; j:2; step size: 1. Toggling door number 2.
i: 1; j:3; step size: 1. Toggling door number 3.
i: 1; j:4; step size: 1. Toggling door number 4.
i: 1; j:5; step size: 1. Toggling door number 5.
i: 1; j:6; step size: 1. Toggling door number 6.
i: 1; j:7; step size: 1. Toggling door number 7.
i: 1; j:8; step size: 1. Toggling door number 8.
i: 1; j:9; step size: 1. Toggling door number 9.
i: 1; j:10; step size: 1. Toggling door number 10.
i: 2; j:2; step size: 2. Toggling door number 2.
i: 2; j:4; step size: 2. Toggling door number 4.
i: 2; j:6; step size: 2. Toggling door number 6.
i: 2; j:8; step size: 2. Toggling door number 8.
i: 2; j:10; step size: 2. Toggling door number 10.
i: 3; j:3; step size: 3. Toggling door number 3.
i: 3; j:6; step size: 3. Toggling door number 6.
i: 3; j:9; step size: 3. Toggling door number 9.
i: 4; j:4; step size: 4. Toggling door number 4.
i: 4; j:8; step size: 4. Toggling door number 8.
i: 5; j:5; step size: 5. Toggling door number 5.
i: 5; j:10; step size: 5. Toggling door number 10.
i: 6; j:6; step size: 6. Toggling door number 6.
i: 7; j:7; step size: 7. Toggling door number 7.
i: 8; j:8; step size: 8. Toggling door number 8.
i: 9; j:9; step size: 9. Toggling door number 9.
i: 10; j:10; step size: 10. Toggling door number 10.
Algorithm has finished.
Door number 1 remains open.
Door number 4 remains open.
Door number 9 remains open.
Door number 2 remains closed.
Door number 3 remains closed.
Door number 5 remains closed.
Door number 6 remains closed.
Door number 7 remains closed.
Door number 8 remains closed.
Door number 10 remains closed.
Bonus Part (25 points):
For all the open doors, i, after the last pass i.e., N th pass, return a list where:
doors[i]== "FizzBuzz" if i is divisible by 3 and 5.
doors[i]== "Fizz" if i is divisible by 3.
doors[i]== "Buzz" if i is divisible by 5.
doors[i]== i if none of the above conditions are true.
Run 1: When N =20,
N Doors Puzzle's Fizz Buzz Implementation: [1,4, 'fizz', 16]
Run 2: When N =100,
N Doors Puzzle's Fizz Buzz Implementation: [1,4, 'fizz', 16, 'buzz', 'fizz', 49,64, 'fizz', 'buzz']
Run 3: When N =257,
N Doors Puzzle's Fizz Buzz Implementation: [1,4, 'fizz', 16, 'buzz', 'fizz', 49,64, 'fizz', 'buzz',
121, 'fizz', 169,196, 'fizzbuzz', 25

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions

Question

Discuss the goals of financial management.

Answered: 1 week ago

Question

5. Identify the logical fallacies, deceptive forms of reasoning

Answered: 1 week ago

Question

6. Choose an appropriate organizational strategy for your speech

Answered: 1 week ago