% The rules for membership of a club are set out in the club's constitution
% as follows:
% 
% 	A person applying for membership of the Computer Science Drop-outs Club
% 	will be deemed acceptable for membership provided that the applicant has
%	been proposed by two other persons, each of whom, is qualified to propose
%	the applicant, and provided the applicant is eligible for membership under
%	the terms below.
% 
% 	The applicant is eligible for membership if he or she has dropped out 
% 	of a Computer Science course.
% 	The applicant must be less the 21 years of age.
% 	An applicant is not eligible for membership if his or her annual salary is
% 	greater than $20,000.
% 	
% 	A proposer is not qualified to propose a potential applicant if he or she 
% 	has not been a member of the club far at least two years.
%
%	All of the above conditions will be waived if the applicant's annual salary
%	is $100,000 or more.
% 
% Translate these rules into a set of Prolog clauses. Your program should be
% able to answer the question:
% 
% 	acceptable(Person)?
% 
% Therefore should begin by defining an acceptable person in terms of conditions
% set out.
% You may assume that the following information is held in the database:
% 
% 	earns(Person, Salary).
% 	age(Person, Age).
% 	joined_in_year(Person, Year).
%	current_year(Year).
% 	has_proposed(Proposer, Applicant).
% 	discontinued(Person, Course).
% 

earns(fred, 19000).
age(fred, 20).
discontinued(fred, computer_science).
joined_in_year(bill, 1984).
joined_in_year(jim, 1984).
current_year(1988).
has_proposed(bill, fred).
has_proposed(jim, fred).

acceptable(Person) :-
	discontinued(Person, computer_science),
	age(Person, Age),
	Age < 21,
	earns(Person, Salary),
	Salary < 20000,
	has_two_proposers(Person).
acceptable(Person) :-
	earns(Person, Salary),
	Salary >= 100000.

has_two_proposers(Person) :-
	has_proposed(Proposer1, Person),
	has_proposed(Proposer2, Person),
	Proposer1 /= Proposer2,
	qualified_to_propose(Proposer1),
	qualified_to_propose(Proposer2).

qualified_to_propose(Proposer) :-
	joined_in_year(Proposer, Joined),
	current_year(ThisYear),
	ThisYear >= Joined + 2.
