/* Adding their cubes in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 13. Adding their cubes The numbers 407 and 370 have this peculiarity, that they exactly equal the sum of the cubes of their digits. Thus, the cube of 4 is 64, the cube of 0 is 0, and the cube of 7 is 343. Add together 64, 0, and 343, and you get 407. Again, the cube of 3 (i.e. 27), added to the cube of 7 (i.e. 343), is 370. Can you find a number not containing a 0 that will work in the same way? Of course, we bar the absurd case of 1. (puzzle 143 from Dudeney (2016)) """ There are two such numbers: 153 371 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 ?=> N = 3, Xs = new_list(N), Xs :: 1..9, X :: 100..999, to_num(Xs,X), X #= sum([Xs[I]**3 : I in 1..N]), Vars = Xs, solve(Vars), println(X), fail, nl. go => true. % % 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]). to_num(List, Num) => to_num(List, 10, Num).