2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00

added another prolog example

This commit is contained in:
Martin Thoma 2014-09-16 16:56:23 +02:00
parent 87fe3eb2b5
commit 6829f6cf97
5 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,15 @@
#!/usr/bin/swipl -q -t main -f
% Find three digits X, Y and Z such that
% XYZ in base10 is equal to ZYX in base9
is_solution(X, Y, Z) :- between(0,9,X),
between(0,9,Y),
between(0,9,Z),
Base10 is (100*X + 10*Y + Z),
Base9 is (9*9*Z+9*Y+X),
Base10 = Base9.
main :-
is_solution(X, Y, Z),
format("solution: ~w ~w ~w\n", [X,Y,Z]),
false. % make sure that all solutions get printed