Skip to content

Instantly share code, notes, and snippets.

@gsg
Created August 9, 2016 21:36
Show Gist options
  • Save gsg/e319a68a65e96b16b33ca92df3ab5ca6 to your computer and use it in GitHub Desktop.
Save gsg/e319a68a65e96b16b33ca92df3ab5ca6 to your computer and use it in GitHub Desktop.
let partition a p =
let len = Array.length a in
let rec loop l r =
if r = len then l
else if p a.(r) then begin
let tmp = a.(l) in
a.(l) <- a.(r);
a.(r) <- tmp;
loop (l + 1) (r + 1)
end else
loop l (r + 1)
in
loop 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment