2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 14:28:05 +02:00
LaTeX-examples/documents/Programmierparadigmen/scripts/prolog/01-two-bases.prolog

15 lines
509 B
Prolog
Raw Normal View History

2014-09-16 16:56:23 +02:00
#!/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