summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/dune8
-rw-r--r--bin/main.ml43
2 files changed, 51 insertions, 0 deletions
diff --git a/bin/dune b/bin/dune
new file mode 100644
index 0000000..73686e6
--- /dev/null
+++ b/bin/dune
@@ -0,0 +1,8 @@
+; SPDX-FileCopyrightText: Copyright 2025 Alexandre Jesus <https://adbjesus.com>
+;
+; SPDX-License-Identifier: CC0-1.0
+
+(executable
+ (public_name aoc2025)
+ (name main)
+ (libraries aoc2025))
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 <https://adbjesus.com>
+ *
+ * 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 <day> <part> <inputfile>" 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: <day> <part> <inputfile>"
+ 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