From 735b792bcf2a8cc1fb77c19c42e6362a9abb429f Mon Sep 17 00:00:00 2001 From: Alexandre Jesus Date: Mon, 1 Dec 2025 11:44:39 +0000 Subject: Initial commit --- bin/main.ml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 bin/main.ml (limited to 'bin/main.ml') diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..2cddf84 --- /dev/null +++ b/bin/main.ml @@ -0,0 +1,43 @@ +(* + * SPDX-FileCopyrightText: Copyright 2025 Alexandre Jesus + * + * SPDX-License-Identifier: GPL-3.0-or-later + *) + +open Aoc2025 + +let parse_day s = + match int_of_string_opt s with + | Some n when n >= 1 && n <= 12 -> n + | _ -> failwith (Format.sprintf "Day '%s' is invalid, expected an integer between 1 and 12" s) + +let parse_part s = + match int_of_string_opt s with + | Some n when n >= 1 && n <= 2 -> n + | _ -> failwith (Format.sprintf "Part '%s' is invalid, expected an integer between 1 and 2" s) + +let day_part_fn day part = + let day = parse_day day in + let part = parse_part part in + match (day, part) with + | (1, 1) -> Day01.part1 + | (1, 2) -> Day01.part2 + | _ -> failwith (Format.sprintf "Day %d, part %d, has not yet been implemented\n" day part) + +let () = + let usage_msg = "aoc2025 " in + let args = ref [] in + let anon_fun arg = args := arg :: !args in + let speclist = [] in + Arg.parse speclist anon_fun usage_msg; + let args = Array.of_list !args in + if Array.length args != 3 then + failwith "Wrong number of arguments, expected 3: " + else + let fn = day_part_fn args.(2) args.(1) in + let ic = open_in args.(0) in + try + fn ic + with e -> + close_in_noerr ic; + raise e -- cgit v1.2.3