/* Project Euler #62 in Picat. http://projecteuler.net/problem=62 """ The cube, 41063625 (345^3), can be permuted to produce two other cubes: 56623104 (384^3) and 66430125 (405^3). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube. Find the smallest cube for which exactly five permutations of its digits are cube. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => euler62. euler62 => M = new_map(), Found = false, N = 1, while(Found = false) C = N.cube(), % sort the permutation for hashing Str = C.to_string().sort(), if M.has_key(Str) then if not membchk(N,M.get(Str)) then M.put(Str,M.get(Str)++[N]) end else M.put(Str,[N]) end, if M.get(Str).length == 5 then SS = M.get(Str), % println([Str,SS, SS.min()]), Found := SS.min() end, N := N +1 end, println([Found,Found.cube()]), nl. cube(N) = N*N*N. % cube(N) = N**3.