%%% 14.11.2009 %%%
% Group 1

%% Task 2
% K - a list of lists with two elements (natural numbers)
% X, Y - natural number

% is_member(E, L)
is_member(H, [H|_]).
is_member(H, [_|T]) :- is_member(H, T).

% gennat(N) :- Generates natural numbers
gennat(0).
gennat(N) :- gennat(N1), N is N1 + 1.

% is_nat(N) :- Checks if N is a natural number
is_nat(0).
is_nat(N) :- N > 0, N1 is N - 1, is_nat(N1).

% first_condition(X, Y, K)
first_condition(X, Y, K) :- A is X + 1, B is Y - 1,
							is_member([A, B], K).

% second_condition(X, Y, K)
second_condition(X, Y, K) :- is_member([X1, Y1], K),
							 is_member([X2, Y2], K),
							 X1 \= X2, Y1 \= Y2,
							 X is X1 + X2,
							 Y is Y1 * Y2.

% second_condition(X, Y, [[1,2], [5,6], [1,5], [3,4]]).

% third_condition(X, Y, K)
third_condition(X, Y, K) :- A is X * Y * Y,
							B is X * X * Y,
							is_member([A, B], K).

% third_condition(1, 2, [[1,2], [5,2], [1,5], [3,8]]).

p(X, Y, K) :- gennat(X), gennat(Y),
			  (first_condition(X, Y, K);
			  	second_condition(X, Y, K);
			  	third_condition(X, Y, K)).