And there was no one (?

Asked 2 years ago, Updated 2 years ago, 34 views

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

2022-09-20 19:28

1 Answers

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']


2022-09-20 19:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.