RosettaCodeData/Task/Rare-numbers/Phix/rare-numbers-1.phix
2026-02-01 16:33:20 -08:00

31 lines
714 B
Text

with javascript_semantics
function revn(atom n, integer nd)
atom r = 0
for i=1 to nd do
r = r*10+remainder(n,10)
n = floor(n/10)
end for
return r
end function
integer nd = 2, count = 0
atom lim = 99, n = 9, t0 = time()
while true do
n += 1
atom r = revn(n,nd)
if r<n then
atom s = n+r,
d = n-r
if s=power(floor(sqrt(s)),2)
and d=power(floor(sqrt(d)),2) then
count += 1
printf(1,"%d: %d (%s)\n",{count,n,elapsed(time()-t0)})
if count=3 then exit end if
end if
end if
if n=lim then
-- ?{"lim",lim,elapsed(time()-t0)}
lim = lim*10+9
nd += 1
end if
end while