Question: Write a function (in standar ml) permu: int -> int list list to generate the permutation of the identity list from 1 to n. permu(2)=>[[1,2],[2,1]].
Write a function (in standar ml) permu: int -> int list list to generate the permutation of the identity list from 1 to n. permu(2)=>[[1,2],[2,1]]. permu(3)=>[[1,2,3],[2,1,3],[2,3,1],[1,3,2],[3,1,2],[3,2,1]]
The key is to implement a function interleave: (int * int list) -> int list list which takes an integer and a list of integers and returns a list containing the set of lists resulting from the insertion of the integer in all possible positions of the original list. For example,
interleave(4,[1,2,3])=[4,1,2,3],[1,4,2,3],[1,2,4,3],[1,2,3,4]]
You have to use higher order function approach to implement interleave function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
