basic algorithm in ocaml