aoc23/04/part1.pl

15 lines
422 B
Perl
Raw Normal View History

2023-12-04 05:16:47 -06:00
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.