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

  • SEARCH
  • Home
  • 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 6855225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:43:51+00:00 2026-05-27T01:43:51+00:00

I am asking for help in basic Prolog, a language whose paradigms are difficult

  • 0

I am asking for help in basic Prolog, a language whose paradigms are difficult for me to grasp. I am very familiar with other languages (C++, Lisp, Java, Assembly, etc.) but am a complete novice with Prolog.

What needs to be solved – in basic English: given 2 parameters, find a corresponding number in a 2D Array.

The problem is a brainlessly easy puzzle on the web which asks you to pick a number, choose that number’s color and then pick the house that contains your given number. The puzzle is set up such that there is only one number for each corresponding color/house combination.

What is currently in place:

function guess(Color, Houses) :-
<--Need what goes here -->

green(1, 15, 23, 24).
pink(2, 6, 10, 18).
etc...

houseA(2, 4, 7, 14).
etc...

The code must match the colors and houses to pick out the correct number. So for example, given "?- guess(pink, houseA)" should return "Your number is 2."

I have been writing down ideas on how to implement this in prolog and none of them get me any further. I do not know how I would implement if/else statements to check which color I should search, or how to check which numbers would correspond between house and color, or even how to “return” values!

It seems to me that I am missing a key point or…way of thinking about the language.

Any help would be appreciated. Thank you!

  • 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-27T01:43:52+00:00Added an answer on May 27, 2026 at 1:43 am

    To return a value, you need another parameter in your predicate (not function btw). This parameter will be a free variable and you will bind it to the result.

    In prolog specifications, such parameters are noted -Parameter while already bound parameters are noted +Parameter and parameters that can be both bound and free are noted ?Parameter. So here for you you could have a comment such as :

    % guess/3 (specify the arity of your predicate)
    % guess(+Color, +House, -Result) (give info about your parameters)
    % guess finds a color shared by Color and House and binds it to Result.
    

    Then, predicates such as pink, houseA and so on are not that great to find numbers from. You can turn them into more adapted predicates by having numbers stored in a list :

    green([1, 15, 23, 24]).
    pink([2, 6, 10, 18]).
    houseA([2, 4, 7, 14]).
    

    When we got that list, we can write :

    guess(Color, House, Result) :-
        call(Color, Pool1),
    

    If you call guess(pink, houseA), that will call your predicate pink with argument Pool1, prolog will try to match Pool1 and [2, 6, 10, 18] so Pool1 is going to be bound to this list precisely.

        call(House, Pool2),
    

    Same with houseA and Pool2.

        member(Result, Pool1),
    

    Now we tell prolog that we want our Result to be a member of Pool1

        member(Result, Pool2),
    

    And a member of Pool2.

        write('Your number is '),
        write(Result),
        write(.),
        nl.
    

    Finally we display the message.

    Prolog will display result as R = x; false below that, if you don’t want the ; false part, you can add a “cut” :

        nl.
    

    =>

        nl,
        !.
    

    The !/0 predicate (cut) tells prolog not to backtrack to try to find other solutions. There it would have backtracked on member explaining why prolog returned a choice with only one result and false.

    Hope it helps. If you got problems to understand some parts please say so and I’ll give infos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I must be asking a very basic question. I've just learnt how to apply
Humbly asking for help with (of course) IE. I have a div that is
I'm new to ADO.NET so asking for help. I have to insert large number
I can say I don't know what I'm asking for help,because I don't know
Asking for your help on this Oracle query. It's giving me the error 2
My apologies for asking such a novice question but, I need help building a
I know I'm not asking this quite right, either. Please help me better form
Instead of asking for help when hitting the iceberg, now I can see there
I've posted a code snippet on another forum asking for help and people pointed
I am asking for help on self-help, which is kind of an oxymoron. How

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.