Most elegant way to generate all permutations?

Given the list of letters [“A”, “B”, “C” …] what would be the most elegant way to generate all possible 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]
10 Likes

Thank you :slight_smile:

1 Like