/* Super number puzzle in Picat. From https://www.logisch-gedacht.de/logikraetsel/10stellige-zahl/ (German) Translated: """ The Super number We are looking for the 10-digit number which satisfies the following conditions: All digits from 0-9 occur exactly once. The first 2 digits are divisible by 2. The first 3 digits are divisible by 3. ... The first 10 digits are divisible by 10. """" Solution: 3816547290 Also see: https://stackoverflow.com/questions/44348306/solving-a-logic-riddle-in-prolog This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. import cp. main => go. go => N = 10, X = new_list(N), X :: 0..9, all_different(X), foreach(I in 2..N) to_num([X[J] : J in 1..I],T), T mod I #= 0 end, solve($[ff,split],X), println([X[I].to_string() : I in 1..N].join('')), nl. to_num(List, Num) => Len = length(List), Num #= sum([List[I]*10**(Len-I) : I in 1..Len]).