Most elegant way to generate all permutations?

Well from old erlang code translated to Elixir, the all-generic:

def permutations([]), do: [[]]
def permutations(list), do: for elem <- list, rest <- permutations(list--[elem]), do: [elem|rest]
15 Likes