i love grammars so much u guys

This commit is contained in:
rhiannon morris 2022-12-03 11:38:14 +01:00
parent 6eb6f4bd15
commit b1bc7ef4b6

9
day3.m
View file

@ -35,8 +35,11 @@ prio(C) = I :-
:- type triple(T) ---> t(T, T, T).
:- pred threes(list(T)::in, list(triple(T))::out) is semidet.
threes([], []).
threes([X, Y, Z | Rest], [t(X, Y, Z) | Groups]) :- threes(Rest, Groups).
threes(In, Out) :- threes(Out, In, []).
:- pred threes(list(triple(T))::out, list(T)::in, list(T)::out) is semidet.
threes([]) --> =([]).
threes([t(X, Y, Z) | Rest]) --> [X, Y, Z], threes(Rest).
:- pred go1(string::in, int::out) is cc_multi.
@ -63,4 +66,4 @@ run(two, Lines, univ(sum(Prios))) :-
if threes(Lines, Groups) then
map(go2, Groups, Prios)
else
die("not a multiple of three lines").
die("%d lines given (not a multiple of 3)", [i(length(Lines))]).