/*
Euler #38 in Picat.
"""
Take the number 192 and multiply it by each of 1, 2, and 3:
192 × 1 = 192
192 × 2 = 384
192 × 3 = 576
By concatenating each product we get the 1 to 9 pandigital,
192384576. We will call 192384576 the concatenated product of 192
and (1,2,3)
The same can be achieved by starting with 9 and multiplying by
1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the
concatenated product of 9 and (1,2,3,4,5).
What is the largest 1 to 9 pandigital 9-digit number that can be
formed as the concatenated product of an integer with
(1,2, ... , n) where n > 1?
"""
This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
main => go.
go => time(euler38).
euler38 =>
MaxN = 0,
foreach(N in 9876..-1..9, S = N.to_string(), S[1] != 49+9, MaxN == 0)
I = 2,
while(S.length < 9)
S := S ++ (N*I).to_string(),
I := I + 1
end,
SLen = S.length,
if SLen == 9, is_pandigital(S) then
MaxN := S
end
end,
println(MaxN).
is_pandigital(L) =>
L.length == 9, not member('0',L), [I=1 : I in L.to_string()].new_map().keys().length == 9.