Using each of the digits 1, 2, 3, and 4 twice, write out an eight-digit number in which there is one digit between the 1s, two digits between the 2s,
three digits between the 3s, and four digits between the 4s.
Credit: A. Savin
23421314
41312432
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
s$ = "11223344"
h$ = s
Do
ix1 = InStr(s, "4")
ix2 = InStr(ix1 + 1, s, "4")
If ix2 = ix1 + 5 Then
ix1 = InStr(s, "3")
ix2 = InStr(ix1 + 1, s, "3")
If ix2 = ix1 + 4 Then
ix1 = InStr(s, "2")
ix2 = InStr(ix1 + 1, s, "2")
If ix2 = ix1 + 3 Then
ix1 = InStr(s, "1")
ix2 = InStr(ix1 + 1, s, "1")
If ix2 = ix1 + 2 Then
Text1.Text = Text1.Text & s & crlf
End If
End If
End If
End If
permute s
Loop Until s = h
Text1.Text = Text1.Text & crlf & " done"
End Sub
|
Posted by Charlie
on 2015-08-26 11:17:03 |