d4p1 and d4p2
This commit is contained in:
14
04/part1.pl
Normal file
14
04/part1.pl
Normal 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.
|
Reference in New Issue
Block a user