Definitions and restrictions

Rare   numbers are positive integers    n    where:

    n    is expressed in base ten
    r    is the reverse of    n      (decimal digits)
    n    must be non-palindromic   (n ≠ r)
    (n+r)    is the   sum
    (n-r)    is the   difference   and must be positive
   the   sum   and the   difference   must be perfect squares


Task

   find and show the first   5   rare   numbers
   find and show the first   8   rare   numbers       (optional)
   find and show more   rare   numbers                (stretch goal)


Show all output here, on this page.



References

   an   OEIS   entry:   A035519          rare numbers.
   an   OEIS   entry:   A059755   odd rare numbers.
   planetmath entry:   rare numbers.     (some hints)
   author's  website:   rare numbers   by Shyam Sunder Gupta.     (lots of hints and some observations).


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
