Break up an integer into all possible groups without changing the order in which the digits are arranged, then multiply each set of groups out and sum the products.
Example: 326. 3x2x6, + 32x6, + 3x26 gives 36 + 192 + 78 = 306. If the result equals the original integer, it's an Ellis number.
How many Ellis numbers are there in the integers up to 10,000?
Sometimes the process leads to an integer which isn't an Ellis number but which, when subjected to the same process, leads back to the original number, and is thus a sort of cyclic Ellis number. Find all cyclic Ellis numbers less than 10,000.
Dim crlf$, ns As String, sepsplaced, prevsep, stot, prod
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
Text1.Text = Text1.Text & ellis(326) & crlf & crlf & crlf & crlf
For n = 1 To 10000
If ellis(n) = n Then
Text1.Text = Text1.Text & n & crlf
ct = ct + 1
ElseIf ellis(ellis(n)) = n Then
Text1.Text = Text1.Text & n & Str(ellis(n)) & crlf
ct2 = ct2 + 1
Text1.Text = Text1.Text & "counts: " & ct & Str(ct2) & crlf
ns = LTrim(Str(x))
tot = 0
For pieces = 2 To Len(ns)
sepsplaced = 0: prevsep = 0: prod = 1: stot = 0
tot = tot + stot
ellis = tot
For newsep = prevsep + 1 To Len(ns) - (pieces - 1 - sepsplaced)
v = Val(Mid(ns, prevsep + 1, newsep - prevsep))
saveprod = prod
prod = prod * v
sepsplaced = sepsplaced + 1
saveprevsep = prevsep
prevsep = newsep
If sepsplaced = pieces - 1 Then
prod = prod * Val(Mid(ns, newsep + 1))
stot = stot + prod
sepsplaced = sepsplaced - 1
prevsep = saveprevsep
prod = saveprod
first evaluates 326, to test its own calculations, and correctly finds 306:
Then it finds 3 Ellis numbers under 10,000, as well as 4 that fit the given definition of "a sort of cyclic Ellis number":
counts: 3 Ellis, 4 cyclic, in 2 cycles(pairs).
The mutual numbers are shown paired on their lines, and the Ellis numbers get a line of their own and are bolded.
Extended to a million, there seems to be a pattern:
The 7305 joined the sequence a power of 10 multiple later than 155. Could there be other beginnings that join?
Posted by Charlie
on 2015-01-31 14:53:59