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

Help with prolog programming.

Help with prolog programming.

Help with prolog programming.

Hello everybody!
As a newbie, I'm having trouble with programming in prolog (for SWI-Prolog console). My excerise is about the well known broblem of crossing the bridge. Let me introduce you to it.
We have a group of 7 tourists is located around a bridge (I mean that they are not all of them on the same side), and they should cross the bridge with a torch. Our restrictions are that the bridge can bear from 1 to 3 of the tourists each time and also, no one of them can be alone on each side.Additionally, each time the program should let the user know in which state we are as far as the locations of the tourists and the time passed during the bridge-crossing. I'm asked to show all the actions needed (operators) without using any algorithms. I'v tried to write down some piece of code but it always compiles errors.
Here is the code I've already done:

initial_state (state (left(TL), right(TR), torch_left, time(P)).

max_pace (P1, P2, P3, P3) :- P1 =< P3, P2 =< P3
max_pace (P1, P2, P3, P2) :- P1 =< P2, P3 =< P2
max_pace (P1, P2, P3, P1) :- P1 > P2, P1 > P3
max_pace (P1, P2, P2) :- P1 =< P2
max_pace (P1, P2, P1) :- P1 > P2

left_operator (state (left(TL), right(TR), torch_left, time(P)),
state (left(NTL), right(NTR), torch_right, time(P)).

right_operator (state (left(TL), right(TR), torch_right, time(P)),
state (left(NTL), right(NTR), torch_left, time(P)).

%Bridge- crossing from left to right side.

move (T),
T =< TL,
NTL is TL-T,
NTR is TR+T,
valid (NTL,2),
P is max_pace,
write('The bridge is crossed within P minutes'), nl.

%Bridge- crossing from right to left side.

move (T),
T =< TR,
NTR is TR-T,
NTL is TL+T,
valid (NTR,2),
P is max_pace,
write('The bridge is crossed within P minutes'), nl.

I know that this isn's the best attempt but I'm still working on it. I hope you can help me!

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