aoc2022/aoc.m

48 lines
1.2 KiB
Mathematica
Raw Normal View History

2022-12-01 02:56:19 -05:00
:- 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.
2022-12-01 17:59:19 -05:00
:- import_module univ.
2022-12-01 02:56:19 -05:00
main(!IO) :- wrap_main(main2, !IO).
2022-12-01 17:59:19 -05:00
:- pred main2(io::di, io::uo) is cc_multi.
2022-12-01 02:56:19 -05:00
main2(!IO) :-
command_line_arguments(Args, !IO),
2022-12-01 17:59:19 -05:00
(if Args = [DayS, PartS, File],
2022-12-01 13:23:53 -05:00
to_int(DayS, Day),
2022-12-01 17:59:19 -05:00
part(PartS, Part) then (
read_lines_need(File, Lines, !IO),
run_day(Day, Part, Lines, Out),
write_line(univ_value(Out), !IO)
) else
die("expected day, part, filename")).
2022-12-01 02:56:19 -05:00
2022-12-01 17:59:19 -05:00
:- type sol == (pred(part, list(string), univ)).
:- inst sol == (pred(in, in, out) is cc_multi).
2022-12-01 02:56:19 -05:00
2022-12-01 13:23:53 -05:00
:- pred solution(int::in, sol::out(sol)) is semidet.
2022-12-01 04:46:26 -05:00
:- import_module day1.
solution(1, day1.run).
2022-12-02 01:19:46 -05:00
:- import_module day2.
solution(2, day2.run).
2022-12-03 00:33:45 -05:00
:- import_module day3.
solution(3, day3.run).
2022-12-04 00:45:57 -05:00
:- import_module day4.
solution(4, day4.run).
2022-12-01 02:56:19 -05:00
2022-12-01 17:59:19 -05:00
:- pred run_day(int, part, list(string), univ).
:- mode run_day(in, in, in, out) is cc_multi.
run_day(Day, Part, Lines, Out) :-
2022-12-01 02:56:19 -05:00
if solution(Day, P) then
2022-12-01 17:59:19 -05:00
P(Part, Lines, Out)
2022-12-01 02:56:19 -05:00
else
die("no solution for day %d", [i(Day)]).