Prolog example – bookies exercise

Bookies wants to take some bets and of course they want to make profit with it. All they have are latest results from friendly matches.Predicate win(Team1, Team2, Result) means that the first team won the match with the Result.

Initial knowledge database

Predicate to return difference between points

Write predicate gd(Team, GD) that returns the difference between all points that Team got and points that Team gave.

 

 

What answers Prolog to following queries:

?- win(portugal, X, 2-0).

X = croatia ?;
X = egypt ?;
no

?- win(netherlands, X, _).

X =  ivory_coast ?;
X = ecuador ?;
X = ecuador ?;
no

?- win(X, mexico, _), !, win(mexico, Y, _).

X = south_corea,
Y = paraguay ? ;

X = south_corea,
Y = congo ? ;

X = south_corea,
Y = gana ? ;
no

?- win(X, Y, _-2).

X = argentina,
Y = portugal ? ;

X = croatia,
Y = argentina ? ;
no

How would you ask Prolog following questions (don’t write predicates):

Which teams have been beaten by argentina?

Did team1 won team2, team2 won team3 and team3 won team1?

How many different teams did argentina played with?

List teams that won by at least two point difference.

Prolog predicate group() example

Teams will be arranged in groups. Predicate group(Team, Group) caries information in which group team is. Team is safe (it will surely go to next round) if it hasn’t been beaten by a team from the same group. Following program was written by unskilled programmer and it has errors. Correct it.

Proper program 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Please prove me that you are not spamer :) * Time limit is exhausted. Please reload CAPTCHA.