/* Impossible Ages of Sister Puzzle in Picat. From MindYourDecisions The "Impossible" Ages of Sisters Puzzle https://www.youtube.com/watch?v=1a2GNU0Ypz4 """ Asha and Lata are two sisters with mathematically interesting ages. If you write Lata's age after Asha's, you get a 4 digit perfect square. Amazingly the same thing happens if you repeat the exercise in 11 years. How old are Asha and Lata currently? """ This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. % import util. import cp. import cp_utils. main => go. go ?=> % Now d(Asha1,Asha1A), d(Lata1,Lata1A), a(Asha1A,Lata1A,A1L1), perfect_square(A1L1), % In 11 years d(Asha2,Asha2A), d(Lata2,Lata2A), a(Asha2A,Lata2A,A2L2), perfect_square(A2L2), Asha1 + 11 #= Asha2, Lata1 + 11 #= Lata2, Vars = [Asha1,Asha2,Lata1,Lata2], solve($[ff,split],Vars), println(asha=[now=Asha1,in_11_years=Asha2]), println(lata=[now=Lata1,in_11_years=Lata2]), nl, fail, nl. go => true. % Two digit number <-> list d(X,A) => A = new_list(2), A :: 0..9, X :: 10..100, to_num(A,X). % concatenate two 2-digit numbers (as lists) <-> a four digit number a(A,B,AB) => ABA = A ++ B, AB :: 1000..9999, to_num(ABA,AB). % is a perfect square perfect_square(X) => P :: 1..100, P*P #= X.