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