Determine the total number of values of a positive integer N having at most four digits such that:
(i) The digit 1 occurs an odd number of times in N, and:
(ii) Each of the digits 2, 0 and 6 occurs an even number of times in N. (An even number includes zero), and:
(iii ) Any of the remaining six digits may or may not occur in N.
The program below has a bug leading to this erroneous answer: (see later comments)
763 values of N
from
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For n = 1 To 9999
ns$ = LTrim(Str(n))
For i = 1 To Len(ns)
Select Case Mid(ns, i, 1)
Case 0: ct0 = ct0 + 1
Case 1: ct1 = ct1 + 1
Case 2: ct2 = ct2 + 1
Case 6: ct6 = ct6 + 1
End Select
Next
If ct1 Mod 2 = 1 Then
If ct0 Mod 2 = 0 Then
If ct2 Mod 2 = 0 Then
If ct6 Mod 2 = 0 Then
hitct = hitct + 1
End If
End If
End If
End If
Next
Text1.Text = Text1.Text & crlf & hitct & " done"
End Sub
Edited on April 5, 2016, 10:28 pm
|
Posted by Charlie
on 2016-04-04 19:14:42 |