vikasupendra
Programmer
Hi guys,
I am writing prolog code to find duplicates of an element in the same row and column. How do I do this?
For ex, if my input grid is like
grid(1,1,1).
grid(2,1,2).
grid(2,1,3).
grid(3,2,1).
grid(4,2,2).
grid(5,2,3).
grid(6,3,1).
grid(7,3,2).
grid(2,3,3).
which represents the grid
1 2 2
3 4 5
6 7 2
I need to find if there duplicates for a number in the same row and column. How do I do this in Prolog?
I was trying something like
finddup(N,X,Y):-
a is X, b is Y,
print('Rule 1 \n'),
finddup(N,X-1,b),
finddup(N,X+1,b),
finddup(N,a,Y-1),
finddup(N,a,Y+1).
finddup(N,_,1):-
print('Rule 2\n'),
grid(N,_,1).
finddup(N,1,_):-
print('Rule 3\n'),
grid(N,1,_).
finddup(N,_,3):-
print('Rule 4\n'),
grid(N,_,3).
finddup(N,3,_):-
print('Rule 5\n')
grid(N,3,_).
Please help me out with the code to check duplicate elements in the same row and colum.
I am writing prolog code to find duplicates of an element in the same row and column. How do I do this?
For ex, if my input grid is like
grid(1,1,1).
grid(2,1,2).
grid(2,1,3).
grid(3,2,1).
grid(4,2,2).
grid(5,2,3).
grid(6,3,1).
grid(7,3,2).
grid(2,3,3).
which represents the grid
1 2 2
3 4 5
6 7 2
I need to find if there duplicates for a number in the same row and column. How do I do this in Prolog?
I was trying something like
finddup(N,X,Y):-
a is X, b is Y,
print('Rule 1 \n'),
finddup(N,X-1,b),
finddup(N,X+1,b),
finddup(N,a,Y-1),
finddup(N,a,Y+1).
finddup(N,_,1):-
print('Rule 2\n'),
grid(N,_,1).
finddup(N,1,_):-
print('Rule 3\n'),
grid(N,1,_).
finddup(N,_,3):-
print('Rule 4\n'),
grid(N,_,3).
finddup(N,3,_):-
print('Rule 5\n')
grid(N,3,_).
Please help me out with the code to check duplicate elements in the same row and colum.