' Generates Bordered Magic Cubes of order 6 (Prime Numbers)
' Part III: Anti Symmetric Magic Left Squares (e)
' Tested with Office 365 under Windows 10
Sub PrimeCubes61e()
Dim a1(724), a(100), b1(43291), b(43291), c(100), C6(216)
y = MsgBox("Locked", vbCritical, "Routine PrimeCubes61e")
End
n2 = 0: n9 = 0: k1 = 1: k2 = 1
ShtNm1 = "Pairs63"
ShtNm2 = "TopSqrs6"
ShtNm3 = "BackSqrs6"
Sheets("Klad1").Select
t1 = Timer
For j100 = 2 To 98
If Sheets(ShtNm3).Cells(j100, 40).Value = 0 Then GoTo 1000
' Start Reading Data ShtNm2/ShtNm3
Mc6 = Sheets(ShtNm2).Cells(j100, 37).Value
Rcrd1a = Sheets(ShtNm2).Cells(j100, 38).Value
Rcrd1b = Sheets(ShtNm3).Cells(j100, 38).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 c6()
GoSub 2015
' Fill Scratch Arae
Erase a
a(1) = C6(1): a(2) = C6(7): a(3) = C6(13): a(4) = C6(19): a(5) = C6(25): a(6) = C6(31):
a(7) = C6(37): a(12) = C6(67):
a(13) = C6(73): a(18) = C6(103):
a(19) = C6(109): a(24) = C6(139):
a(25) = C6(145): a(30) = C6(175):
a(31) = C6(181): a(32) = C6(187): a(33) = C6(193): a(34) = C6(199): a(35) = C6(205): a(36) = C6(211):
t11 = Timer 'Time Out
For jj29 = m1 To m2 'a(29)
If b(a1(jj29)) = 0 Then b(a1(jj29)) = a1(jj29): c(29) = a1(jj29) Else GoTo 3290
a(29) = a1(jj29)
a(65) = Pr6 - a(29): If b(a(65)) = 0 Then b(a(65)) = a(65): c(65) = a(65) Else GoTo 3650
For jj22 = m1 To m2 'a(22)
If b(a1(jj22)) = 0 Then b(a1(jj22)) = a1(jj22): c(22) = a1(jj22) Else GoTo 3220
a(22) = a1(jj22)
a(58) = Pr6 - a(22): If b(a(58)) = 0 Then b(a(58)) = a(58): c(58) = a(58) Else GoTo 3580
For jj15 = m1 To m2 'a(15)
If b(a1(jj15)) = 0 Then b(a1(jj15)) = a1(jj15): c(15) = a1(jj15) Else GoTo 3150
a(15) = a1(jj15)
a(51) = Pr6 - a(15): If b(a(51)) = 0 Then b(a(51)) = a(51): c(51) = a(51) Else GoTo 3510
a(8) = s6 - a(1) - a(15) - a(22) - a(29) - a(36)
If a(8) < a1(m1) Or a(8) > a1(m2) Then GoTo 3080
If b1(a(8)) = 0 Then GoTo 3080
If b(a(8)) = 0 Then b(a(8)) = a(8): c(8) = a(8) Else GoTo 3080
a(44) = Pr6 - a(8): If b(a(44)) = 0 Then b(a(44)) = a(44): c(44) = a(44) Else GoTo 3440
For jj26 = m1 To m2 'a(26)
If b(a1(jj26)) = 0 Then b(a1(jj26)) = a1(jj26): c(26) = a1(jj26) Else GoTo 3260
a(26) = a1(jj26)
a(62) = Pr6 - a(26): If b(a(62)) = 0 Then b(a(62)) = a(62): c(62) = a(62) Else GoTo 3620
For jj21 = m1 To m2 'a(21)
If b(a1(jj21)) = 0 Then b(a1(jj21)) = a1(jj21): c(21) = a1(jj21) Else GoTo 3210
a(21) = a1(jj21)
a(57) = Pr6 - a(21): If b(a(57)) = 0 Then b(a(57)) = a(57): c(57) = a(57) Else GoTo 3570
a(16) = (2 * s6 - 2 * a(21) - 2 * a(15) - 2 * a(22) +
- a(1) - a(3) - a(4) - a(6) + a(7) + a(12) + a(25) + a(30) - a(31) - a(33) - a(34) - a(36)) / 2
If a(16) < a1(m1) Or a(16) > a1(m2) Or CInt(a(16)) <> a(16) Then GoTo 3160
If b1(a(16)) = 0 Then GoTo 3160
If b(a(16)) = 0 Then b(a(16)) = a(16): c(16) = a(16) Else GoTo 3160
a(52) = Pr6 - a(16): If b(a(52)) = 0 Then b(a(52)) = a(52): c(52) = a(52) Else GoTo 3520
a(11) = s6 - a(6) - a(16) - a(21) - a(26) - a(31)
If a(11) < a1(m1) Or a(11) > a1(m2) Then GoTo 3110
If b1(a(11)) = 0 Then GoTo 3110
If b(a(11)) = 0 Then b(a(11)) = a(11): c(11) = a(11) Else GoTo 3110
a(47) = Pr6 - a(11): If b(a(47)) = 0 Then b(a(47)) = a(47): c(47) = a(47) Else GoTo 3470
For jj28 = m1 To m2 'a(28)
If b(a1(jj28)) = 0 Then b(a1(jj28)) = a1(jj28): c(28) = a1(jj28) Else GoTo 3280
a(28) = a1(jj28)
a(64) = Pr6 - a(28): If b(a(64)) = 0 Then b(a(64)) = a(64): c(64) = a(64) Else GoTo 3640
a(27) = s6 - a(25) - a(26) - a(28) - a(29) - a(30)
If a(27) < a1(m1) Or a(27) > a1(m2) Then GoTo 3270
If b1(a(27)) = 0 Then GoTo 3270
If b(a(27)) = 0 Then b(a(27)) = a(27): c(27) = a(27) Else GoTo 3270
a(63) = Pr6 - a(27): If b(a(63)) = 0 Then b(a(63)) = a(63): c(63) = a(63) Else GoTo 3630
a(10) = s6 - a(16) - a(22) - a(28) - a(4) - a(34)
If a(10) < a1(m1) Or a(10) > a1(m2) Then GoTo 3100
If b1(a(10)) = 0 Then GoTo 3100
If b(a(10)) = 0 Then b(a(10)) = a(10): c(10) = a(10) Else GoTo 3100
a(46) = Pr6 - a(10): If b(a(46)) = 0 Then b(a(46)) = a(46): c(46) = a(46) Else GoTo 3460
a(9) = s6 - a(15) - a(21) - a(27) - a(3) - a(33)
If a(9) < a1(m1) Or a(9) > a1(m2) Then GoTo 3090
If b1(a(9)) = 0 Then GoTo 3090
If b(a(9)) = 0 Then b(a(9)) = a(9): c(9) = a(9) Else GoTo 3090
a(45) = Pr6 - a(9): If b(a(45)) = 0 Then b(a(45)) = a(45): c(45) = a(45) Else GoTo 3450
For jj23 = m1 To m2 'a(23)
If b(a1(jj23)) = 0 Then b(a1(jj23)) = a1(jj23): c(23) = a1(jj23) Else GoTo 3230
a(23) = a1(jj23)
a(59) = Pr6 - a(23): If b(a(59)) = 0 Then b(a(59)) = a(59): c(59) = a(59) Else GoTo 3590
a(20) = s6 - a(21) - a(22) - a(23) - a(19) - a(24)
If a(20) < a1(m1) Or a(20) > a1(m2) Then GoTo 3200
If b1(a(20)) = 0 Then GoTo 3200
If b(a(20)) = 0 Then b(a(20)) = a(20): c(20) = a(20) Else GoTo 3200
a(56) = Pr6 - a(20): If b(a(56)) = 0 Then b(a(56)) = a(56): c(56) = a(56) Else GoTo 3560
a(17) = s6 - a(11) - a(23) - a(29) - a(5) - a(35)
If a(17) < a1(m1) Or a(17) > a1(m2) Then GoTo 3170
If b1(a(17)) = 0 Then GoTo 3170
If b(a(17)) = 0 Then b(a(17)) = a(17): c(17) = a(17) Else GoTo 3170
a(53) = Pr6 - a(17): If b(a(53)) = 0 Then b(a(53)) = a(53): c(53) = a(53) Else GoTo 3530
a(14) = s6 - a(15) - a(16) - a(17) - a(13) - a(18)
If a(14) < a1(m1) Or a(14) > a1(m2) Then GoTo 3140
If b1(a(14)) = 0 Then GoTo 3140
If b(a(14)) = 0 Then b(a(14)) = a(14): c(14) = a(14) Else GoTo 3140
a(50) = Pr6 - a(14): If b(a(50)) = 0 Then b(a(50)) = a(50): c(50) = a(50) Else GoTo 3500
GoSub 850 'Check identical integers (Back Check)
If fl1 = 0 Then GoTo 5
' n9 = n9 + 1: GoSub 1740 'Print results ,selected numbers a()
n9 = n9 + 1: GoSub 1745 'Print results (squares)
Erase b, c: GoTo 1000 'Print only first Top Square
5
b(c(50)) = 0: c(50) = 0
3500 b(c(14)) = 0: c(14) = 0
3140 b(c(53)) = 0: c(53) = 0
3530 b(c(17)) = 0: c(17) = 0
3170 b(c(56)) = 0: c(56) = 0
3560 b(c(20)) = 0: c(20) = 0
3200 b(c(59)) = 0: c(59) = 0
3590 b(c(23)) = 0: c(23) = 0
3230 Next jj23
b(c(45)) = 0: c(45) = 0
3450 b(c(9)) = 0: c(9) = 0
3090 b(c(46)) = 0: c(46) = 0
3460 b(c(10)) = 0: c(10) = 0
3100 b(c(63)) = 0: c(63) = 0
3630 b(c(27)) = 0: c(27) = 0
3270 b(c(64)) = 0: c(64) = 0
3640 b(c(28)) = 0: c(28) = 0
3280 Next jj28
b(c(47)) = 0: c(47) = 0
3470 b(c(11)) = 0: c(11) = 0
3110 b(c(52)) = 0: c(52) = 0
3520 b(c(16)) = 0: c(16) = 0
3160
b(c(57)) = 0: c(57) = 0
3570 b(c(21)) = 0: c(21) = 0
3210 Next jj21
b(c(62)) = 0: c(62) = 0
3620 b(c(26)) = 0: c(26) = 0
3260 Next jj26
b(c(44)) = 0: c(44) = 0
3440 b(c(8)) = 0: c(8) = 0
3080 b(c(51)) = 0: c(51) = 0
3510 b(c(15)) = 0: c(15) = 0
3150 Next jj15
b(c(58)) = 0: c(58) = 0
3580 b(c(22)) = 0: c(22) = 0
3220 Next jj22
b(c(65)) = 0: c(65) = 0
3650 b(c(29)) = 0: c(29) = 0
3290 Next jj29
1000 Erase b1, b, c
Next j100
t2 = Timer
t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s6)
y = MsgBox(t10, 0, "Routine PrimeCubes61e")
End
' Exclude solutions with identical numbers c6()
850 fl1 = 1
For j1 = 1 To 216
a20 = C6(j1): If a20 = 0 Then GoTo 855
For j2 = (1 + j1) To 216
If a20 = C6(j2) Then fl1 = 0: Return
Next j2
855 Next j1
Return
' Print results, selected numbers a()
1740 For i1 = 1 To 36
Cells(n9, i1).Value = a(i1)
Next i1
Cells(1, 39).Value = n9
Cells(n9, 37).Value = s6
Cells(n9, 38).Value = Rcrd1a 'Record
Return
' Print results, left square a()
1745 n2 = n2 + 1
If n2 = 4 Then
n2 = 1: k1 = k1 + 7: k2 = 1
Else
If n9 > 1 Then k2 = k2 + 7
End If
Cells(3, 1).Value = n9
Cells(k1, k2 + 1).Font.Color = -4165632
Cells(k1, k2 + 1).Value = s6
Cells(k1, k2 + 2).Value = j100
i3 = 0
For i1 = 1 To 6
For i2 = 1 To 6
i3 = i3 + 1
Cells(k1 + i1, k2 + i2).Value = a(i3)
Next i2
Next i1
Return
' Print results (6 plane format)
1750 n2 = n2 + 1
If n2 = 4 Then
n2 = 1: k1 = k1 + 42: k2 = 1
Else
If n9 > 1 Then k2 = k2 + 7
End If
Cells(k1, k2 + 1).Select
Cells(k1, k2 + 1).Font.Color = -4165632
Cells(k1, k2 + 1).Value = "MC = " + CStr(s6) ''n9, j100
For i0 = 1 To 6
i3 = (6 - i0) * 36
For i1 = 1 To 6
For i2 = 1 To 6
i3 = i3 + 1
Cells(k1 + i1 + (i0 - 1) * 7, k2 + i2).Value = C6(i3) 'Bordered Magic Cube
Next i2
Next i1
Next i0
Return
' Fill Cube c6()
1760
' Top Square
For i1 = 1 To 36
C6(i1) = a(i1)
Next i1
' Bottom Square
C6(181) = Pr6 - C6(36): C6(182) = Pr6 - C6(32): C6(183) = Pr6 - C6(33):
C6(184) = Pr6 - C6(34): C6(185) = Pr6 - C6(35): C6(186) = Pr6 - C6(31):
C6(187) = Pr6 - C6(12): C6(188) = Pr6 - C6(8): C6(189) = Pr6 - C6(9):
C6(190) = Pr6 - C6(10): C6(191) = Pr6 - C6(11): C6(192) = Pr6 - C6(7):
C6(193) = Pr6 - C6(18): C6(194) = Pr6 - C6(14): C6(195) = Pr6 - C6(15):
C6(196) = Pr6 - C6(16): C6(197) = Pr6 - C6(17): C6(198) = Pr6 - C6(13):
C6(199) = Pr6 - C6(24): C6(200) = Pr6 - C6(20): C6(201) = Pr6 - C6(21):
C6(202) = Pr6 - C6(22): C6(203) = Pr6 - C6(23): C6(204) = Pr6 - C6(19):
C6(205) = Pr6 - C6(30): C6(206) = Pr6 - C6(26): C6(207) = Pr6 - C6(27):
C6(208) = Pr6 - C6(28): C6(209) = Pr6 - C6(29): C6(210) = Pr6 - C6(25):
C6(211) = Pr6 - C6(6): C6(212) = Pr6 - C6(2): C6(213) = Pr6 - C6(3):
C6(214) = Pr6 - C6(4): C6(215) = Pr6 - C6(5): C6(216) = Pr6 - C6(1):
Return
1770
' Back Square
C6(37) = a(7): C6(38) = a(8): C6(39) = a(9): C6(40) = a(10): C6(41) = a(11): C6(42) = a(12):
C6(73) = a(13): C6(74) = a(14): C6(75) = a(15): C6(76) = a(16): C6(77) = a(17): C6(78) = a(18):
C6(109) = a(19): C6(110) = a(20): C6(111) = a(21): C6(112) = a(22): C6(113) = a(23): C6(114) = a(24):
C6(145) = a(25): C6(146) = a(26): C6(147) = a(27): C6(148) = a(28): C6(149) = a(29): C6(150) = a(30):
' Front Square
C6(67) = Pr6 - C6(42): C6(68) = Pr6 - C6(38): C6(69) = Pr6 - C6(39): C6(70) = Pr6 - C6(40):
C6(71) = Pr6 - C6(41): C6(72) = Pr6 - C6(37):
C6(103) = Pr6 - C6(78): C6(104) = Pr6 - C6(74): C6(105) = Pr6 - C6(75): C6(106) = Pr6 - C6(76):
C6(107) = Pr6 - C6(77): C6(108) = Pr6 - C6(73):
C6(139) = Pr6 - C6(114): C6(140) = Pr6 - C6(110): C6(141) = Pr6 - C6(111): C6(142) = Pr6 - C6(112):
C6(143) = Pr6 - C6(113): C6(144) = Pr6 - C6(109):
C6(175) = Pr6 - C6(150): C6(176) = Pr6 - C6(146): C6(177) = Pr6 - C6(147): C6(178) = Pr6 - C6(148):
C6(179) = Pr6 - C6(149): C6(180) = Pr6 - C6(145):
''n9 = n9 + 1: GoSub 1750: End
Return
' Remove used primes and complements from available primes
950 For i1 = 1 To 36
b1(a(i1)) = 0
b1(Pr6 - a(i1)) = 0
Next i1
Return
' Read Prime Numbers From sheet ShtNm1
2015 Pr6 = Sheets(ShtNm1).Cells(Rcrd1a, 1).Value ' Pairsum
nVar1 = Sheets(ShtNm1).Cells(Rcrd1a, 5).Value
s4 = 2 * Pr6 ' MC4
s6 = 3 * Pr6 ' Mc6
Erase b1
For j1 = 1 To nVar1
x = Sheets(ShtNm1).Cells(Rcrd1a, 10 + j1).Value
b1(x) = x
Next j1
pMax = Sheets(ShtNm1).Cells(Rcrd1a, 10 + nVar1).Value
' Read Top Square 7 x 7
Erase a
For i1 = 1 To 36
a(i1) = Sheets(ShtNm2).Cells(j100, i1).Value
Next i1
GoSub 1760 'Fill Top and Bottom Square Cube c6()
GoSub 950 'Remove used primes and complements from available primes
' Read Back Square 6 x 6
Erase a
For i1 = 1 To 36
a(i1) = Sheets(ShtNm3).Cells(j100, i1).Value
Next i1
GoSub 1770 'Fill Back and Front Square Cube c6()
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