The following program tests matrices from 2x2 to 8x8. It finds the 2x2 (not included in the puzzle) has determinant 1, but the ones included in the puzzle (n>4) all have determinant zero.
The determinant evaluation routine was swiped from an old puzzle solution program I had written. Hopefully it wasn't assuming anything about the matrices whose determinants were being evaluated; the determinants for the 3x3 and 4x4 cases were verified as zero by a TI-84 plus CE calculator, which has a built-in determinant function.
DefDbl A-Z
Dim crlf$, fib(100)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr(13) + Chr(10)
maxsize = 10
a = 1: b = 1
fib(1) = a: fib(2) = b
For nxt = 3 To 100
fib(nxt) = fib(nxt - 2) + fib(nxt - 1)
Text1.Text = Text1.Text & Str(fib(nxt))
Next
For sz = 1 To 8
ReDim triangle(sz, sz)
For row = 1 To sz
For col = 1 To sz
triangle(row, col) = fib((row - 1) * sz + col)
Next
Next
Text1.Text = Text1.Text & sz & Str(det(sz, triangle())) & crlf
DoEvents
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Function det(sz, triangle())
If sz = 2 Then
xx = xx
End If
If sz = 1 Then
det = triangle(1, 1)
Exit Function
End If
ReDim matrix(sz - 1, sz - 1)
tot = 0
For col = 1 To sz
newrow = 0
For r = 2 To sz
newrow = newrow + 1
newcol = 0
For c = 1 To sz
If c <> col Then
newcol = newcol + 1
matrix(newrow, newcol) = triangle(r, c)
End If
Next
Next r
term = triangle(1, col) * det(sz - 1, matrix())
If col Mod 2 = 0 Then term = -term
tot = tot + term
Next col
det = tot
End Function
|
Posted by Charlie
on 2019-04-08 16:41:42 |