/* Lucky numbers in Picat. From God Plays Dice "What is the origin of Kirillov's lucky number problem?" http://godplaysdice.blogspot.com/2011/03/what-is-origin-of-kirillovs-lucky.html """ I've run across a few references to a Russian superstition as follows: a bus ticket has a six-digit number, and a ticket is said to be "lucky" if the sum of the first three digits equals the sum of the last three digits. """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 6, lucky_number(N, _X,A), println(A), fail, nl. go => true. lucky_number(N, X,A)=> M = N div 2, X = new_list(N), X :: 0..9, A :: 10**(N-1)..10**N-1, sum(X[1..M]) #= sum(X[M+1..N]), to_num(X,10,A), Vars = X ++ [A], solve(Vars). to_num(List, Base, Num) => Len = length(List), Num #= sum([List[I]*Base**(Len-I) : I in 1..Len]).