' Constructs Prime Number Magic Squares of order 10
' Tested with Office 2007 under Windows 7
Sub CnstrSqrs10b()
Dim a2(10), b2(100), a(100), b(100), c(100)
y = MsgBox("Locked", vbExclamation, "Routine CnstrSqrs10b")
End
n2 = 0: n9 = 0: k1 = 1: k2 = 1
Sheets("Klad1").Select
t1 = Timer
For j1 = 2 To 9
' Read (Balanced) Magic Lines
For j2 = 1 To 10: a2(j2) = Sheets("Att103").Cells(j1, j2).Value: Next j2
For j2 = 1 To 10: b2(j2) = Sheets("Att103").Cells(j1, j2 + 11).Value: Next j2
s1 = Sheets("Att103").Cells(j1, 23).Value
' Construct squares a() and b()
GoSub 200
' Calculate Square c()
For j2 = 1 To 100
c(j2) = a(j2) + b(j2)
Next j2
' Print results
GoSub 800: If fl1 = 0 Then GoTo 70
' n9 = n9 + 1: GoSub 640 'Lines
n9 = n9 + 1: GoSub 650 'Squares
70 Next j1
t2 = Timer
t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s1)
y = MsgBox(t10, vbInformation, "Routine CnstrSqrs10b")
End
' Construct squares a() and b()
200
' Simple Magic
a(1) = a2(1): a(2) = a2(2): a(3) = a2(3): a(4) = a2(4): a(5) = a2(5):
a(6) = a2(6): a(7) = a2(7): a(8) = a2(8): a(9) = a2(9): a(10) = a2(10):
a(11) = a2(2): a(12) = a2(7): a(13) = a2(10): a(14) = a2(8): a(15) = a2(1):
a(16) = a2(3): a(17) = a2(9): a(18) = a2(5): a(19) = a2(4): a(20) = a2(6):
a(21) = a2(4): a(22) = a2(1): a(23) = a2(2): a(24) = a2(7): a(25) = a2(8):
a(26) = a2(5): a(27) = a2(10): a(28) = a2(9): a(29) = a2(6): a(30) = a2(3):
a(31) = a2(3): a(32) = a2(8): a(33) = a2(4): a(34) = a2(6): a(35) = a2(9):
a(36) = a2(2): a(37) = a2(1): a(38) = a2(10): a(39) = a2(5): a(40) = a2(7):
a(41) = a2(9): a(42) = a2(5): a(43) = a2(1): a(44) = a2(2): a(45) = a2(10):
a(46) = a2(7): a(47) = a2(4): a(48) = a2(6): a(49) = a2(3): a(50) = a2(8):
a(51) = a2(6): a(52) = a2(3): a(53) = a2(5): a(54) = a2(10): a(55) = a2(2):
a(56) = a2(9): a(57) = a2(8): a(58) = a2(4): a(59) = a2(7): a(60) = a2(1):
a(61) = a2(8): a(62) = a2(4): a(63) = a2(7): a(64) = a2(3): a(65) = a2(6):
a(66) = a2(10): a(67) = a2(5): a(68) = a2(2): a(69) = a2(1): a(70) = a2(9):
a(71) = a2(7): a(72) = a2(10): a(73) = a2(8): a(74) = a2(9): a(75) = a2(4):
a(76) = a2(1): a(77) = a2(6): a(78) = a2(3): a(79) = a2(2): a(80) = a2(5):
a(81) = a2(10): a(82) = a2(6): a(83) = a2(9): a(84) = a2(5): a(85) = a2(7):
a(86) = a2(4): a(87) = a2(3): a(88) = a2(1): a(89) = a2(8): a(90) = a2(2):
a(91) = a2(5): a(92) = a2(9): a(93) = a2(6): a(94) = a2(1): a(95) = a2(3):
a(96) = a2(8): a(97) = a2(2): a(98) = a2(7): a(99) = a2(10): a(100) = a2(4):
b(1) = b2(1): b(2) = b2(2): b(3) = b2(3): b(4) = b2(4): b(5) = b2(5):
b(6) = b2(6): b(7) = b2(7): b(8) = b2(8): b(9) = b2(9): b(10) = b2(10):
b(11) = b2(9): b(12) = b2(8): b(13) = b2(7): b(14) = b2(6): b(15) = b2(10):
b(16) = b2(1): b(17) = b2(5): b(18) = b2(4): b(19) = b2(3): b(20) = b2(2):
b(21) = b2(2): b(22) = b2(3): b(23) = b2(4): b(24) = b2(5): b(25) = b2(1):
b(26) = b2(10): b(27) = b2(6): b(28) = b2(7): b(29) = b2(8): b(30) = b2(9):
b(31) = b2(10): b(32) = b2(9): b(33) = b2(8): b(34) = b2(7): b(35) = b2(6):
b(36) = b2(5): b(37) = b2(4): b(38) = b2(3): b(39) = b2(2): b(40) = b2(1):
b(41) = b2(8): b(42) = b2(7): b(43) = b2(6): b(44) = b2(10): b(45) = b2(2):
b(46) = b2(9): b(47) = b2(1): b(48) = b2(5): b(49) = b2(4): b(50) = b2(3):
b(51) = b2(4): b(52) = b2(5): b(53) = b2(1): b(54) = b2(9): b(55) = b2(8):
b(56) = b2(3): b(57) = b2(2): b(58) = b2(10): b(59) = b2(6): b(60) = b2(7):
b(61) = b2(7): b(62) = b2(6): b(63) = b2(10): b(64) = b2(2): b(65) = b2(3):
b(66) = b2(8): b(67) = b2(9): b(68) = b2(1): b(69) = b2(5): b(70) = b2(4):
b(71) = b2(3): b(72) = b2(4): b(73) = b2(5): b(74) = b2(1): b(75) = b2(9):
b(76) = b2(2): b(77) = b2(10): b(78) = b2(6): b(79) = b2(7): b(80) = b2(8):
b(81) = b2(5): b(82) = b2(1): b(83) = b2(2): b(84) = b2(3): b(85) = b2(4):
b(86) = b2(7): b(87) = b2(8): b(88) = b2(9): b(89) = b2(10): b(90) = b2(6):
b(91) = b2(6): b(92) = b2(10): b(93) = b2(9): b(94) = b2(8): b(95) = b2(7):
b(96) = b2(4): b(97) = b2(3): b(98) = b2(2): b(99) = b2(1): b(100) = b2(5):
Return
' Exclude solutions with identical numbers
800 fl1 = 1
For j10 = 1 To 100
c2 = c(j10)
For j20 = (1 + j10) To 100
If c2 = c(j20) Then fl1 = 0: Return
Next j20
Next j10
Return
' Print results (selected numbers)
640 Cells(n9, 101).Select
For i1 = 1 To 100
Cells(n9, i1).Value = c(i1)
Next i1
Cells(n9, 101).Value = n9
Return
' Print results (squares)
650 n1 = n1 + 1
If n1 = 3 Then
n1 = 1: k1 = k1 + 11: k2 = 1
Else
If n9 > 1 Then k2 = k2 + 11
End If
Cells(k1, k2 + 1).Select
Cells(k1, k2 + 1).Font.Color = -4165632
Cells(k1, k2 + 1).Value = s1
i3 = 0
For i1 = 1 To 10
For i2 = 1 To 10
i3 = i3 + 1
Cells(k1 + i1, k2 + i2).Value = c(i3)
Next i2
Next i1
Return
End Sub