I am writing a swi-prolog program to solve a sudoku puzzle, the program is working perfectly when using the built-in "all_different" predicate but I was now instructed to actually write my own and not take advantage of the available function. Therefore I am attempting to write my own customized version "alldifferent(L):-" that will achieve the same results.
Code:
alldifferent([A1,B1,C1,D1]),
alldifferent([A2,B2,C2,D2]),
alldifferent([A3,B3,C3,D3]),
alldifferent([A4,B4,C4,D4]),
...
alldifferent([_]). % Base Case
alldifferent(H,T) :- H\=T. % Compare Head and Tail
alldifferent([H|T]) :- alldifferent(H,T), alldifferent(T).
[/oOde]
As you can see I pass in a list of 4 variables and I need to ensure that none of them are the same. I've been trying to implement this for a while now and can't seem to figure it out (I've written my current attempt) - I was wondering if anyone could provide some help. MY current attempt doesn't work (not sure how you can compare the head of a list [H] with the tail [T] and am doubtful about my base-case.
Any hints would be greatly appreciated.
Thanks,