/*
Euler #33 in Picat.
"""
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in
attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct,
is obtained by cancelling the 9s.
We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
There are exactly four non-trivial examples of this type of fraction, less than
one in value, and containing two digits in the numerator and denominator.
If the product of these four fractions is given in its lowest common terms, find
the value of the denominator.
"""
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(euler33).
euler33 =>
S = 1,
foreach(Y in 1..9,Z in Y..9)
X = 9.0*Y*Z/(10.0*Y-Z),
if 1.0*floor(X)==X*1.0, Y/Z < 1.0, X < 10.0 then
S := (S*Y)/Z % ,
% println([X,Y, Z, (floor(10*Y+X)),"/", (floor(Z+10*X)), Y,"/",Z, floor(1/S)])
end
end,
println(floor(1/S)).