' Combines Quaternary Magic Squares into Magic Squares
' Tested with Office 2007 under Windows 7
Sub CnstrSqrs8c()
Dim b(3, 125), a(125)
Sheets("Klad1").Select
y = MsgBox("Locked", vbCritical, "Routine CnstrSqrs8c")
End
n4 = 304: ShtNm8 = "Test4"
' n4 = 3072: ShtNm8 = "Test5"
n2 = 0: n9 = 22656: k1 = 1: k2 = 1
s1 = 260
t1 = Timer
For j1 = 148 To n4
Cells(n9 + 1, 65).Select: Cells(n9 + 1, 65).Value = j1
For j2 = 1 To n4
If j2 = j1 Then GoTo 20
Cells(n9 + 1, 66).Select: Cells(n9 + 1, 66).Value = j2
For j3 = 1 To n4
If j3 = j2 Or j3 = j1 Then GoTo 30
j10 = j1: j20 = 1: GoSub 100 'Read Quaternary Magic Square 1
j10 = j2: j20 = 2: GoSub 100 'Read Quaternary Magic Square 2
j10 = j3: j20 = 3: GoSub 100 'Read Quaternary Magic Square 3
For j4 = 1 To 64
a(j4) = b(1, j4) + 4 * b(2, j4) + 16 * b(3, j4) + 1
Next j4
GoSub 300: If fl1 = 0 Then GoTo 30 'Ckeck identical numbers
n9 = n9 + 1: GoSub 740 'Print results (selected numbers)
' n9 = n9 + 1: GoSub 750 'Print results (squares)
30 Next j3
20 Next j2
Next j1
t2 = Timer
t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s1)
y = MsgBox(t10, 0, "Routine CnstrSqrs8c")
End
' Read Quaternary Magic Squares (line format)
100
For i1 = 1 To 64
b(j20, i1) = Sheets(ShtNm8).Cells(j10, i1).Value
Next i1
Return
' Check identical numbers
300 fl1 = 1
For i1 = 1 To 64
a2 = a(i1)
For i2 = (1 + i1) To 64
If a2 = a(i2) Then fl1 = 0: Return
Next i2
Next i1
Return
' Print results (selected numbers)
740 For i1 = 1 To 64
Cells(n9, i1).Value = a(i1)
Next i1
Cells(n9, 65).Value = j1
Cells(n9, 66).Value = j2
Cells(n9, 67).Value = j3
Return
' Print results (squares)
750 n2 = n2 + 1
If n2 = 5 Then
n2 = 1: k1 = k1 + 9: k2 = 1
Else
If n9 > 1 Then k2 = k2 + 9
End If
Cells(k1, k2 + 1).Select
Cells(k1, k2 + 1).Font.Color = -4165632
Cells(k1, k2 + 1).Value = CStr(n9)
i3 = 0
For i1 = 1 To 8
For i2 = 1 To 8
i3 = i3 + 1
Cells(k1 + i1, k2 + i2).Value = a(i3)
Next i2
Next i1
Return
End Sub