/* Divisors ending in 0 to 9 puzzle in Picat. From Card Colm Mulcahy https://twitter.com/CardColm/status/547518933398732803 """ RT of @WWMGT (from MG book): Find the smallest integer which has divisors ending in 0,1,2,3,4,5,6,7,8 and 9 (problem via @BruceReznick ) """ Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. % import sat. main => go. divisors(N) = [ I : I in 1..N div 2, N mod I == 0]. go => X = [], foreach(N in 1..3000) DivisorsMod10 = [D mod 10 : D in divisors(N)].remove_dups().sort(), if DivisorsMod10.length == 10 then X := X ++ [N] end end, println(x=X), % I can't see any direct pattern in the differences... println(diffs=[X[I]-X[I-1] : I in 2..X.length]), nl. % % shorter variant % go2 ?=> between(1,1000,N), [D mod 10 : D in 1..N div 2, N mod D == 0].remove_dups().sort().length() == 10, println(N), fail. go2 => true. % % another approach % go3 => between(1,1000,N), foreach(I in 0..9) between(1,N div 2,D), N mod D == 0, D mod 10 == I end, println(N), nl. % % CP version % go4 => Max = 1000, N :: 1..Max, foreach(I in 0..9) sum([D mod 10 #= I #/\ N mod D #= 0 : D in 1..Max div 2]) #> 0 end, solve([degree,split],[N]), println(n=N), fail, nl.