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 8929585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:42:19+00:00 2026-06-15T08:42:19+00:00

I have been working on this code to look for the location and tell

  • 0

I have been working on this code to look for the location and tell me if the location exists. The code is:

    location(C, L).
    location(C, [C,L]|_]).
    location(C, [_|T]):- location(C,T,L).

and i want it to be true if C appears as a chest in the location L. I type in the following code which is:

    location(b,[(a, 1), (b,2)]).

The answer should be given as a yes as its found that the chest is in the location. This does give me a yes but when i change the code to:

   location(e, [(a,1), (b,2)]).

I still get a yes when it should state a no. Does anyone know what im missing?

  • 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-06-15T08:42:20+00:00Added an answer on June 15, 2026 at 8:42 am

    Hello I’ll try to answer your question and point out at your errors.
    Your first line says any C is element of L. Unification in Prolog is done from the top towards the bottom, and from left to right. So Prolog will always unify that line, hence it will return true always. Your second and third line contain syntax errors. Anyways here is the code that should answer your question :

    % here we say that no chest can be contained in an empty location

     location(_,[]) :- fail.
    

    % if we somehow manage to get to a head that contains C thats true

    location(C,[Head|_]) :- Head=(C,_).
    

    % here we say if C is not equal to Something(from the Head) try to look for C in the Tail

    location(C,[Head|Tail]):- Head=(Something,_),not(Something = C),location(C,Tail).
    

    You can also solve it in the following manner

    %basically you ask is there a member Chest in L such that Chest=(C,_).

    location1(C,L) :- member(Chest,L),Chest=(C,_). 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have been working on this code that creates a table with radio
Have been working on this question for a couple hours and have come close
I have been working on this app for at least 3-4 months and just
I have been working on this sort of ATM (With a maximum of 50
I have been working on this for few hours and got stuck, so how
I have been working on this application that enables user to log in into
I have been working on this problem for 2 days now and it's an
I have been working on this for days but I don't get it so
I have been working on this problem for a while now. I am trying
I have been working on this for 24 hours now, trying to optimize it.

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.