/* Remainder problem in Picat. """ 11. Is there a number which when divided by 3 gives a remainder of 1; when divided by 4, gives a remainder of 2; when divided by 5, gives a remainder of 3; and when divided by 6, gives a remainder of 4? (Kordemsky) """ Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => writeln(findall(X,$remainder(X,10000))),nl. go2 => writeln(findall(X,$remainder2(X,10000))),nl. remainder(X,Max) => [X,A,B,C,D] :: 1..Max, X #= A*3 + 1, X #= B*4 + 2, X #= C*5 + 3, X #= D*6 + 4, solve([X,A,B,C,D]). remainder2(X,Max) => [X,A,B,C,D] :: 1..Max, foreach({I,K} in zip(1..4,[A,B,C,D])) X #= K*(I+2) + I end, solve([X,A,B,C,D]).