/* Solve the equation in Picat. 11x11=4 22x22=16 33x33=? This model solves the problem with four interpretations. (2013-03-11: I've seen this problem in my web server log the last days. Don't know the origin.) Later comment: MindYourDecision (Presh Talwalkar) has blogged/youtubed about it: "Viral Puzzle 11×11 = 4. The Correct Answer Explained" - https://mindyourdecisions.com/blog/2016/09/21/viral-puzzle-11x11-4-the-correct-answer-explained/ - https://www.youtube.com/watch?v=IQd1oDsHVSc&feature=youtu.be&fbclid=IwAR3fblHbfwmuAQ23UcIvTI70i6KyyIGxst2F9c5oB7ZsKOrOIP5K-5mQaAs Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => interpretation1(X1), writeln(x1=X1), interpretation2(X2), writeln(x2=X2), interpretation3(X3), writeln(x3=X3), interpretation4(X4), writeln(x4=X4), nl. % 33x33=36 interpretation1(X) => X :: 0..10000, (1+1) * (1+1) #= 4, (2+2) * (2+2) #= 16, (3+3) * (3+3) #= X, solve(X). calc(X,Y,Z) => Len = length(X), Xs = [(10**I) : I in 0..Len-1], scalar_product(X,Xs,Y), sum(X) #= Z. % 33x33=18 interpretation2(X) => X :: 0..10000, N = 6, A = new_list(N), A :: 0..9, B = new_list(N), B :: 0..9, C = new_list(N), C :: 0..9, calc(A, 11*11, 4), calc(B, 22*22, 16), calc(C, 33*33, X), solve(X). s3(I, X) => X #= 4**I. % 33x33=64 interpretation3(X) => X :: 0..10000, s3(1, 4), s3(2, 16), s3(3, X), solve(X). s4(I, X) => X #= 4*(I**I). % 33x33=108 interpretation4(X) => X :: 0..10000, s4(1, 4), s4(2, 16), s4(3, X), solve(X).