×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

# Help with prolog programming.

## Help with prolog programming.

(OP)
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),
valid(NTR,2)
time(P)
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),
valid(NTL,2)
time(P)
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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!