I coded a function to enumerate all permutations of a given list. What do you think of the code below?
def interleave(x:Int, l:List[Int]):List[List[Int]] = {
Consider the difference here: your version
scala> permutations(List(1,1,2)) foreach println List(1, 1, 2) List(1, 1, 2) List(1, 2, 1) List(1, 2, 1) List(2, 1, 1) List(2, 1, 1)
The reference version:
scala> List(1,1,2).permutations foreach println List(1, 1, 2) List(1, 2, 1) List(2, 1, 1)