
% countries.pro
% Prolog Lab, Semester 1, 2025-2026

% area/2: country-name, area in km^2
area( austria, 83858).
area( france, 547030).
area( germany, 357021).
area( italy, 301230).
area( liechtenstein, 160).  
area( switzerland, 41290).
area( spain, 504851).
area( united_kingdom, 244820).


% pop/2: country-name, no. of people (population)
pop( austria, 8169929).
pop( france, 63182000).
pop( germany, 83251851).
pop( italy, 59530464).
pop( liechtenstein, 32842).  
pop( spain, 47059533).
pop( switzerland, 7507000).
pop( united_kingdom, 61100835).


% nextTo: two countries are next to each other
nextTo( austria, switzerland).
nextTo( switzerland, france).
nextTo( france, germany).
nextTo( france, spain).
nextTo( germany, switzerland).
nextTo( italy, switzerland).
nextTo( liechtenstein, switzerland).  


% ================================

% ?- (nextTo(france, X);nextTo(X,france)), writeln(X).

% ?- pop(C, P), P > 60000000, writeln(C).

% ?- area(C, A), A > 300000, A < 500000, writeln(C).

% ?- member(1, [2,1,3]).


adjacent(C, C1) :-
  nextTo(C, C1).
adjacent(C, C1) :-
  nextTo(C1, C).

% ?- adjacent(france, X), writeln(X).

density(C, Density) :-
  pop(C, Pop), area(C, Area), Density is Pop / Area.

% ?- density(C, Density), write(C), write(" = "), writeln(Density).


biggest([], -1).
biggest([X|Rest], Val) :-
  biggest(Rest, X, Val).

biggest([], Val, Val).
biggest([X|Rest], V, Val) :-
  X > V,
  biggest(Rest, X, Val).
biggest([X|Rest], V, Val) :-
  X =< V,
  biggest(Rest, V, Val).

% ?- biggest([22, 5, 1, 17], V), writeln(V).


?- findall(C, area(C,D), List), writeln(List).

% ?- findall(D, area(C,D), List), biggest(List, Area), 
%   area(Country, Area), writeln(Country). 



% ===========================================
% printing predicate

writeln(Var) :-
  write(Var), write("\n").

writeln(Name, Var) :-
  write(Name), write(" = "), write(Var), write("\n").


