Some positive integers n have the property that the sum
[ n + reverse(n) ] consists entirely of odd (decimal) digits.
For instance, 36 + 63 = 99 and 409 + 904 = 1313.
We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n).
There are 120 reversible numbers below onethousand.
a. Evaluate how many reversible numbers are there
below 10^{k}, k=2,3... up to 6 or 7 .
b. Analyze the results, aiming to find the relation (i.e. approximate function) between N(k) and k.
Source: Project Euler, modified.
Limit is followed by number under that limit:
100 20
1000 120
10000 720
100000 720
1000000 18720
10000000 68720
DefDbl AZ
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
rept = 100
For n = 1 To 10000000
If n Mod 10 > 0 Then
ns$ = LTrim(Str(n))
nrs$ = ""
For i = 1 To Len(ns)
nrs = Mid(ns, i, 1) + nrs
Next
tot$ = LTrim(Str(n + Val(nrs)))
good = 1
For i = 1 To Len(tot)
If InStr("13579", Mid(tot, i, 1)) = 0 Then good = 0: Exit For
Next
If good Then ct = ct + 1
End If
If n = rept Then
Text1.Text = Text1.Text & rept & Str(ct) & crlf
rept = 10 * rept
DoEvents
End If
Next
Text1.Text = Text1.Text & ct & crlf & " done"
End Sub

Posted by Charlie
on 20150807 18:59:07 