' Constructs Prime Number Magic Squares of order 11
' Tested with Office 2007 under Windows 7
Sub CnstrSqrs11b()
Dim a2(11), b2(121), a(121), b(121), c(121)
y = MsgBox("Locked", vbExclamation, "Routine CnstrSqrs11b")
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 11: a2(j2) = Sheets("Att103").Cells(j1, j2).Value: Next j2
For j2 = 1 To 11: b2(j2) = Sheets("Att103").Cells(j1, j2 + 12).Value: Next j2
s1 = Sheets("Att103").Cells(j1, 25).Value
' Construct squares a() and b()
GoSub 200
' Calculate Square c()
For j2 = 1 To 121
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 CnstrSqrs11b")
End
' Construct squares a() and b()
200
' Pan Magic
a(1) = a2(1): a(2) = a2(11): a(3) = a2(2): a(4) = a2(3): a(5) = a2(4): a(6) = a2(5):
a(7) = a2(6): a(8) = a2(7): a(9) = a2(8): a(10) = a2(9): a(11) = a2(10):
a(12) = a2(9): a(13) = a2(10): a(14) = a2(1): a(15) = a2(11): a(16) = a2(2): a(17) = a2(3):
a(18) = a2(4): a(19) = a2(5): a(20) = a2(6): a(21) = a2(7): a(22) = a2(8):
a(23) = a2(7): a(24) = a2(8): a(25) = a2(9): a(26) = a2(10): a(27) = a2(1): a(28) = a2(11):
a(29) = a2(2): a(30) = a2(3): a(31) = a2(4): a(32) = a2(5): a(33) = a2(6):
a(34) = a2(5): a(35) = a2(6): a(36) = a2(7): a(37) = a2(8): a(38) = a2(9): a(39) = a2(10):
a(40) = a2(1): a(41) = a2(11): a(42) = a2(2): a(43) = a2(3): a(44) = a2(4):
a(45) = a2(3): a(46) = a2(4): a(47) = a2(5): a(48) = a2(6): a(49) = a2(7): a(50) = a2(8):
a(51) = a2(9): a(52) = a2(10): a(53) = a2(1): a(54) = a2(11): a(55) = a2(2):
a(56) = a2(11): a(57) = a2(2): a(58) = a2(3): a(59) = a2(4): a(60) = a2(5): a(61) = a2(6):
a(62) = a2(7): a(63) = a2(8): a(64) = a2(9): a(65) = a2(10): a(66) = a2(1):
a(67) = a2(10): a(68) = a2(1): a(69) = a2(11): a(70) = a2(2): a(71) = a2(3): a(72) = a2(4):
a(73) = a2(5): a(74) = a2(6): a(75) = a2(7): a(76) = a2(8): a(77) = a2(9):
a(78) = a2(8): a(79) = a2(9): a(80) = a2(10): a(81) = a2(1): a(82) = a2(11): a(83) = a2(2):
a(84) = a2(3): a(85) = a2(4): a(86) = a2(5): a(87) = a2(6): a(88) = a2(7):
a(89) = a2(6): a(90) = a2(7): a(91) = a2(8): a(92) = a2(9): a(93) = a2(10): a(94) = a2(1):
a(95) = a2(11): a(96) = a2(2): a(97) = a2(3): a(98) = a2(4): a(99) = a2(5):
a(100) = a2(4): a(101) = a2(5): a(102) = a2(6): a(103) = a2(7): a(104) = a2(8): a(105) = a2(9):
a(106) = a2(10): a(107) = a2(1): a(108) = a2(11): a(109) = a2(2): a(110) = a2(3):
a(111) = a2(2): a(112) = a2(3): a(113) = a2(4): a(114) = a2(5): a(115) = a2(6): a(116) = a2(7):
a(117) = a2(8): a(118) = a2(9): a(119) = a2(10): a(120) = a2(1): a(121) = a2(11):
b(1) = b2(1): b(2) = b2(9): b(3) = b2(7): b(4) = b2(5): b(5) = b2(3): b(6) = b2(11):
b(7) = b2(10): b(8) = b2(8): b(9) = b2(6): b(10) = b2(4): b(11) = b2(2):
b(12) = b2(11): b(13) = b2(10): b(14) = b2(8): b(15) = b2(6): b(16) = b2(4): b(17) = b2(2):
b(18) = b2(1): b(19) = b2(9): b(20) = b2(7): b(21) = b2(5): b(22) = b2(3):
b(23) = b2(2): b(24) = b2(1): b(25) = b2(9): b(26) = b2(7): b(27) = b2(5): b(28) = b2(3):
b(29) = b2(11): b(30) = b2(10): b(31) = b2(8): b(32) = b2(6): b(33) = b2(4):
b(34) = b2(3): b(35) = b2(11): b(36) = b2(10): b(37) = b2(8): b(38) = b2(6): b(39) = b2(4):
b(40) = b2(2): b(41) = b2(1): b(42) = b2(9): b(43) = b2(7): b(44) = b2(5):
b(45) = b2(4): b(46) = b2(2): b(47) = b2(1): b(48) = b2(9): b(49) = b2(7): b(50) = b2(5):
b(51) = b2(3): b(52) = b2(11): b(53) = b2(10): b(54) = b2(8): b(55) = b2(6):
b(56) = b2(5): b(57) = b2(3): b(58) = b2(11): b(59) = b2(10): b(60) = b2(8): b(61) = b2(6):
b(62) = b2(4): b(63) = b2(2): b(64) = b2(1): b(65) = b2(9): b(66) = b2(7):
b(67) = b2(6): b(68) = b2(4): b(69) = b2(2): b(70) = b2(1): b(71) = b2(9): b(72) = b2(7):
b(73) = b2(5): b(74) = b2(3): b(75) = b2(11): b(76) = b2(10): b(77) = b2(8):
b(78) = b2(7): b(79) = b2(5): b(80) = b2(3): b(81) = b2(11): b(82) = b2(10): b(83) = b2(8):
b(84) = b2(6): b(85) = b2(4): b(86) = b2(2): b(87) = b2(1): b(88) = b2(9):
b(89) = b2(8): b(90) = b2(6): b(91) = b2(4): b(92) = b2(2): b(93) = b2(1): b(94) = b2(9):
b(95) = b2(7): b(96) = b2(5): b(97) = b2(3): b(98) = b2(11): b(99) = b2(10):
b(100) = b2(9): b(101) = b2(7): b(102) = b2(5): b(103) = b2(3): b(104) = b2(11): b(105) = b2(10):
b(106) = b2(8): b(107) = b2(6): b(108) = b2(4): b(109) = b2(2): b(110) = b2(1):
b(111) = b2(10): b(112) = b2(8): b(113) = b2(6): b(114) = b2(4): b(115) = b2(2): b(116) = b2(1):
b(117) = b2(9): b(118) = b2(7): b(119) = b2(5): b(120) = b2(3): b(121) = b2(11):
Return
' Exclude solutions with identical numbers
800 fl1 = 1
For j10 = 1 To 121
c2 = c(j10)
For j20 = (1 + j10) To 121
If c2 = c(j20) Then fl1 = 0: Return
Next j20
Next j10
Return
' Print results (selected numbers)
640 Cells(n9, 122).Select
For i1 = 1 To 121
Cells(n9, i1).Value = c(i1)
Next i1
Cells(n9, 122).Value = n9
Return
' Print results (squares)
650 n1 = n1 + 1
If n1 = 3 Then
n1 = 1: k1 = k1 + 12: k2 = 1
Else
If n9 > 1 Then k2 = k2 + 12
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 11
For i2 = 1 To 11
i3 = i3 + 1
Cells(k1 + i1, k2 + i2).Value = c(i3)
Next i2
Next i1
Return
End Sub