Skip to content

Instantly share code, notes, and snippets.

@thran
Created December 5, 2016 15:55
Show Gist options
  • Select an option

  • Save thran/eedd6cb8c9066e53eb54282a602049ef to your computer and use it in GitHub Desktop.

Select an option

Save thran/eedd6cb8c9066e53eb54282a602049ef to your computer and use it in GitHub Desktop.
n = 100
def run(losi, i, j):
l = losi[i]
losi.remove(l)
return losi[:j] + [l] + losi[j:]
losi = range(1, n + 1)
last = None
x = 0
while last != losi:
print(losi[::-1])
x += 1
runs = []
for l in losi:
i = losi.index(l)
for l2 in losi[:i][::-1]:
if l % l2 == 0:
runs.append((l, l2))
break
last = losi
for l, l2 in runs:
losi = run(losi, losi.index(l), losi.index(l2))
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment