diff options
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));; |