diff --git a/day3.m b/day3.m index c8eea59..77cd651 100644 --- a/day3.m +++ b/day3.m @@ -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))]).