Arrange integers 1- 15 in a triangle such that the upper row consists of 5 integers, all other rows represent each the absolute values of the differences between the adjacent members of the row above so that the 5th row contains one number only.
A bad example:
4 7 15 10 2
3 12 5 8
9 7 * oops! Can't use 3 again.
Just wanted to explain the build-up..
Better luck to the solvers!
The two mirror-image solutions are:
6 14 15 3 13
8 1 12 10
7 11 2
4 9
5
13 3 15 14 6
10 12 1 8
2 11 7
9 4
5
DefDbl A-Z
Dim crlf$, grid(5, 5), used(15)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
addOn 1, 1
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub addOn(row, col)
If row = 1 Then
For i = 1 To 15
If used(i) = 0 Then
grid(row, col) = i
used(i) = 1
r = row: c = col + 1
If c > 5 Then r = r + 1: c = 1
addOn r, c
used(i) = 0
End If
Next
Else
diff = Abs(grid(row - 1, col) - grid(row - 1, col + 1))
If used(diff) = 0 Then
grid(row, col) = diff
used(diff) = 1
r = row: c = col + 1
If c > 6 - row Then r = r + 1: c = 1
If r < 6 Then
addOn r, c
Else
For r = 1 To 5
For c = 1 To 6 - r
Text1.Text = Text1.Text & Str(grid(r, c))
Next c
Text1.Text = Text1.Text & crlf
Next r
Text1.Text = Text1.Text & crlf
End If
used(diff) = 0
End If
End If
End Sub
|
Posted by Charlie
on 2016-02-02 15:37:44 |