diff options
author | Emile <git@emile.space> | 2024-12-02 18:31:28 +0100 |
---|---|---|
committer | Emile <git@emile.space> | 2024-12-02 18:31:28 +0100 |
commit | 7b72f794891bb885d1dc4944be6e97758c4c2a90 (patch) | |
tree | 0e60ea8737ff6b6cc699f1a366785da02a557b67 /2024/d01.ml | |
parent | 3577bb20ef3a3e1af25f1419a3e4a88d336866a0 (diff) |
2024 day two
Diffstat (limited to '2024/d01.ml')
-rw-r--r-- | 2024/d01.ml | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/2024/d01.ml b/2024/d01.ml new file mode 100644 index 0000000..310f6ac --- /dev/null +++ b/2024/d01.ml @@ -0,0 +1,20 @@ +let () = print_endline "hello" + +let read_file_into_lists filename = + let in_channel = open_in filename in + let rec read_lines left right = + try + let line = input_line in_channel in + match String.split_on_char '\t' line with + | [l; r] -> + read_lines (int_of_string l :: left) (int_of_string r :: right) + | _ -> failwith "invalid line format" + with End_of_file -> + close_in in_channel; + (List.rev left, List.rev right) + in read_lines [] [] + +let () = + let left_nums, right_nums = read_file_into_lists "d01.input" in + Print.printf "Left numbers: %s\n" (String.concat " " (List.map string_of_int left_nums)); + Print.printf "Right numbers: %s\n" (String.concat " " (List.map string_of_int right_nums));; |