Skip to content

Instantly share code, notes, and snippets.

Jackson Tale MassD

Block or report user

Report or block MassD

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@MassD
MassD / permutations_ins_into_all_positions.ml
Last active Aug 29, 2015
A implementation for generating all permutations of a list, written in OCaml
View permutations_ins_into_all_positions.ml
(* note that in order to preserve certain order
and also show the conciseness of the implementation,
no tail-recursive is used *)
let ins_all_positions x l =
let rec aux prev acc = function
| [] -> (prev @ [x]) :: acc |> List.rev
| hd::tl as l -> aux (prev @ [hd]) ((prev @ [x] @ l) :: acc) tl
in
aux [] [] l
You can’t perform that action at this time.