Skip to content

Instantly share code, notes, and snippets.

@reterVision
Last active December 12, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reterVision/4716071 to your computer and use it in GitHub Desktop.
Save reterVision/4716071 to your computer and use it in GitHub Desktop.
All permulation algorithm written in Python.
"""
Permulation algorithm implemented in Python.
"""
array = range(1, 4)
def perm(array, lower, upper):
if lower >= upper:
print array
else:
for elem in array[lower:]:
i = array.index(elem)
array[i], array[lower] = array[lower], array[i]
perm(array, lower + 1, upper)
array[i], array[lower] = array[lower], array[i]
if __name__ == "__main__":
perm(array, 0, len(array))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment