There are 178,811 solutions. The lowest is
1023458769 or binary 111101000000001011110111010001
and the highest is
9876530214 or binary 1001001100101011111110010000100110
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
Open "decimal and binary representation.txt" For Output As #2
s$ = "1234567890": h$ = s
Do
If Left(s, 1) > "0" Then
n = Val(s)
b$ = ""
ct0 = 0: ct1 = 0
Do
DoEvents
q = Int(n / 2): bindig = n - q * 2
bd$ = LTrim(Str(bindig))
n = q
b = bd$ + b
If bd = "1" Then ct1 = ct1 + 1 Else ct0 = ct0 + 1
Loop Until n = 0
If ct1 = ct0 Then
Text1.Text = Text1.Text & s & " " & b & crlf
Print #2, s & " " & b
End If
End If
DoEvents
permute s
Loop Until s = h
Close 2
Text1.Text = Text1.Text & crlf & " done"
End Sub
|
Posted by Charlie
on 2016-12-14 10:23:49 |