i love grammars so much u guys
This commit is contained in:
parent
6eb6f4bd15
commit
b1bc7ef4b6
1 changed files with 6 additions and 3 deletions
9
day3.m
9
day3.m
|
@ -35,8 +35,11 @@ prio(C) = I :-
|
||||||
:- type triple(T) ---> t(T, T, T).
|
:- type triple(T) ---> t(T, T, T).
|
||||||
|
|
||||||
:- pred threes(list(T)::in, list(triple(T))::out) is semidet.
|
:- pred threes(list(T)::in, list(triple(T))::out) is semidet.
|
||||||
threes([], []).
|
threes(In, Out) :- threes(Out, In, []).
|
||||||
threes([X, Y, Z | Rest], [t(X, Y, Z) | Groups]) :- threes(Rest, Groups).
|
|
||||||
|
:- 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.
|
:- pred go1(string::in, int::out) is cc_multi.
|
||||||
|
@ -63,4 +66,4 @@ run(two, Lines, univ(sum(Prios))) :-
|
||||||
if threes(Lines, Groups) then
|
if threes(Lines, Groups) then
|
||||||
map(go2, Groups, Prios)
|
map(go2, Groups, Prios)
|
||||||
else
|
else
|
||||||
die("not a multiple of three lines").
|
die("%d lines given (not a multiple of 3)", [i(length(Lines))]).
|
||||||
|
|
Loading…
Reference in a new issue