Solved 8th problem using OCaml