Find the total count of numbers from 1 (base ten) to 20150 (base ten) which have at least one 0 and more 1s than 0s when written in base 4.
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For n = 1 To 20150
b4$ = base$(n, 4)
ct1 = 0: ct0 = 0
For i = 1 To Len(b4)
Select Case Mid(b4, i, 1)
Case 1: ct1 = ct1 + 1
Case 0: ct0 = ct0 + 1
End Select
Next
If ct1 > ct0 And ct0 > 0 Then goodct = goodct + 1
If ct1 > ct0 And ct0 = 0 Then suppct = suppct + 1
Next n
Text1.Text = Text1.Text & goodct & Str(suppct) & crlf & " done"
End Sub
Function base$(n, b)
v$ = ""
n2 = n
Do
d = n2 Mod b
n2 = n2 \ b
v$ = LTrim(Str(d)) + v$
Loop Until n2 = 0
base$ = v$
End Function
finds that 5997 numbers meet the criterion.
An additional 3025 would meet it if numbers with no zeros were allowed also.
|
Posted by Charlie
on 2015-10-21 15:27:42 |