I have such code for creating permutations:
--unique permutation
perm :: [t] -> [[t]]
perm [] = [[]]
perm (x:xs) = [(y:zs) | (y,ys) <- views (x:xs), zs <- perm ys]
--create all possible views
views :: [t] -> [(t,[t])]
views [] = []
views (x:xs) = ((x,xs) : [ (y,(x:ys)) | (y,ys) <- views xs ])
However I want to limit the output to a certain length. For example, it should take a parameter specifying the number of elements in the ouput of the permutation. I want to create k distinct permutations drawn from a list [0..9]. So, for example, if k will be equal to 3, then the output should be something like this:[1,2,3], [9,8,7], [0,6,8] etc..
Right now if i pass [0..9] to the function it will generate a list with permutations of length 10. I am struggling to come up with a solution.
In the end, the function should look like perm k list
Thank you!
It is connected with this question: Verbal Arithmetics in Haskell (SEND + MORE = MONEY)