30 The individual is in a boat , overload , need 15 People get off the ship . So people lined up , The queue is their number .
Number off , from 1 Start , Count to 9 People get off the ship . So circular , Until there's only 15 So far , Ask what number of people got off the ship ?
resolvent :
python Code :
remove_sum=15
remove_num=9
remove_list=[] # Put the number to be moved out in the list
list_peple=list(range(1,31))# establish 1-30 Number
r_sum=0 # Number of people moved out
while r_sum<remove_sum:
r_num=1 # Who are the first people to visit
while r_num<remove_num:
first=list_peple.pop(0) # Delete the first element of the list and return the deleted element
list_peple.append(first) # Put the deleted element at the end of the list
r_num=r_num+1
first=list_peple.pop(0)
remove_list.append(first)# The first 9 individual , Put the deleted element in remove_list At the end of the list
r_sum+=1
result :
list_peple
[25, 28, 29, 1, 2, 3, 4, 10, 11, 13, 14, 15, 17, 20, 21]
remove_list
[9, 18, 27, 6, 16, 26, 7, 19, 30, 12, 24, 8, 22, 5, 23]