Skip to content

Instantly share code, notes, and snippets.

@ichiban
Created December 9, 2019 09:12
Show Gist options
  • Save ichiban/870dfa9211dad9f78b119516908dda0d to your computer and use it in GitHub Desktop.
Save ichiban/870dfa9211dad9f78b119516908dda0d to your computer and use it in GitHub Desktop.
#!/usr/bin/env swipl
:- use_module(library(clpfd)).
:- initialization(main, main).
main(_) :-
current_prolog_flag(max_tagged_integer, Max),
between(3, Max, N),
fermat(X, Y, Z, N),
format('X = ~d~n', X),
format('Y = ~d~n', Y),
format('Z = ~d~n', Z).
fermat(X, Y, Z, N) :-
Vars = [X, Y, Z],
current_prolog_flag(max_tagged_integer, Max),
Vars ins 1..Max,
X ^ N + Y ^ N #= Z ^ N,
label(Vars).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment