Created
October 23, 2017 22:29
-
-
Save zinid/1da345fcde47f5e6a799288f66ee3857 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(** Need ocaml >= 4.04 | |
Compile: | |
$ ocamlopt -unsafe -o zinid zinid.ml *) | |
let rec split keys values = | |
match input_line stdin with | |
| exception _ -> | |
(keys, values) | |
| s -> | |
match String.split_on_char ' ' s with | |
| [k; v] -> | |
split (k::keys) ((String.trim v)::values) | |
| _ -> | |
(keys, values) | |
let _ = | |
let keys, values = split [] [] in | |
let keys' = Array.of_list (List.rev keys) in | |
let values' = Array.of_list (List.rev values) in | |
let buf = Buffer.create 10000 in | |
for i = 0 to Array.length keys' - 1 do | |
for j = 0 to Array.length values' - 1 do | |
Buffer.add_string buf keys'.(i); | |
Buffer.add_string buf values'.(j); | |
Buffer.add_char buf '\n'; | |
if ((j mod 1000) = 0) then ( | |
Buffer.output_buffer stdout buf; | |
Buffer.clear buf | |
) | |
done | |
done; | |
Buffer.output_buffer stdout buf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment