change( N10, N20, N50) :-
c1( N10), c2( N20), c5( N50),
100 is N10 * 10 + N20 * 20 + N50 * 50.
c5( 0).
c5( 1).
c5( 2).
c2( N) :- c5( N).
c2( 3).
c2( 4).
c2( 5).
c1( N) :- c2( N).
c1( 6).
c1( 7).
c1( 8).
c1( 9).
c1( 10).
Back to example 2.1
map( A, B, C, D, E) :-
adjacent( A, B), adjacent( A, D), adjacent( A, E),
adjacent( B, C), adjacent( B, D), adjacent( B, E),
adjacent( C, D), adjacent( C, E),
adjacent( D, E).
color( red).
color( bue).
color( yellow).
color( green).
adjacent( X, Y) :- color( X), color (Y), X \= Y.
Back to example 2.2
density( S, D) :- population( S, E), area( S, F), D is E/F.
neighbors( S1, S2) :- neighbor( S1, S2).
neighbors( S1, S2) :- neighbor( S2, S1).
neighbor_ch( S) :- neighbors( ch, S).
neighbor_f( S) :- neighbors( f, S).
neighbor_d( S) :-
neighbors( d, S),
population( d, ED), population( S, ES),
area( d, FD), area( S, FS),
ES > ED, FS > FD.
neighbor_ch1( S) :-
neighbors( ch, S),
density( ch, DCH), density( S, DS), DS > DCH.
Back to example 2.3