Skip to content

Instantly share code, notes, and snippets.

View cmcbride's full-sized avatar

Cameron McBride cmcbride

  • Boston, MA (USA)
View GitHub Profile
(* compute GCD. playing with OCaml *)
let rec gcd n m =
if m = 0 then
n
else
if n > m
then
gcd (n-m) m
else
(* for use with Array. Easy way to create an index, and then sort the index *)
let index a = Array.init ( Array.length a) (fun i -> i)
let sort_index a idx =
let cmpi i j = compare a.(i) a.(j) in
Array.fast_sort cmpi idx