Have you seen any code that you think came from "The Book"?

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!

5 Likes