From bf692a17dbfe749f11eea3cac8b6f79f4f40d94e Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Tue, 10 Jan 2023 17:23:37 +0100 Subject: [PATCH] Day 1 OCaml --- .gitignore | 1 + ocaml/1.ml | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .gitignore create mode 100644 ocaml/1.ml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..15d7aef --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +inputs diff --git a/ocaml/1.ml b/ocaml/1.ml new file mode 100644 index 0000000..4753bc3 --- /dev/null +++ b/ocaml/1.ml @@ -0,0 +1,20 @@ +#load "str.cma" ;; + +let read_file filename = + let ch = open_in filename in + let s = really_input_string ch (in_channel_length ch) in + close_in ch; + s + ;; + +let contents = read_file "inputs/1.txt" ;; +(* print_endline contents ;; *) + +let maxcal = Str.split (Str.regexp "\n\n") contents + |> List.map (String.split_on_char '\n') + |> List.map (List.map (int_of_string)) + |> List.map (List.fold_left (+) 0) + |> List.fold_left (max) 0 + ;; + +Printf.printf "%d" maxcal