I’ll nominate the following way to generate all permutations:
def permutations([]), do: [[]]
def permutations(list), do: for x <- list, rest <- permutations(list -- [x]), do: [x | rest]
I expected it to be so much more complicated than it was!
I’ll nominate the following way to generate all permutations:
def permutations([]), do: [[]]
def permutations(list), do: for x <- list, rest <- permutations(list -- [x]), do: [x | rest]
I expected it to be so much more complicated than it was!