Solved 10th problem using OCaml