Skip to content

Instantly share code, notes, and snippets.

@vrotaru
Created June 20, 2014 17:07
Show Gist options
  • Save vrotaru/99f0d4a85b4dd84b245b to your computer and use it in GitHub Desktop.
Save vrotaru/99f0d4a85b4dd84b245b to your computer and use it in GitHub Desktop.
let split s n =
let arr = Array.make n 0 in
let rec loop j i =
if i < String.length s && j < n then
let c = s.[i] in
if c == ' ' then
loop (j + 1) (i + 1)
else
let () = arr.(j) <-
arr.(j) * 10 + (int_of_char c - int_of_char '0')
in
loop j (i + 1)
else
arr
in
loop 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment