Created
December 10, 2015 19:47
-
-
Save vrotaru/f53e9c64072c5fb8ecaa to your computer and use it in GitHub Desktop.
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
let char_0 = Char.code '0' | |
let split n s = | |
let len_s = String.length s in | |
let res = Array.make n 0 in | |
let rec slide pos = | |
if pos < len_s && s.[pos] <> ' ' then | |
pos + 1 |> slide | |
else pos | |
in | |
let rec to_int i over n = | |
if i < over then | |
let n = n * 10 + Char.code s.[i] - char_0 in | |
to_int (i + 1) over n | |
else | |
n | |
in | |
let rec loop i j = | |
if i < n && j < len_s then | |
let j' = slide j in | |
if s.[j] = '-' then | |
res.(i) <- -1 * to_int (j + 1) j' 0 | |
else | |
res.(i) <- to_int j j' 0; | |
loop (i + 1) (j' + 1) | |
in | |
loop 0 0; | |
res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment