diff options
| author | Alexandre Jesus <adbjesus@gmail.com> | 2025-12-01 11:44:39 +0000 |
|---|---|---|
| committer | Alexandre Jesus <adbjesus@gmail.com> | 2025-12-01 11:44:39 +0000 |
| commit | 735b792bcf2a8cc1fb77c19c42e6362a9abb429f (patch) | |
| tree | 4f141174fbc2468d2e47b3c30ae7d171197270f2 /bin | |
| download | aoc2025-735b792bcf2a8cc1fb77c19c42e6362a9abb429f.tar.gz aoc2025-735b792bcf2a8cc1fb77c19c42e6362a9abb429f.zip | |
Initial commit
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/dune | 8 | ||||
| -rw-r--r-- | bin/main.ml | 43 |
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 |
