d4p1 and d4p2

This commit is contained in:
2023-12-04 03:16:47 -08:00
parent 92caa0f5c4
commit 26365275e8
6 changed files with 478 additions and 0 deletions

14
04/part1.pl Normal file
View File

@@ -0,0 +1,14 @@
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.