0
weather(sunday,fair).
weather(monday,overcast).
weather(tuesday,fair).
weather(wednesday,fair).
weather(thursday,overcast).
weather(friday,rainy).
weather(saturday,overcast).

sky(blue):- weather(Day,fair).
sky(grey):- weather(Day,overcast).

If the weather is fair, the color of the sky is blue.
If the weather is overcast, the color of the sky is grey.

Birds are active on Sunday, Tuesday, and Thursday.
Birders are happy on a given day if the day is fair and birds are active on that day.

The 4 statements i need to translate into code are the problems im having. Ive attempted the first 2 but i think there's something wrong with them. I'm just barely learning basics of Prolog so i don't know very much. Ive been sitting here for a few hours now and looking around on the internet but i can't seem to find anything that helps.

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by rebellion346
0

Hi there,

You're on the right track, but you'll have to add a variable to the sky clause in order to receive a correct result.

sky(blue):-weather(Day,fair).

...should be written as

sky(Day,blue):-weather(Day,fair).

Then you can ask prolog for sky(X,blue). to receive all the days (X) for which the sky color is blue.

This works the same way for the birds.

birdsActive(sunday).
birdsActive(tuesday).
birdsActive(thursday).
birdsHappy(Day):-birdsActive(Day),weather(Day,fair).

By asking birdsHappy(X). you will receive all the days (X) for which the birders are happy.

Hope this helps,

Traevel

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.