first
This commit is contained in:
commit
ea6fb40895
4 changed files with 88 additions and 0 deletions
42
aoc.m
Normal file
42
aoc.m
Normal file
|
@ -0,0 +1,42 @@
|
|||
:- module aoc.
|
||||
:- interface.
|
||||
:- import_module io.
|
||||
|
||||
:- pred main(io::di, io::uo) is cc_multi.
|
||||
|
||||
:- implementation.
|
||||
:- import_module basics.
|
||||
:- import_module die.
|
||||
:- import_module string.
|
||||
:- import_module list.
|
||||
:- import_module exception.
|
||||
|
||||
main(!IO) :- wrap_main(main2, !IO).
|
||||
|
||||
:- pred main2(io::di, io::uo) is cc_multi.
|
||||
:- pragma no_determinism_warning(main2/2).
|
||||
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 solution == (pred(part, list(string), io, io)).
|
||||
:- inst solution == (pred(in, in, di, uo) is det).
|
||||
|
||||
:- pred solution(int::in, solution::out(solution)) is semidet.
|
||||
solution(_, _) :- fail.
|
||||
|
||||
:- 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)]).
|
Loading…
Add table
Add a link
Reference in a new issue