its not called score

This commit is contained in:
rhiannon morris 2022-12-03 06:55:52 +01:00
parent d5b2222586
commit 5572d13047

18
day3.m
View file

@ -20,8 +20,8 @@ split(X, L, H) :-
:- pred common(list(chars)::in, char::out) is nondet.
common([S | Ss], C) :- member(C, S), (Ss = [] ; common(Ss, C)).
:- func score(char) = int.
score(C) = I :-
:- func prio(char) = int.
prio(C) = I :-
if is_lower(C) then
I = to_int(C) - to_int('a') + 1
else
@ -37,23 +37,23 @@ go1(Line, Out) :-
if split(to_char_list(Line), Fst, Snd),
common([Fst, Snd], C)
then
Out = score(C)
Out = prio(C)
else
die("invalid line: ""%s""", [s(Line)]).
:- pred go2(list(string)::in, int::out) is cc_multi.
go2(Lines, Score) :-
go2(Lines, Prio) :-
if common(map(to_char_list, Lines), C) then
Score = score(C)
Prio = prio(C)
else
die("no item in common").
run(one, Lines, univ(sum(Scores))) :-
map(go1, Lines, Scores).
run(two, Lines, univ(sum(Scores))) :-
run(one, Lines, univ(sum(Prios))) :-
map(go1, Lines, Prios).
run(two, Lines, univ(sum(Prios))) :-
if threes(Lines, Groups) then
map(go2, Groups, Scores)
map(go2, Groups, Prios)
else
die("not a multiple of three lines").