Let S be a set of all sixdigit integers.
Let S1 be a subset of S, including all members of S such that each consists
of distinct digits.
Let S2 be a subset of S1, including all members of S1 each with 5 being the difference between its largest digit and its lowest one.
Let S3 be a subset of S2, comprising all elements of S2 divisible by 143.
What is the cardinality of S3 ?
Explain your way of reasoning.
The program:
DefDbl AZ
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 20200706 10:15:25 