01-two-bases.prolog 509 B

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