The program:
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
st = Int(100000 / 143) * 143
Text1.Text = Text1.Text & st & crlf
n = st
Do
n = n + 143
ns$ = LTrim(Str(n))
lowest = 999
highest = -1
For i = 1 To Len(ns)
If Val(Mid(ns, i, 1)) < lowest Then lowest = Val(Mid(ns, i, 1))
If Val(Mid(ns, i, 1)) > highest Then highest = Val(Mid(ns, i, 1))
Next
If highest - lowest = 5 Then ct = ct + 1: lastmemb = n
Loop Until n > 999999
Text1.Text = Text1.Text & ct & Str(lastmemb) & " done"
DoEvents
End Sub
has output:
99957
542 997854 done
meaning
99957 is the last multiple of 143 that's less than 6 digits.
542 is the sought cardinality.
997854 is the last multiple of 143 that meets the other criteria.
The subsets were chosen in reverse order to make the search more efficient: only multiples of 143 were tested; the starting point was arrived at by division, so as few numbers as possible were tested to see if the middle criterion was true, concerning the difference between highest and lowest digits.
|
Posted by Charlie
on 2020-07-06 10:15:25 |