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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.