Skip to content

Instantly share code, notes, and snippets.

@abarax
Created May 6, 2013 07:03
Show Gist options
  • Save abarax/5523738 to your computer and use it in GitHub Desktop.
Save abarax/5523738 to your computer and use it in GitHub Desktop.
def perms(arr):
if len(arr) == 1:
return [arr]
ret = []
head = arr[:1]
for tail in perms(arr[1:]):
for i in range(len(arr)):
ret.append(tail[i:] + head + tail[:i])
return ret
print perms([1,2,3,4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment