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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started