Chose a positive integer N.
Repeatedly
replace this number by the sum of the cubes of its digits.
Stop once the replacement left the number unchanged.
Show that the "fixed point result" is only one of five possible choices.
List them.
5 * 9^3 = 3645, so any number of digits above 4 will reduce the number of digits at each iteration. So we need look only up to 4-digit numbers.
The program below reports the first number where the procedure leads to a given number. The results were:
1 1
2 371
3 153
4 133 55 250 133
7 370
16 217 352 160 217
47 407
49 1099 1459 919 1459
55 55 250 133 55
79 352 160 217 352
136 153 136 244 136
160 160 217 352 160
163 163 244 136 244
250 250 133 55 250
478 478 919 1459 919
There are indeed only 5 fixed points, where the result stays constant: 1, 371, 153, 370 and 407. I would not say, however, that there are only "five possible choices", as one does not know ahead of time that one will hit a fixed point.
Another possibility is that you cycle ... 133 55 250 133 ...
another cycle is ... 217 352 160 217 ...
or back and forth between 919 and 1459
or between 244 and 136.
So there are 5 fixed points possible, and 4 cycles possible.
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For n = 1 To 9999
nn = n
Do
ppprev = pprev
pprev = prev
prev = nn
nn = socd(nn)
DoEvents
Loop Until nn = prev Or nn = pprev Or nn = ppprev
s$ = Str(nn)
If InStr(allNN$, s) = 0 Then
Text1.Text = Text1.Text & n
If nn <> prev Then Text1.Text = Text1.Text & Str(ppprev) & Str(pprev) & Str(prev)
Text1.Text = Text1.Text & s & crlf
allNN = allNN + s
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Function socd(n)
s$ = LTrim(Str(n))
tot = 0
For i = 1 To Len(s$)
d = Val(Mid(s$, i, 1))
tot = tot + d * d * d
Next
socd = tot
End Function
|
Posted by Charlie
on 2016-05-29 11:22:38 |