aoc23/04/part1.pl
2023-12-04 03:16:47 -08:00

15 lines
422 B
Prolog

score(_, [], 0).
score(Wins, [X|Nums], N) :- member(X, Wins), score(Wins, Nums, N1), N is N1 + 1.
score(Wins, [X|Nums], N) :- \+ member(X, Wins), score(Wins, Nums, N).
exponent(N, 0) :- N =< 0.
exponent(N, M) :- N > 0, M is 2**(N-1).
all_scores([], 0).
all_scores([[Wins1|Card1]|RestOfCards], N) :-
score(Wins1, Card1, N1),
all_scores(RestOfCards, RestOfScore),
exponent(N1, N2),
N is N2 + RestOfScore.