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
(* 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 |
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
(* 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 |
NewerOlder