Skip to content

Instantly share code, notes, and snippets.

@greyson
Forked from baali/permute_list.erl
Created April 10, 2012 08:34
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 greyson/2349382 to your computer and use it in GitHub Desktop.
Save greyson/2349382 to your computer and use it in GitHub Desktop.
Permutation of List in Erlang
-module( permute_list ).
-export([ permute/1 ]).
permute( List ) ->
jumble( List, [] ).
jumble( [], Permuted_List ) ->
Permuted_List;
jumble( List, Permuted_List ) ->
Index = random:uniform( length(List) ) -1,
{Left, [Element | Right]} = lists:split( Index, List ),
jumble( lists:append( Left, Right ), [Element | Permuted_List] ).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment