/* Successive number problem in Picat. From God Plays Dice: "A cute number theory puzzle" http://godplaysdice.blogspot.com/2011/07/cute-number-theory-puzzle.html """ Today's MAA number of the day, when multiplied by its successor, gives a number concatenated with itself. (Like 455 * 539 = 245245, except 539 isn't the successor of 455.) Puzzle: find all such three-digit numbers. (The fact that I'm phrasing it this way should indicate to you that there's more than one.) Meta-puzzle: generalize this. (I have some generalizations in mind.) """ The problem is explained here: "Solution to a puzzle from a few months ago " http://godplaysdice.blogspot.com/2011/10/solution-to-puzzle-from-few-months-ago.html 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 :: 0..999, XA = new_list(3), XA :: 0..9, Y :: 0..999, YA = new_list(3), YA :: 0..9, Z :: 0..999999, ZA = new_list(6), ZA :: 0..9, to_num(XA,10,X), to_num(YA,10,Y), to_num(ZA,10,Z), Y #= X + 1, X * Y #= Z, foreach(I in 1..3) ZA[I] #= ZA[I+3] end, Vars = XA ++ YA ++ ZA, solve(Vars), println([X,Y,Z]), fail, nl. % Without to_num/3 go2 => X :: 0..999, Y :: 0..999, Z :: 0..999999, Y #= X + 1, X * Y #= Z, Z div 100000 mod 10 #= Z div 100 mod 10, Z div 10000 mod 10 #= Z div 10 mod 10, Z div 1000 mod 10 #= Z mod 10, Vars = [X,Y,Z], solve(Vars), println(Vars), fail, nl. % % converts a number Num to/from a list of integer List given a base Base % to_num(List, Base, Num) => Len = length(List), Num #= sum([List[I]*Base**(Len-I) : I in 1..Len]).