def get_pukes(num):
result = [num]
for k in range(num - 1, 0, -1):
for _ in range(k):
result = reverse(result)
result.insert(0, k)
return result
def reverse(pukes):
last = pukes[-1]
del pukes[-1]
pukes.insert(0, last)
return pukes
if __name__ == '__main__':
print(get_pukes(20))
D:\Anaconda\python.exe D:/AI20/06_codes/deeplearning_20/p23_puke.py
[1, 6, 2, 8, 16, 3, 17, 19, 14, 4, 13, 7, 20, 10, 5, 11, 9, 18, 15, 12]
Process finished with exit code 0