Skip to content

Instantly share code, notes, and snippets.

@aomoriringo
Last active August 29, 2015 14:06
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 aomoriringo/3cc10f542588e0991a51 to your computer and use it in GitHub Desktop.
Save aomoriringo/3cc10f542588e0991a51 to your computer and use it in GitHub Desktop.
function! Permutations(list)
let len = len(a:list)
if len == 0
return [[]]
elseif len == 1
return [a:list]
endif
let list = []
for perm in Permutations(a:list[1:])
let list = s:push(list, [a:list[0]] + perm)
for i in range(len - 1)
let list = s:push(list, perm[:i] + [a:list[0]] + perm[(i + 1):])
endfor
endfor
return list
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment