I will be checking my e-mail intermittently while I'm gone.
To start up Prolog, type "pl" at any UNIX prompt.
?- sorted([1,2,3,4,7]).
Yes
?- sorted([2,3,4,1,7]).
No
Here are two hints:
Hint 1:
The Prolog predicate "<" checks if one quantity is less than another.
For example:
?- <(3,5).
Yes
?- <(5,3).
No
Hint 2:
In class, we used the Prolog header/tail notation only on the left
side of an implication. It can also can be used on the right side, or both.
For example, here is a Prolog predicate that is true if and only if Y is
the rest of list X:
- [user].
| rest(X,Y) :- [A | B] = X, B = Y.
| % user compiled 0.01 sec, 380 bytes
Yes
?- rest([a,b,c],Q).
Q = [b, c] ;
No
?- rest([a,b,c,d,e],Q).
Q = [b, c, d, e] ;
No
Make sure to name your program sorted.pl, and submit it using hsp.
To give you a sense of scale: my solution consisted of two lines of Prolog code. Yours should be roughly the same (2 plus or minus 5).
consult('wumpus.pl').
deadWumpus(X).
Prolog will start showing you varying ways to solve the problem. When it shows you the first one, hit the "w" key to get read of the "..." and give you the full output. Hit a semicolon to see more results, and an "a" to abort the program.
YOUR GOAL:
Copy wumpus.pl to a new program, called pitwumpus.pl. Modify it so
that there is a pit in location (2,3), and modify the code so that the
hero always avoids this pit. Remember, this is a simple version of the
wumpus world where all the agent is trying to do is get from the starting
location at (2,2) to the sword at (3,3). pick it up, then walk back to
(1,1) to hit the wumpus. This is intended to be straightforward - don't
add any breezes or anything like that. My solution consisted of two small
modifications to the code.
Submit pitwumpus.pl using hsp.