Art, the mail carrier delivers mail to the 19 houses on the east side of a street.
Art notices that:
(i) No two adjacent houses ever get mail on the same day, and:
(ii) There are never more than two houses in a row that get no mail on the same day.
How many distinct patterns of mail delivery are possible?
After listing all the possibilities
DefDbl A-Z
Dim crlf$, h(19), ct
Private Sub Form_Load()
ChDir "C:\Program Files (x86)\DevStudio\VB\projects\flooble"
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
addOn 1
Text1.Text = Text1.Text & ct & crlf & " done"
End Sub
Sub addOn(wh)
For i = 0 To 1
good = 1
h(wh) = i
If h(wh) = 1 And h(wh - 1) = 1 Then good = 0
If wh > 2 Then
If h(wh) + h(wh - 1) + h(wh - 2) = 0 Then good = 0
End If
If good Then
If wh = 19 Then
ct = ct + 1
For j = 1 To 19
Text1.Text = Text1.Text & Str(h(j))
DoEvents
Next
Text1.Text = Text1.Text & crlf
DoEvents
Else
addOn wh + 1
End If
End If
Next i
End Sub
|
Posted by Charlie
on 2014-09-04 17:33:37 |