an error message

This commit is contained in:
rhiannon morris 2022-12-03 06:59:06 +01:00
parent 5572d13047
commit c4a3f44cfd
1 changed files with 10 additions and 6 deletions

16
day3.m
View File

@ -27,9 +27,12 @@ prio(C) = I :-
else
I = to_int(C) - to_int('A') + 27.
:- pred threes(list(T)::in, list(list(T))::out) is semidet.
:- type triple(T) ---> t(T, T, T).
:- pred threes(list(T)::in, list(triple(T))::out) is semidet.
threes([], []).
threes([X, Y, Z | Rest], [[X, Y, Z] | Groups]) :- threes(Rest, Groups).
threes([X, Y, Z | Rest], [t(X, Y, Z) | Groups]) :- threes(Rest, Groups).
:- pred go1(string::in, int::out) is cc_multi.
@ -42,12 +45,13 @@ go1(Line, Out) :-
die("invalid line: ""%s""", [s(Line)]).
:- pred go2(list(string)::in, int::out) is cc_multi.
go2(Lines, Prio) :-
if common(map(to_char_list, Lines), C) then
:- pred go2(triple(string)::in, int::out) is cc_multi.
go2(t(X, Y, Z), Prio) :-
if common(map(to_char_list, [X, Y, Z]), C) then
Prio = prio(C)
else
die("no item in common").
die("no item in common in:\n - %s\n - %s\n - %s",
[s(X), s(Y), s(Z)]).
run(one, Lines, univ(sum(Prios))) :-