' Generates Bordered Magic Cubes of order 7 (Prime Numbers)
' Part III: Anti Symmetric Magic Left Squares (e)
' Tested with Office 365 under Windows 10
Sub PrimeCubes71e()
Dim a1(724), a(100), b1(43291), b(43291), c(100), c7(343)
y = MsgBox("Locked", vbCritical, "Routine PrimeCubes71e")
End
n2 = 0: n9 = 0: k1 = 1: k2 = 1
ShtNm1 = "Pairs77"
ShtNm2 = "TopSqrs7"
ShtNm3 = "BackSqrs7"
Sheets("Klad1").Select
t1 = Timer
For j100 = 181 To 181 ''175 To 175
''Cells(k1, 1).Select: Cells(k1, 1).Value = j100
' Start Reading Data ShtNm2/ShtNm3
Rcrd1a = Sheets(ShtNm2).Cells(j100, 51).Value
MC7 = Sheets(ShtNm2).Cells(j100, 50).Value
Rcrd1b = Sheets(ShtNm3).Cells(j100, 51).Value
If Rcrd1a <> Rcrd1b Then
y = MsgBox("Conflicting Data", vbCritical, "Check Input: " + CStr(j100))
End
End If
' Read Available Prime Numbers From Sheet ShtNm1
' Reduce with ShtNm1 and ShtNm2, fill Cube c7()
GoSub 2015
' Fill Scratch Arae
Erase a
a(1) = c7(1): a(2) = c7(8): a(3) = c7(15): a(4) = c7(22): a(5) = c7(29): a(6) = c7(36): a(7) = c7(43):
a(8) = c7(50): a(14) = c7(92):
a(15) = c7(99): a(21) = c7(141):
a(22) = c7(148): a(28) = c7(190):
a(29) = c7(197): a(35) = c7(239):
a(36) = c7(246): a(42) = c7(288):
a(43) = c7(295): a(44) = c7(302): a(45) = c7(309): a(46) = c7(316): a(47) = c7(323): a(48) = c7(330): a(49) = c7(337):
b(Cntr7) = Cntr7 'Block Center Element
For j41 = (m2 - 1) / 2 To m1 Step -1 'a(41)
If b1(a1(j41)) = 0 Then GoTo 410
If b(a1(j41)) = 0 Then b(a1(j41)) = a1(j41): c(41) = a1(j41) Else GoTo 410
a(41) = a1(j41)
a(91) = Pr7 - a(41): If b(a(91)) = 0 Then b(a(91)) = a(91): c(91) = a(91) Else GoTo 910
For j33 = m1 To m2 'a(33)
If b1(a1(j33)) = 0 Then GoTo 330
If b(a1(j33)) = 0 Then b(a1(j33)) = a1(j33): c(33) = a1(j33) Else GoTo 330
a(33) = a1(j33)
a(83) = Pr7 - a(33): If b(a(83)) = 0 Then b(a(83)) = a(83): c(83) = a(83) Else GoTo 830
For j25 = m1 To m2 'a(25)
If b1(a1(j25)) = 0 Then GoTo 250
If b(a1(j25)) = 0 Then b(a1(j25)) = a1(j25): c(25) = a1(j25) Else GoTo 250
a(25) = a1(j25)
a(75) = Pr7 - a(25): If b(a(75)) = 0 Then b(a(75)) = a(75): c(75) = a(75) Else GoTo 750
For j17 = m1 To m2 'a(17)
If b1(a1(j17)) = 0 Then GoTo 170
If b(a1(j17)) = 0 Then b(a1(j17)) = a1(j17): c(17) = a1(j17) Else GoTo 170
a(17) = a1(j17)
a(67) = Pr7 - a(17): If b(a(67)) = 0 Then b(a(67)) = a(67): c(67) = a(67) Else GoTo 670
a(9) = s7 - a(17) - a(25) - a(33) - a(41) - a(1) - a(49)
If a(9) < a1(m1) Or a(9) > a1(m2) Then GoTo 90
If b1(a(9)) = 0 Then GoTo 90
If b(a(9)) = 0 Then b(a(9)) = a(9): c(9) = a(9) Else GoTo 90
a(59) = Pr7 - a(9): If b(a(59)) = 0 Then b(a(59)) = a(59): c(59) = a(59) Else GoTo 590
For j37 = m1 To m2 'a(37)
If b1(a1(j37)) = 0 Then GoTo 370
If b(a1(j37)) = 0 Then b(a1(j37)) = a1(j37): c(37) = a1(j37) Else GoTo 370
a(37) = a1(j37)
a(87) = Pr7 - a(37): If b(a(87)) = 0 Then b(a(87)) = a(87): c(87) = a(87) Else GoTo 870
For j31 = m1 To m2 'a(31)
If b1(a1(j31)) = 0 Then GoTo 310
If b(a1(j31)) = 0 Then b(a1(j31)) = a1(j31): c(31) = a1(j31) Else GoTo 310
a(31) = a1(j31)
a(81) = Pr7 - a(31): If b(a(81)) = 0 Then b(a(81)) = a(81): c(81) = a(81) Else GoTo 810
For j19 = m1 To m2 'a(19)
If b1(a1(j19)) = 0 Then GoTo 190
If b(a1(j19)) = 0 Then b(a1(j19)) = a1(j19): c(19) = a1(j19) Else GoTo 190
a(19) = a1(j19)
a(69) = Pr7 - a(19): If b(a(69)) = 0 Then b(a(69)) = a(69): c(69) = a(69) Else GoTo 690
a(13) = s7 - a(19) - a(25) - a(31) - a(37) - a(7) - a(43)
If a(13) < a1(m1) Or a(13) > a1(m2) Then GoTo 130
If b1(a(13)) = 0 Then GoTo 130
If b(a(13)) = 0 Then b(a(13)) = a(13): c(13) = a(13) Else GoTo 130
a(63) = Pr7 - a(13): If b(a(63)) = 0 Then b(a(63)) = a(63): c(63) = a(63) Else GoTo 630
For j20 = m1 To m2 'a(20)
If b1(a1(j20)) = 0 Then GoTo 200
If b(a1(j20)) = 0 Then b(a1(j20)) = a1(j20): c(20) = a1(j20) Else GoTo 200
a(20) = a1(j20)
a(70) = Pr7 - a(20): If b(a(70)) = 0 Then b(a(70)) = a(70): c(70) = a(70) Else GoTo 700
For j18 = m1 To m2 'a(18)
If b1(a1(j18)) = 0 Then GoTo 180
If b(a1(j18)) = 0 Then b(a1(j18)) = a1(j18): c(18) = a1(j18) Else GoTo 180
a(18) = a1(j18)
a(68) = Pr7 - a(18): If b(a(68)) = 0 Then b(a(68)) = a(68): c(68) = a(68) Else GoTo 680
a(16) = s7 - a(17) - a(18) - a(19) - a(20) - a(15) - a(21)
If a(16) < a1(m1) Or a(16) > a1(m2) Then GoTo 160
If b1(a(16)) = 0 Then GoTo 160
If b(a(16)) = 0 Then b(a(16)) = a(16): c(16) = a(16) Else GoTo 160
a(66) = Pr7 - a(16): If b(a(66)) = 0 Then b(a(66)) = a(66): c(66) = a(66) Else GoTo 660
For j23 = m1 To m2 'a(23)
If b1(a1(j23)) = 0 Then GoTo 230
If b(a1(j23)) = 0 Then b(a1(j23)) = a1(j23): c(23) = a1(j23) Else GoTo 230
a(23) = a1(j23)
a(73) = Pr7 - a(23): If b(a(73)) = 0 Then b(a(73)) = a(73): c(73) = a(73) Else GoTo 730
a(30) = s7 - a(9) - a(16) - a(23) - a(37) - a(2) - a(44)
If a(30) < a1(m1) Or a(30) > a1(m2) Then GoTo 300
If b1(a(30)) = 0 Then GoTo 300
If b(a(30)) = 0 Then b(a(30)) = a(30): c(30) = a(30) Else GoTo 300
a(80) = Pr7 - a(30): If b(a(80)) = 0 Then b(a(80)) = a(80): c(80) = a(80) Else GoTo 800
For j27 = m1 To m2 'a(27)
If b1(a1(j27)) = 0 Then GoTo 270
If b(a1(j27)) = 0 Then b(a1(j27)) = a1(j27): c(27) = a1(j27) Else GoTo 270
a(27) = a1(j27)
a(77) = Pr7 - a(27): If b(a(77)) = 0 Then b(a(77)) = a(77): c(77) = a(77) Else GoTo 770
a(34) = s7 - a(41) - a(27) - a(20) - a(13) - a(6) - a(48)
If a(34) < a1(m1) Or a(34) > a1(m2) Then GoTo 340
If b1(a(34)) = 0 Then GoTo 340
If b(a(34)) = 0 Then b(a(34)) = a(34): c(34) = a(34) Else GoTo 340
a(84) = Pr7 - a(34): If b(a(84)) = 0 Then b(a(84)) = a(84): c(84) = a(84) Else GoTo 840
a(32) = s7 - a(30) - a(31) - a(33) - a(34) - a(29) - a(35)
If a(32) < a1(m1) Or a(32) > a1(m2) Then GoTo 320
If b1(a(32)) = 0 Then GoTo 320
If b(a(32)) = 0 Then b(a(32)) = a(32): c(32) = a(32) Else GoTo 320
a(82) = Pr7 - a(32): If b(a(82)) = 0 Then b(a(82)) = a(82): c(82) = a(82) Else GoTo 820
For j26 = m1 To m2 'a(26)
If b1(a1(j26)) = 0 Then GoTo 260
If b(a1(j26)) = 0 Then b(a1(j26)) = a1(j26): c(26) = a1(j26) Else GoTo 260
a(26) = a1(j26)
a(76) = Pr7 - a(26): If b(a(76)) = 0 Then b(a(76)) = a(76): c(76) = a(76) Else GoTo 760
a(24) = s7 - a(23) - a(25) - a(26) - a(27) - a(22) - a(28)
If a(24) < a1(m1) Or a(24) > a1(m2) Then GoTo 240
If b1(a(24)) = 0 Then GoTo 240
If b(a(24)) = 0 Then b(a(24)) = a(24): c(24) = a(24) Else GoTo 240
a(74) = Pr7 - a(24): If b(a(74)) = 0 Then b(a(74)) = a(74): c(74) = a(74) Else GoTo 740
For j11 = m1 To m2 'a(11)
If b(a1(j11)) = 0 Then b(a1(j11)) = a1(j11): c(11) = a1(j11) Else GoTo 110
a(11) = a1(j11)
a(61) = Pr7 - a(11): If b(a(61)) = 0 Then b(a(61)) = a(61): c(61) = a(61) Else GoTo 610
a(39) = s7 - a(11) - a(18) - a(25) - a(32) - a(4) - a(46)
If a(39) < a1(m1) Or a(39) > a1(m2) Then GoTo 390
If b1(a(39)) = 0 Then GoTo 390
If b(a(39)) = 0 Then b(a(39)) = a(39): c(39) = a(39) Else GoTo 390
a(89) = Pr7 - a(39): If b(a(89)) = 0 Then b(a(89)) = a(89): c(89) = a(89) Else GoTo 890
For j10 = m1 To m2 'a(10)
If b(a1(j10)) = 0 Then b(a1(j10)) = a1(j10): c(10) = a1(j10) Else GoTo 100
a(10) = a1(j10)
a(60) = Pr7 - a(10): If b(a(60)) = 0 Then b(a(60)) = a(60): c(60) = a(60) Else GoTo 600
a(38) = s7 - a(10) - a(17) - a(24) - a(31) - a(3) - a(45)
If a(38) < a1(m1) Or a(38) > a1(m2) Then GoTo 380
If b1(a(38)) = 0 Then GoTo 380
If b(a(38)) = 0 Then b(a(38)) = a(38): c(38) = a(38) Else GoTo 380
a(88) = Pr7 - a(38): If b(a(88)) = 0 Then b(a(88)) = a(88): c(88) = a(88) Else GoTo 880
a(12) = s7 - a(9) - a(10) - a(11) - a(13) - a(8) - a(14)
If a(12) < a1(m1) Or a(12) > a1(m2) Then GoTo 120
If b1(a(12)) = 0 Then GoTo 120
If b(a(12)) = 0 Then b(a(12)) = a(12): c(12) = a(12) Else GoTo 120
a(62) = Pr7 - a(12): If b(a(62)) = 0 Then b(a(62)) = a(62): c(62) = a(62) Else GoTo 620
a(40) = s7 - a(37) - a(38) - a(39) - a(41) - a(36) - a(42)
If a(40) < a1(m1) Or a(40) > a1(m2) Then GoTo 400
If b1(a(40)) = 0 Then GoTo 400
If b(a(40)) = 0 Then b(a(40)) = a(40): c(40) = a(40) Else GoTo 400
a(90) = Pr7 - a(40): If b(a(90)) = 0 Then b(a(90)) = a(90): c(90) = a(90) Else GoTo 900
' n9 = n9 + 1: GoSub 1740 'Print results ,selected numbers a()
' n9 = n9 + 1: GoSub 1750 'Print results (cubes)
n9 = n9 + 1: GoSub 1745 'Print results (squares)
Erase b, c: GoTo 1000 'Print only first Top Square
5
b(c(90)) = 0: c(90) = 0
900 b(c(40)) = 0: c(40) = 0
400 b(c(62)) = 0: c(62) = 0
620 b(c(12)) = 0: c(12) = 0
120 b(c(88)) = 0: c(88) = 0
880 b(c(38)) = 0: c(38) = 0
380 b(c(60)) = 0: c(60) = 0
600 b(c(10)) = 0: c(10) = 0
100 Next j10
b(c(89)) = 0: c(89) = 0
890 b(c(39)) = 0: c(39) = 0
390 b(c(61)) = 0: c(61) = 0
610 b(c(11)) = 0: c(11) = 0
110 Next j11
b(c(74)) = 0: c(74) = 0
740 b(c(24)) = 0: c(24) = 0
240 b(c(76)) = 0: c(76) = 0
760 b(c(26)) = 0: c(26) = 0
260 Next j26
b(c(82)) = 0: c(82) = 0
820 b(c(32)) = 0: c(32) = 0
320 b(c(84)) = 0: c(84) = 0
840 b(c(34)) = 0: c(34) = 0
340 b(c(77)) = 0: c(77) = 0
770 b(c(27)) = 0: c(27) = 0
270 Next j27
b(c(80)) = 0: c(80) = 0
800 b(c(30)) = 0: c(30) = 0
300 b(c(73)) = 0: c(73) = 0
730 b(c(23)) = 0: c(23) = 0
230 Next j23
b(c(66)) = 0: c(66) = 0
660 b(c(16)) = 0: c(16) = 0
160 b(c(68)) = 0: c(68) = 0
680 b(c(18)) = 0: c(18) = 0
180 Next j18
b(c(70)) = 0: c(70) = 0
700 b(c(20)) = 0: c(20) = 0
200 Next j20
b(c(63)) = 0: c(63) = 0
630 b(c(13)) = 0: c(13) = 0
130 b(c(69)) = 0: c(69) = 0
690 b(c(19)) = 0: c(19) = 0
190 Next j19
b(c(81)) = 0: c(81) = 0
810 b(c(31)) = 0: c(31) = 0
310 Next j31
b(c(87)) = 0: c(87) = 0
870 b(c(37)) = 0: c(37) = 0
370 Next j37
b(c(59)) = 0: c(59) = 0
590 b(c(9)) = 0: c(9) = 0
90 b(c(67)) = 0: c(67) = 0
670 b(c(17)) = 0: c(17) = 0
170 Next j17
b(c(75)) = 0: c(75) = 0
750 b(c(25)) = 0: c(25) = 0
250 Next j25
b(c(83)) = 0: c(83) = 0
830 b(c(33)) = 0: c(33) = 0
330 Next j33
b(c(91)) = 0: c(91) = 0
910 b(c(41)) = 0: c(41) = 0
410 Next j41
1000 Erase b1, b, c
Next j100
t2 = Timer
t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s7)
y = MsgBox(t10, 0, "Routine PrimeCubes71e")
End
' Print results, selected numbers a()
1740 For i1 = 1 To 49
Cells(n9, i1).Value = a(i1)
Next i1
Cells(n9, 50).Select
Cells(n9, 50).Value = s7
Cells(n9, 51).Value = Rcrd1a 'Record
Return
' Print results, left square a()
1745 n2 = n2 + 1
If n2 = 5 Then
n2 = 1: k1 = k1 + 8: k2 = 1
Else
If n9 > 1 Then k2 = k2 + 8
End If
Cells(k1 + 1, k2 + 1).Select
Cells(k1, k2 + 1).Select
Cells(k1, k2 + 1).Font.Color = -4165632
Cells(k1, k2 + 1).Value = s7
i3 = 0
For i1 = 1 To 7
For i2 = 1 To 7
i3 = i3 + 1
Cells(k1 + i1, k2 + i2).Value = a(i3)
Next i2
Next i1
Return
' Print results (7 plane format)
1750 n2 = n2 + 1
If n2 = 3 Then
n2 = 1: k1 = k1 + 56: k2 = 1
Else
If n9 > 1 Then k2 = k2 + 8
End If
Cells(k1, k2 + 1).Select
Cells(k1, k2 + 1).Font.Color = -4165632
Cells(k1, k2 + 1).Value = "MC = " + CStr(s7)
For i0 = 1 To 7
i3 = (7 - i0) * 49
For i1 = 1 To 7
For i2 = 1 To 7
i3 = i3 + 1
Cells(k1 + i1 + (i0 - 1) * 8, k2 + i2).Value = c7(i3)
Next i2
Next i1
Next i0
Return
' Fill Cube c7()
1760
' Top Square
For i1 = 1 To 49
c7(i1) = a(i1)
Next i1
' Bottom Square
c7(295) = Pr7 - c7(49): c7(296) = Pr7 - c7(44): c7(297) = Pr7 - c7(45): c7(298) = Pr7 - c7(46): c7(299) = Pr7 - c7(47):
c7(300) = Pr7 - c7(48): c7(301) = Pr7 - c7(43):
c7(302) = Pr7 - c7(14): c7(303) = Pr7 - c7(9): c7(304) = Pr7 - c7(10): c7(305) = Pr7 - c7(11): c7(306) = Pr7 - c7(12):
c7(307) = Pr7 - c7(13): c7(308) = Pr7 - c7(8):
c7(309) = Pr7 - c7(21): c7(310) = Pr7 - c7(16): c7(311) = Pr7 - c7(17): c7(312) = Pr7 - c7(18): c7(313) = Pr7 - c7(19):
c7(314) = Pr7 - c7(20): c7(315) = Pr7 - c7(15):
c7(316) = Pr7 - c7(28): c7(317) = Pr7 - c7(23): c7(318) = Pr7 - c7(24): c7(319) = Pr7 - c7(25): c7(320) = Pr7 - c7(26):
c7(321) = Pr7 - c7(27): c7(322) = Pr7 - c7(22):
c7(323) = Pr7 - c7(35): c7(324) = Pr7 - c7(30): c7(325) = Pr7 - c7(31): c7(326) = Pr7 - c7(32): c7(327) = Pr7 - c7(33):
c7(328) = Pr7 - c7(34): c7(329) = Pr7 - c7(29):
c7(330) = Pr7 - c7(42): c7(331) = Pr7 - c7(37): c7(332) = Pr7 - c7(38): c7(333) = Pr7 - c7(39): c7(334) = Pr7 - c7(40):
c7(335) = Pr7 - c7(41): c7(336) = Pr7 - c7(36):
c7(337) = Pr7 - c7(7): c7(338) = Pr7 - c7(2): c7(339) = Pr7 - c7(3): c7(340) = Pr7 - c7(4): c7(341) = Pr7 - c7(5):
c7(342) = Pr7 - c7(6): c7(343) = Pr7 - c7(1):
Return
1770
' Back Square
c7(50) = a(8): c7(51) = a(9): c7(52) = a(10): c7(53) = a(11): c7(54) = a(12): c7(55) = a(13): c7(56) = a(14):
c7(99) = a(15): c7(100) = a(16): c7(101) = a(17): c7(102) = a(18): c7(103) = a(19): c7(104) = a(20): c7(105) = a(21):
c7(148) = a(22): c7(149) = a(23): c7(150) = a(24): c7(151) = a(25): c7(152) = a(26): c7(153) = a(27): c7(154) = a(28):
c7(197) = a(29): c7(198) = a(30): c7(199) = a(31): c7(200) = a(32): c7(201) = a(33): c7(202) = a(34): c7(203) = a(35):
c7(246) = a(36): c7(247) = a(37): c7(248) = a(38): c7(249) = a(39): c7(250) = a(40): c7(251) = a(41): c7(252) = a(42):
' Front Square
c7(92) = Pr7 - c7(56): c7(93) = Pr7 - c7(51): c7(94) = Pr7 - c7(52): c7(95) = Pr7 - c7(53): c7(96) = Pr7 - c7(54):
c7(97) = Pr7 - c7(55): c7(98) = Pr7 - c7(50):
c7(141) = Pr7 - c7(105): c7(142) = Pr7 - c7(100): c7(143) = Pr7 - c7(101): c7(144) = Pr7 - c7(102): c7(145) = Pr7 - c7(103):
c7(146) = Pr7 - c7(104): c7(147) = Pr7 - c7(99):
c7(190) = Pr7 - c7(154): c7(191) = Pr7 - c7(149): c7(192) = Pr7 - c7(150): c7(193) = Pr7 - c7(151): c7(194) = Pr7 - c7(152):
c7(195) = Pr7 - c7(153): c7(196) = Pr7 - c7(148):
c7(239) = Pr7 - c7(203): c7(240) = Pr7 - c7(198): c7(241) = Pr7 - c7(199): c7(242) = Pr7 - c7(200): c7(243) = Pr7 - c7(201):
c7(244) = Pr7 - c7(202): c7(245) = Pr7 - c7(197):
c7(288) = Pr7 - c7(252): c7(289) = Pr7 - c7(247): c7(290) = Pr7 - c7(248): c7(291) = Pr7 - c7(249): c7(292) = Pr7 - c7(250):
c7(293) = Pr7 - c7(251): c7(294) = Pr7 - c7(246):
Return
' Remove used primes and complements from available primes
950 For i1 = 1 To 49
b1(a(i1)) = 0
b1(Pr7 - a(i1)) = 0
Next i1
Return
' Read Prime Numbers From sheet ShtNm1
2015 Pr7 = Sheets(ShtNm1).Cells(Rcrd1a, 1).Value ' Pairsum
nVar1 = Sheets(ShtNm1).Cells(Rcrd1a, 9).Value
s4 = 2 * Pr7 ' MC4
Cntr7 = Pr7 / 2 ' Center
s3 = 3 * Cntr7 ' MC3
s7 = 7 * Cntr7 ' MC7
Erase b1
For j1 = 1 To nVar1
x = Sheets(ShtNm1).Cells(Rcrd1a, 9 + j1).Value
b1(x) = x
Next j1
pMax = Sheets(ShtNm1).Cells(Rcrd1a, 9 + nVar1).Value
' Read Top Square 7 x 7
Erase a
For i1 = 1 To 49
a(i1) = Sheets(ShtNm2).Cells(j100, i1).Value
Next i1
GoSub 1760 'Fill Top and Bottom Square Cube c7()
GoSub 950 'Remove used primes and complements from available primes
' Read Back Square 7 x 7
Erase a
For i1 = 1 To 49
a(i1) = Sheets(ShtNm3).Cells(j100, i1).Value
Next i1
GoSub 1770 'Fill Back and Front Square Cube c7()
GoSub 950 'Remove used primes and complements from available primes
' Restore available pairs in a1()
n10 = 0
For j1 = 1 To pMax
If b1(j1) <> 0 Then
n10 = n10 + 1
a1(n10) = b1(j1)
End If
Next j1
m1 = 1: m2 = n10: n10 = 0
If a1(1) = 1 Then m1 = 2: m2 = m2 - 1
Return
End Sub