Skip to content

Commit c53dcb3

Browse files
author
Kendrick Ledet
committed
Convert indentation to spaces.
1 parent fa5de36 commit c53dcb3

1 file changed

Lines changed: 30 additions & 30 deletions

File tree

100_Doors_Problem/Python/kennyledet/100_Doors.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,54 @@
1414
import math
1515

1616
def test_doors(doors):
17-
'''Check that all open door numbers are perfect squares'''
18-
for i, door in enumerate(doors):
19-
door_num = i + 1
20-
if door and math.sqrt(door_num) % 1 > 0: # if door open and door number is not a perfect square
21-
return False
17+
'''Check that all open door numbers are perfect squares'''
18+
for i, door in enumerate(doors):
19+
door_num = i + 1
20+
if door and math.sqrt(door_num) % 1 > 0: # if door open and door number is not a perfect square
21+
return False
2222

23-
return True
23+
return True
2424

2525

2626
def print_doors(doors):
27-
for door_num, door in enumerate(doors):
28-
print "Door #{0}: {1}".format(door_num+1, "Open" if door else "Closed")
27+
for door_num, door in enumerate(doors):
28+
print "Door #{0}: {1}".format(door_num+1, "Open" if door else "Closed")
2929

3030

3131
def pass_doors(doors):
32-
for pass_num in xrange(1, 101): # Make 100 passes
33-
current_door = pass_num-1 # Start current door offset at the current pass number ('-1' to account for lists/arrays starting count at 0)
34-
while current_door <= 99:
35-
doors[current_door] = not doors[current_door] # Open door if close, close if open (negate old value using 'not')
36-
current_door += pass_num # Increment current door number by current pass number
37-
return doors
32+
for pass_num in xrange(1, 101): # Make 100 passes
33+
current_door = pass_num-1 # Start current door offset at the current pass number ('-1' to account for lists/arrays starting count at 0)
34+
while current_door <= 99:
35+
doors[current_door] = not doors[current_door] # Open door if close, close if open (negate old value using 'not')
36+
current_door += pass_num # Increment current door number by current pass number
37+
return doors
3838

3939
pass_doors_optimized = lambda doors: [0 if math.sqrt(door_num+1) % 1 > 0 else 1 for door_num, door in enumerate(doors)]
4040

4141

4242
def main():
43-
# Create list of 100 elements initialized to 0 to represent all doors being closed.
44-
doors = [0 for x in xrange(0, 100)]
43+
# Create list of 100 elements initialized to 0 to represent all doors being closed.
44+
doors = [0 for x in xrange(0, 100)]
4545

46-
# Run algorithm
47-
doors = pass_doors(doors)
46+
# Run algorithm
47+
doors = pass_doors(doors)
4848

49-
# Print final door states
50-
print_doors(doors)
49+
# Print final door states
50+
print_doors(doors)
5151

52-
# Test algorithm
53-
result = test_doors(doors)
54-
print "Algorithm has {0}".format("passed" if result else "failed")
52+
# Test algorithm
53+
result = test_doors(doors)
54+
print "Algorithm has {0}".format("passed" if result else "failed")
5555

56-
# Run optimized algorithm
57-
doors = pass_doors_optimized(doors)
58-
print_doors(doors)
56+
# Run optimized algorithm
57+
doors = pass_doors_optimized(doors)
58+
print_doors(doors)
5959

60-
# Test optimized algorithm
61-
result = test_doors(doors)
62-
print "Optimized algorithm has {0}".format("passed" if result else "failed")
60+
# Test optimized algorithm
61+
result = test_doors(doors)
62+
print "Optimized algorithm has {0}".format("passed" if result else "failed")
6363

6464

6565

6666
if __name__ == "__main__":
67-
main()
67+
main()

0 commit comments

Comments
 (0)