/* Triangle problem in Picat. From "Fun with Num3ers": "Digits from 0 to 9 used only once" http://benvitalenum3ers.wordpress.com/2013/08/16/digits-from-0-to-9-used-only-once/ """ A B C D E F G H I J Replace the letters A, B, C, D, E, F, G, H, I, J with with a different number from 0 to 9, such that A + C + F + J = A + B + D + G = G + H + I + J and A + B + C = D + G + H = F + I + J """ There are 12 solutions, e.g. [0,5,9,4,3,7,8,2,6,1] 0 5 9 4 3 7 8 2 6 1 [0,9,5,7,3,4,1,6,2,8] 0 9 5 7 3 4 1 6 2 8 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => X = [A,B,C,D,E,F,G,H,I,J], X :: 0..9, all_different(X), A + C + F + J #= A + B + D + G, A + B + D + G #= G + H + I + J, A + B + C #= D + G + H, D + G + H #= F + I + J, solve(X), println(X), printf(" %d\n",A), printf(" %d %d\n",B,C), printf(" %d %d %d\n",D,E,F), printf(" %d %d %d %d\n",G,H,I,J), nl, fail, nl.