Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
CMCDragonkai / even_and_odd.pl
Last active June 7, 2022 02:17
Prolog: Even and Odd
%% The `=` is Prolog unification operator, it does not perform arithmetic evaluation.
%% That means `8 = 4 + 4` is false in Prolog.
%% Instead you can use `8 is 4 + 4` or `8 =:= 4 + 4`.
%% The unification operator tries to unify intensional structure, and `8 = 4 + 4` is
%% trying to unify `'+'(4, 4)` with `8`.
%% However `8 = 8` unifies!
even(0).
even(X) :- X > 0, X1 is X - 1, odd(X1).
even(X) :- X < 0, X1 is X + 1, odd(X1).
@kalinchernev
kalinchernev / countries
Created October 6, 2014 09:42
Plain text list of countries
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua & Deps
Argentina
Armenia
Australia
Austria