-
-
Save MassD/22950955c5efa8f8af88 to your computer and use it in GitHub Desktop.
A implementation for generating permutations using fixed-head approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rm x l = List.filter ((<>) x) l | |
let rec permutations = function | |
| [] -> [] | |
| x::[] -> [[x]] | |
| l -> | |
List.fold_left (fun acc x -> acc @ List.map (fun p -> x::p) (permutations (rm x l))) [] l | |
(* The List.fold_left makes every element have their oppotunities to be a head *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment