its not called score
This commit is contained in:
parent
d5b2222586
commit
5572d13047
1 changed files with 9 additions and 9 deletions
18
day3.m
18
day3.m
|
@ -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").
|
||||
|
|
Loading…
Reference in a new issue