0

I'm having issues connecting the following three rules together.

countingCombo([H|T], Sequence2) :-
   fact1(H, Sequence),
   append(Sequence, Sequence2, Sequence3),
   countingCombo(T, Sequence3).
countingCombo([], Combination) :-
   print(Combination),
   membersofCombo(Combination, X, C).

membersofCombo(List, X, C) :-
   sort(List, List1),
   member(X, List1),
   count(List, X, C).

count([], X, 0).
count([X|T], X, Y) :-
   count(T, X, Z),
   Y is 1+Z.
count([X1|T], X, Z) :-
   X1 \= X,
   count(T, X, Z).

countingcombo creates an appended list. membersofcombo, sorts that list and then produces each member of the original appended list, count rule then counts the occurences of each memeber.

membersofcombo and count work together, but I can't get countingcombo to connect to members of combo.

FProlog
  • 173
  • 1
  • 1
  • 9

1 Answers1

2

There are a number of issues with your code:

  • Are you aware that combination is not a variable (standing for some list)?

    rule1([], combination) :-
       print(combination),
       rule2(combination, X, C).
    
  • Choose better predicate names: rule1, rule2, and rule3 don't tell me nothing...

  • Use in the implementation of count/3!

  • Eliminate the singleton variable X in clause count([], X, 0).
    Quite likely, you meant to write count([], _, 0).

  • Provide an implementation of count/3. Is it rule3/3?

repeat
  • 18,496
  • 4
  • 54
  • 166
  • 1
    Yes, typo. Meant to be Combination with a capital. The code still doesn't work however. Editted the question. – FProlog Jan 15 '16 at 12:57