Skip to content

Instantly share code, notes, and snippets.

@lotka
Last active November 28, 2015 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotka/d39b0da96ede6ca3565c to your computer and use it in GitHub Desktop.
Save lotka/d39b0da96ede6ca3565c to your computer and use it in GitHub Desktop.
life(good).
life(bad).
life(okay).
setOfLifeOutcomes(X) :-
lengthAcc(X,0).
getAcc([],_,_).
getAcc([H|T],Acc,N) :-
Acc > N -> ! ;
(NewAcc is Acc+1,
getAcc(T,NewAcc,N),
life(H),
\+member(H,T)).
getHelper(List,Length) :-
getAcc(List,0,Length),
length(List,Length), !.
lengthAcc(List,I) :-
NewI is I+1,
getHelper(_,NewI) -> lengthAcc(List,NewI) ; getHelper(List,I).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment