From 7b72f794891bb885d1dc4944be6e97758c4c2a90 Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 2 Dec 2024 18:31:28 +0100 Subject: 2024 day two --- 2024/d01.ml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 2024/d01.ml (limited to '2024/d01.ml') 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));; -- cgit 1.4.1