From c4a3f44cfd161e6e705d2466951e93c5363362a7 Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Sat, 3 Dec 2022 06:59:06 +0100 Subject: [PATCH] an error message --- day3.m | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/day3.m b/day3.m index bbbcdde..0869df6 100644 --- a/day3.m +++ b/day3.m @@ -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))) :-