I have a prolog predicate:
Add( [A|B] , Answer ) :-
...
~ Add everything in the list to come up with answer
...
I would now like to implement AddUnique that would return unique values for everything in the list except when I give it the variable twice.
Here are somethings that are logically equivalent:
?- AddUnique([A, B, C], 10). is equivalent to: ?- Add([A, B, C], 10), A != B, B != C, A != C.
And:
?- AddUnique([A, B, B], 10). is equivalent to: ?- Add([A, B, B], 10), A != B.
Also:
?- AddUnique([A, B, B], 10). is NOT equivalent to: ?- Add([A, B, B], 10), A != B, B!=B.
If ?- AddUnique([A,B,C,D], 4). is given it should return false since it cannot come with unique positive integers that add to four.
If ?- AddUnique([A,A,A,A], 4). is given it should return A=1.
Question: How can I move the A != B, B != C, A != C. logic inside the predicate without doing something like this A != A?
This is the solution that I came up with. It will only assign the input to be numbers less than ten but works great for that!