×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Find duplicates in a row and column

Find duplicates in a row and column

Find duplicates in a row and column

(OP)
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.

RE: Find duplicates in a row and column

You can do that for a line, works with SWI-Prolog

CODE

find_dup_in_line :-
    forall(between(1,3,I),
           (   setof(V, L^grid(V, I, L), LV),
           (   length(LV, 3) -> true; format('Dups exist in line ~w~n', [I])))).

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close