Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3349506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:40:22+00:00 2026-05-18T01:40:22+00:00

This is for GNU-Prolog I’m having trouble getting a certain predicate to work. Its

  • 0

This is for GNU-Prolog

I’m having trouble getting a certain predicate to work. Its functionality is that it matches a list of integers
that have a domain of 1 to N with no duplicates and length N. Basically what I want to do is have this as inputs and outputs:

| ?- row_valid(X, 3).

X = [1, 2, 3] ? ;
X = [1, 3, 2] ? ;
X = [2, 1, 3] ? ;
X = [2, 3, 1] ? ;
X = [3, 1, 2] ? ;
X = [3, 2, 1] ? ;

no

| ?- row_valid(X, 2).

X = [1, 2] ? ;
X = [2, 1] ? ;

no

| ?- row_valid(X, 1).

X = [1] ? ;

no

But right now, this is what is happening:

| ?- row_valid(X, 3).

X = [] ? ;

no

This is probably happening because of the row_valid([], _). predicate I have in the code. However, I can verify that the predicate matches correctly since:

| ?- row_valid([1,2,3], 3).

true ?

yes

Here are the predicates defined. Do you have any suggestions on how I could get this to work the way I want? Thanks for your time.

% row_valid/2: matches if list of integers has domain of 1 to N and is not duplicated
% 1 - list of integers
% 2 - N
row_valid([], _).
row_valid(Row, N) :-
    length(Row, N),                % length
    no_duplicates_within_domain(Row, 1, N),
    row_valid(RestRow, N).

% no_duplicates/1: matches if list doesn't have repeat elements
% 1 - list
no_duplicates([]).        % for empty list always true
no_duplicates([Element | RestElements]) :-
    \+ member(Element, RestElements),        % this element cannot be repeated in the list
    no_duplicates(RestElements).

% within_domain/3 : matches if list integers are within a domain
% 1 - list
% 2 - min
% 3 - max
within_domain(Integers, Min, Max) :-
    max_list(Integers, Max),
    min_list(Integers, Min).

% no_duplicates_within_domain/3: matches if list integers are within a domain and isn't repeated
% 1 - list
% 2 - min
% 3 - max
no_duplicates_within_domain(Integers, Min, Max) :-
    no_duplicates(Integers),
    within_domain(Integers, Min, Max). 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:40:23+00:00Added an answer on May 18, 2026 at 1:40 am

    Here is a simple piece of code that does this in SWI-Prolog. I don’t know if GNU-Prolog provides between/3 and permutation/2, so maybe it doesn’t directly answer your question, but maybe it can still help you further.

    row_valid(List, N) :-
        findall(X, between(1, N, X), Xs),
        permutation(Xs, List).
    

    Usage examples:

    ?- row_valid(List, 0).
    List = [].
    
    ?- row_valid(List, 1).
    List = [1] ;
    false.
    
    ?- row_valid(List, 2).
    List = [1, 2] ;
    List = [2, 1] ;
    false.
    
    ?- row_valid(List, 3).
    List = [1, 2, 3] ;
    List = [2, 1, 3] ;
    List = [2, 3, 1] ;
    List = [1, 3, 2] ;
    List = [3, 1, 2] ;
    List = [3, 2, 1] ;
    false.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a crash report - its from an ad-hoc tester and I cannot
GNU Emacs on Mac OS X, by default, uses the control key as CTRL
This is my code: typedef std::hash_multimap<Vertice<VerticeType, WeightType>*, Edge<VerticeType, WeightType>*> ght; std::pair<ght::iterator, ght::iterator> getEdgesFromVertice(Vertice<VerticeType, WeightType>*);
I am using gnu compiler for java version 4.4.4. It doesn't come with support
This is a pretty straightforward thing, but I've been bashing my head trying to
In asking this question, I'm looking for either better understanding of the situation or
Despite attempts to master grep and related GNU software, I haven't come close to
I'm running this sample code I found while googling: SELECT MD5(RAND()) But, to my
I've been learning GNU Emacs on a Windows system for the last couple of
I am using GNU autotools for my project. The configure.ac script has the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.