1) Output: Before alignment
[A, B, C, D, E, F, G, H, I, J]
[C, D, E, F, G, H, I, J, A]
[E, F, G, H, I, J, A, C]
[G, H, I, J, A, C, E]
[I, J, A, C, E, G]
[A, C, E, G, I]
[E, G, I, A]
[I, A, E]
[E, I]
[E] #<- The culprit!
2) Output: After alignment
[A, B, C, D, E, F, G, H, I, J]
[A, C, D, E, F, G, H, I, J]
[A, C, E, F, G, H, I, J]
[A, C, E, G, H, I, J]
[A, C, E, G, I, J]
[A, C, E, G, I]
[A, E, G, I]
[A, E, I]
[E, I]
[E] #<- The culprit!
Code written in #python3
people = ["A","B","C","D","E","F","G","H","I","J"]
def do(list):
list.append(list.pop(0)) #Turn the first person over to the last
list.pop(0) #killing one person
showing = []
while not len(people) == 1:
do(people)
showing = people.copy() # Copy to show
showing.sort() #aligning
print(showing)
# The result
['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
['A', 'C', 'E', 'F', 'G', 'H', 'I', 'J']
['A', 'C', 'E', 'G', 'H', 'I', 'J']
['A', 'C', 'E', 'G', 'I', 'J']
['A', 'C', 'E', 'G', 'I']
['A', 'E', 'G', 'I']
['A', 'E', 'I']
['E', 'I']
['E']
© 2024 OneMinuteCode. All rights reserved.