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).


 
load "stdlib.ring"
 
see "working..." + nl
see "the first 5 rare numbers are:" + nl
 
num = 0
 
for n = 1 to 2042832002
    strn = string(n)
    nrev = ""
    for m = len(strn) to 1 step -1
        nrev = nrev + strn[m]
    next
    nrev = number(nrev)
    sum = n + nrev
    diff = n - nrev
    if diff < 1
       loop    
    ok
    sqrtsum = sqrt(sum)
    flagsum = (sqrtsum = floor(sqrtsum))
    sqrtdiff = sqrt(diff)
    flagdiff= (sqrtdiff = floor(sqrtdiff))
    if flagsum = 1 and flagdiff = 1
       num = num + 1
       see "" + num + ": " + n + nl
    ok
next
see "done..." + nl
 