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


Function revn(n As ULongInt, nd As ULongInt) As ULongInt
    Dim As ULongInt r
    For i As UInteger = 1 To nd
        r = r * 10 + n Mod 10
        n = n \ 10
    Next i
    Return r
End Function
 
Dim As UInteger nd = 2, count, lim = 90, n = 20
 
Do
    n += 1
    Dim As ULongInt r = revn(n,nd)
    If r < n Then
        Dim As ULongInt s = n + r, d = n - r
        If nd And 1 Then
            If d Mod 1089 <> 0 Then GoTo jump
        Else
            If s Mod 121 <> 0 Then GoTo jump
        End If
        If Frac(Sqr(s)) = 0 And Frac(Sqr(d)) = 0 Then
            count += 1
            Print count; ": "; n
            If count = 5 Then Exit Do : End If
        End If
    End If
jump:
    If n = lim Then
        lim = lim * 10
        nd += 1
        n = (lim \ 9) * 2 
    End If
Loop
 
Print
Print "Done"
Sleep