From ca7631ff2fdc6d783f1ae8043de95dcd1b6b7d08 Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Mon, 1 Dec 2025 22:52:12 +0100 Subject: feat(file): implement file reader --- 2025/ocaml/lib/infrastructure/file_reader.ml | 4 ++++ 2025/ocaml/lib/infrastructure/file_reader.mli | 3 +++ 2025/ocaml/lib/presentation/cli.ml | 16 ++++------------ 3 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 2025/ocaml/lib/infrastructure/file_reader.ml create mode 100644 2025/ocaml/lib/infrastructure/file_reader.mli (limited to '2025') diff --git a/2025/ocaml/lib/infrastructure/file_reader.ml b/2025/ocaml/lib/infrastructure/file_reader.ml new file mode 100644 index 0000000..7a80c0b --- /dev/null +++ b/2025/ocaml/lib/infrastructure/file_reader.ml @@ -0,0 +1,4 @@ +let read_file filename = + let chan = In_channel.open_text filename in + let content = In_channel.input_all chan in + In_channel.close chan ; content diff --git a/2025/ocaml/lib/infrastructure/file_reader.mli b/2025/ocaml/lib/infrastructure/file_reader.mli new file mode 100644 index 0000000..bb40577 --- /dev/null +++ b/2025/ocaml/lib/infrastructure/file_reader.mli @@ -0,0 +1,3 @@ +val read_file : string -> string +(** [read_file filename] is the contents of [filename] as a string. + The empty string is returned if [filename] does not exist. *) diff --git a/2025/ocaml/lib/presentation/cli.ml b/2025/ocaml/lib/presentation/cli.ml index 6344d07..fba98ae 100644 --- a/2025/ocaml/lib/presentation/cli.ml +++ b/2025/ocaml/lib/presentation/cli.ml @@ -1,17 +1,9 @@ -let day_1_example = {|L68 -L30 -R48 -L5 -R60 -L55 -L1 -L99 -R14 -L82|} - let run_day = function | 1 -> - let answer = Application.Day_1.solve day_1_example () in + let content = + Infrastructure.File_reader.read_file "../_input/day_01.txt" + in + let answer = Application.D01p01.solve content () in Logs.app (fun m -> m "%d" answer) ; 0 | _ -> -- cgit v1.2.3