954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Weather in Prolog

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.

rebellion346
Light Poster
37 posts since Aug 2010
Reputation Points: 10
Solved Threads: 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

Traevel
Light Poster
38 posts since May 2009
Reputation Points: 16
Solved Threads: 16
 

THANK YOU! This program has been driving me nuts for the last few days...

rebellion346
Light Poster
37 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You