aoc2022/aoc.m
2022-12-01 19:23:53 +01:00

40 lines
1,016 B
Mathematica

:- module aoc.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
:- import_module basics.
:- import_module string.
:- import_module list.
:- import_module exception.
main(!IO) :- wrap_main(main2, !IO).
:- pred main2(io::di, io::uo) is det.
main2(!IO) :-
command_line_arguments(Args, !IO),
(if Args = [DayS, PartS | Rest],
to_int(DayS, Day),
part(PartS, Part) then
run(Day, Part, Rest, !IO)
else if Args = [D, P | _] then
die("expected a day and a part, got ""%s"" ""%s""", [s(D), s(P)])
else
die("expected at least two args")).
:- type sol == (pred(part, list(string), io, io)).
:- inst sol == (pred(in, in, di, uo) is det).
:- pred solution(int::in, sol::out(sol)) is semidet.
:- import_module day1.
solution(1, day1.run).
:- pred run(int::in, part::in, list(string)::in, io::di, io::uo) is det.
run(Day, Part, Args, !IO) :-
if solution(Day, P) then
P(Part, Args, !IO)
else
die("no solution for day %d", [i(Day)]).