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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:19:55+00:00 2026-05-27T18:19:55+00:00

Sample database: any(a,b,2). any(b,c,2). any(c,d,3). any(d,e,1). any(e,f,3). Key: (Station1,Station2,Time) . The question: enter (station1,time)

  • 0

Sample database:

 any(a,b,2). 
 any(b,c,2). 
 any(c,d,3). 
 any(d,e,1). 
 any(e,f,3).

Key: (Station1,Station2,Time).

The question:

enter (station1,time) into prolog and have it return all of the stations within reach.

For example:

If you enter: (b,2).

The output should be: ‘a’ and ‘c’

This is because from station ‘b’ in ‘2’ minutes, you will be able to get to stations ‘a’ and ‘c’ as they are within reach of the time entered.


I have tired using lists and recursion but no luck, any help/suggestions?


reachable(Station1, Limit, Result) :-
    reachable(Station1, Limit, 0, 0, Result).

reachable(Station1, Visited, TimeSpent, Limit, Result) :-
    overground(Station1,Station2,Time),
    Visited is Limit - Time,
    Limit =< TimeSpent,
    Result = [Station2];
    overground(Station1, Waypoint, Time),
    NewVisited is Visited - Limit,
    NewTimeSpent is TimeSpent - NewVisited,
    reachable(Waypoint,Station2, NewTimeSpent, NewVisited,Result).

<<< something I tried but doesnt seem to work X_X

  • 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-27T18:19:56+00:00Added an answer on May 27, 2026 at 6:19 pm

    So, let’s look at the problem :

    1. you need to be able to find the station in “both ways” from your predicate, ie any(MyStation, Y) or any(Y, MyStation), so you’ll need a disjunction when using any/3.
    2. you need to find a station that isn’t directly in reach of the departure station if necessary, through recursion.
    3. since you have to use recursion, you have to keep track of time already spent at a given point of the recursion with an accumulator, in order to know if a station at a given point still satisfies the time limit.
    4. since you have to use recursion, you have to keep track of already visited stations, in order not to fall into an infinite loop, or to give twice the same result just through one more loop in a circuit this will be done thanks to an accumulator this time again.

    General look of the solution :

    First step, calling the working predicate :

    reachable(From, Limit, Result) :-
        ...
    

    Where ... should be a call to reachable/5 (this one + the 2 accumulators).

    Second step, the working predicate :

    reachable(From, Visited, TimeSpent, Limit, Result) :-
        ...
    

    Where ... should satisfy those guidelines :

    • first you have to find a station that is related to From thanks to any/3
    • then you have to check if this station is in Visited or not
    • then you have to write a disjunction with two cases (or write two clauses) :
      • the final case ie you check that time spent is under the limit and unify Result with the appropriate variable
      • the recursive case ie you call reachable with a new TimeSpent that you calculate, a new Visited that you update and a new departure station.

    If you want more precise advice, I’d advise you to publish the work you’ve already done so that we can work from there !

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

Sidebar

Related Questions

I have a very simple question. Is there any way to relate database errors
I have installed a sample database, specifically Northwind from http://msdn.microsoft.com/en-us/library/8b6y4c7s.aspx . After installing the
Say you have a string 3.4564. A sample set in the database has these
I have a table in my database with columns: Lead_id INT(11) PRIMARY KEY NOT
I have a simple database to store some emails, Is there any way to
I have worked on sample application for insert the data into SqliteDb and try
Does anybody know of any sample databases I could download, preferably in CSV or
I need a simple app to edit database tables. Are there any code generators
Where I can download sample database which can be used for data warehouse creation?
I'm looking at the AdventureWorks sample database for SQL Server 2008, and I see

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.