Skip to content

Instantly share code, notes, and snippets.

@Koitaro
Created October 1, 2011 19:47
Show Gist options
  • Select an option

  • Save Koitaro/1256559 to your computer and use it in GitHub Desktop.

Select an option

Save Koitaro/1256559 to your computer and use it in GitHub Desktop.
CHR : Project Euler 130-139
:- use_module(library(chr)).
:- chr_option(optimize, full).
:- chr_constraint triangle(+int,+int,+int), answer(+int), problem139.
problem139 <=> triangle(3,4,5).
next_triangle(A,B,C) :-
X is -A-2*B+2*C, Y is -2*A-B+2*C, Z is -2*A-2*B+3*C,
triangle(X,Y,Z).
triangle(A,B,C) <=> A+B+C >= 10**8 | true.
triangle(A,B,C) ==> A1 is -A, B1 is -B, next_triangle(A1,B1,C).
triangle(A,B,C) <=> X is (10**8-1)//(A+B+C), answer(X).
answer(M), answer(N) <=> X is M+N, answer(X).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment