Vorige Pagina About the Author

' Generates Bordered Magic Cubes of order 5 (Prime Numbers)
' Magic Top/Bottom Planes

' Tested with Office 2007 under Windows 7

Sub PrimeCubes5a()

Dim a1(658), a(50), b1(43300), b(43300), c(50), c5(125)
Dim a3(27)          'Center
Dim a2(50), c2(50)  'Left Square
 
y = MsgBox("Locked", vbCritical, "Routine PrimeCubes5a")
End

n2 = 0: n9 = 0: k1 = 1: k2 = 1

ShtNm1 = "AntSym5b"            'Top Squares  (Anti Symmetric Magic)
ShtNm2 = "Pairs73"             'Pairs        (Reduced  with  Cubes3)
ShtNm3 = "Cubes3"              'Inner Cubes
    
    Sheets("Klad1").Select
    
    t1 = Timer

For j100 = 21 To 51

'   Start reading data from "AntSym5b"

    Rcrd1a = Sheets(ShtNm1).Cells(j100, 28).Value
    MC5 = Sheets(ShtNm1).Cells(j100, 26).Value

'   Start reading data from "Cubes3"                        Double Check

    MC3 = Sheets(ShtNm3).Cells(Rcrd1a, 28).Value
    
    If MC3 <> (3 * MC5 / 5) Then
        y = MsgBox("Conflict in Data", vbCritical, "Cubes5")
        End
    Else

'       Read Center Cube a3()
        For i1 = 1 To 27
            a3(i1) = Sheets(ShtNm3).Cells(Rcrd1a, i1).Value
        Next i1

    End If

'   Read Prime Numbers From sheet "Pairs73"

    s1 = Sheets(ShtNm2).Cells(Rcrd1a, 4).Value              'MC5
    Pr5 = Sheets(ShtNm2).Cells(Rcrd1a, 1).Value
    Cntr5 = Sheets(ShtNm2).Cells(Rcrd1a, 6).Value
    nVar = Sheets(ShtNm2).Cells(Rcrd1a, 9).Value
    
    m1 = 1: m2 = nVar

    Erase b1
    For j1 = 1 To nVar
           x = Sheets(ShtNm2).Cells(Rcrd1a, 9 + j1).Value
           b1(x) = x
    Next j1
    pMax = Sheets(ShtNm2).Cells(Rcrd1a, 9 + nVar).Value

    m1 = 1: m2 = nVar

'   Read Anti Symmetric Square

    For i1 = 1 To 25
        a(i1) = Sheets(ShtNm1).Cells(j100, i1).Value
    Next i1
    GoSub 750   'Fill Top and Bottom c5()

'   Remove used primes and complements from available primes

    For i1 = 1 To 25
        b1(c5(i1)) = 0: b1(c5(100 + i1)) = 0
    Next i1
    
'   Store 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

    b(Cntr5) = Cntr5                'Block Center Element

'   Define Back Square

    Erase a                         'Clear Scratch Area
    For i1 = 1 To 5
        a(i1) = c5(i1): a(i1 + 20) = c5(i1 + 100)
    Next i1
 
    For j20 = m1 To m2                                           'a(20)
    If b(a1(j20)) = 0 Then b(a1(j20)) = a1(j20): c(20) = a1(j20) Else GoTo 200
    a(20) = a1(j20)

    a(45) = Pr5 - a(20):    If b(a(45)) = 0 Then b(a(45)) = a(45): c(45) = a(45) Else GoTo 450
  
    For j19 = m1 To m2                                            'a(19)
    If b(a1(j19)) = 0 Then b(a1(j19)) = a1(j19): c(19) = a1(j19) Else GoTo 190
    a(19) = a1(j19)
  
    a(44) = Pr5 - a(19):    If b(a(44)) = 0 Then b(a(44)) = a(44): c(44) = a(44) Else GoTo 440
 
    For j18 = m1 To m2                                            'a(18)
    If b(a1(j18)) = 0 Then b(a1(j18)) = a1(j18): c(18) = a1(j18) Else GoTo 180
    a(18) = a1(j18)

    a(43) = Pr5 - a(18):    If b(a(43)) = 0 Then b(a(43)) = a(43): c(43) = a(43) Else GoTo 430
   
    For j17 = m1 To m2                                             'a(17)
    If b(a1(j17)) = 0 Then b(a1(j17)) = a1(j17): c(17) = a1(j17) Else GoTo 170
    a(17) = a1(j17)
    
    a(42) = Pr5 - a(17):    If b(a(42)) = 0 Then b(a(42)) = a(42): c(42) = a(42) Else GoTo 420
   
    a(16) = s1 - a(17) - a(18) - a(19) - a(20):
    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(41) = Pr5 - a(16):    If b(a(41)) = 0 Then b(a(41)) = a(41): c(41) = a(41) Else GoTo 410

    For j15 = m1 To m2                                          'a(15)
    If b(a1(j15)) = 0 Then b(a1(j15)) = a1(j15): c(15) = a1(j15) Else GoTo 150
    a(15) = a1(j15)

    a(40) = Pr5 - a(15):    If b(a(40)) = 0 Then b(a(40)) = a(40): c(40) = a(40) Else GoTo 400

    a(10) = s1 - a(15) - a(20) - a(5) - a(25)
    If a(10) < a1(m1) Or a(10) > a1(m2) Then GoTo 100
    If b1(a(10)) = 0 Then GoTo 100
    If b(a(10)) = 0 Then b(a(10)) = a(10): c(10) = a(10) Else GoTo 100

    a(35) = Pr5 - a(10):    If b(a(35)) = 0 Then b(a(35)) = a(35): c(35) = a(35) Else GoTo 350

    For j14 = m1 To m2                                          'a(14)
    If b(a1(j14)) = 0 Then b(a1(j14)) = a1(j14): c(14) = a1(j14) Else GoTo 140
    a(14) = a1(j14)
    
    a(39) = Pr5 - a(14):    If b(a(39)) = 0 Then b(a(39)) = a(39): c(39) = a(39) Else GoTo 390

    a(9) = s1 - a(14) - a(19) - a(4) - a(24)
    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(34) = Pr5 - a(9): If b(a(34)) = 0 Then b(a(34)) = a(34): c(34) = a(34) Else GoTo 340

    For j13 = m1 To m2                                          'a(13)
    If b(a1(j13)) = 0 Then b(a1(j13)) = a1(j13): c(13) = a1(j13) Else GoTo 130
    a(13) = a1(j13)

    a(38) = Pr5 - a(13):    If b(a(38)) = 0 Then b(a(38)) = a(38): c(38) = a(38) Else GoTo 380

    a(8) = s1 - a(13) - a(18) - a(3) - a(23)
    If a(8) < a1(m1) Or a(8) > a1(m2) Then GoTo 80
    If b1(a(8)) = 0 Then GoTo 80
    If b(a(8)) = 0 Then b(a(8)) = a(8): c(8) = a(8) Else GoTo 80
    
    a(33) = Pr5 - a(8): If b(a(33)) = 0 Then b(a(33)) = a(33): c(33) = a(33) Else GoTo 330

    For j12 = m1 To m2                                          'a(12)
    If b(a1(j12)) = 0 Then b(a1(j12)) = a1(j12): c(12) = a1(j12) Else GoTo 120
    a(12) = a1(j12)

    a(37) = Pr5 - a(12):    If b(a(37)) = 0 Then b(a(37)) = a(37): c(37) = a(37) Else GoTo 370

    a(11) = s1 - a(12) - a(13) - a(14) - a(15)
    If a(11) < a1(m1) Or a(11) > a1(m2) Then GoTo 110
    If b1(a(11)) = 0 Then GoTo 110
    If b(a(11)) = 0 Then b(a(11)) = a(11): c(11) = a(11) Else GoTo 110
    
    a(36) = Pr5 - a(11):    If b(a(36)) = 0 Then b(a(36)) = a(36): c(36) = a(36) Else GoTo 360

    a(7) = s1 - a(12) - a(17) - a(2) - a(22)
    If a(7) < a1(m1) Or a(7) > a1(m2) Then GoTo 70
    If b1(a(7)) = 0 Then GoTo 70
    If b(a(7)) = 0 Then b(a(7)) = a(7): c(7) = a(7) Else GoTo 70
    
    a(32) = Pr5 - a(7): If b(a(32)) = 0 Then b(a(32)) = a(32): c(32) = a(32) Else GoTo 320

    a(6) = s1 - a(11) - a(16) - a(1) - a(21)
    If a(6) < a1(m1) Or a(6) > a1(m2) Then GoTo 60
    If b1(a(6)) = 0 Then GoTo 60
    If b(a(6)) = 0 Then b(a(6)) = a(6): c(6) = a(6) Else GoTo 60
    
    a(31) = Pr5 - a(6): If b(a(31)) = 0 Then b(a(31)) = a(31): c(31) = a(31) Else GoTo 310
    
    
                             GoSub 760                                  'Fill Back and Front c5()
                             GoSub 2000                                 'Determine Left Square
                             
                             If fl2 = 1 Then Erase b, c, c5: GoTo 1000 'Print only first cube

5

    b(c(31)) = 0: c(31) = 0
310 b(c(6)) = 0: c(6) = 0
60  b(c(32)) = 0: c(32) = 0
320 b(c(7)) = 0: c(7) = 0
70  b(c(36)) = 0: c(36) = 0
360 b(c(11)) = 0: c(11) = 0
110 b(c(37)) = 0: c(37) = 0
370 b(c(12)) = 0: c(12) = 0
120 Next j12

    b(c(33)) = 0: c(33) = 0
330 b(c(8)) = 0: c(8) = 0
80  b(c(38)) = 0: c(38) = 0
380 b(c(13)) = 0: c(13) = 0
130 Next j13
    
    b(c(34)) = 0: c(34) = 0
340 b(c(9)) = 0: c(9) = 0
90  b(c(39)) = 0: c(39) = 0
390 b(c(14)) = 0: c(14) = 0
140 Next j14

    b(c(35)) = 0: c(35) = 0
350 b(c(10)) = 0: c(10) = 0
100 b(c(40)) = 0: c(40) = 0
400 b(c(15)) = 0: c(15) = 0
150 Next j15

    b(c(41)) = 0: c(41) = 0
410 b(c(16)) = 0: c(16) = 0
160 b(c(42)) = 0: c(42) = 0
420 b(c(17)) = 0: c(17) = 0
170 Next j17
     
    b(c(43)) = 0: c(43) = 0
430 b(c(18)) = 0: c(18) = 0
180 Next j18
     
    b(c(44)) = 0: c(44) = 0
440 b(c(19)) = 0: c(19) = 0
190 Next j19

    b(c(45)) = 0: c(45) = 0
450 b(c(20)) = 0: c(20) = 0
200 Next j20

      Erase b, c, c5
1000  Next j100
    
    t2 = Timer
    
    t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s1)
    y = MsgBox(t10, 0, "Routine PrimeCubes5a")
    
End

'    Determine Left Square and Complete Cube

2000 fl2 = 1

     Erase a2, c2         'Clear Scratch Areas
    
     a2(1) = c5(1):    a2(2) = c5(6):    a2(3) = c5(11):   a2(4) = c5(16):   a2(5) = c5(21):
     a2(6) = c5(26):                                                         a2(10) = c5(46):
     a2(11) = c5(51):                                                        a2(15) = c5(71):
     a2(16) = c5(76):                                                        a2(20) = c5(96):
     a2(21) = c5(101): a2(22) = c5(106): a2(23) = c5(111): a2(24) = c5(116): a2(25) = c5(121):

    For jj19 = m1 To m2                                            'a2(19)
    If b(a1(jj19)) = 0 Then b(a1(jj19)) = a1(jj19): c2(19) = a1(jj19) Else GoTo 2190
    a2(19) = a1(jj19)
  
    a2(44) = Pr5 - a2(19):    If b(a2(44)) = 0 Then b(a2(44)) = a2(44): c2(44) = a2(44) Else GoTo 2440
 
    For jj18 = m1 To m2                                            'a2(18)
    If b(a1(jj18)) = 0 Then b(a1(jj18)) = a1(jj18): c2(18) = a1(jj18) Else GoTo 2180
    a2(18) = a1(jj18)

    a2(43) = Pr5 - a2(18):    If b(a2(43)) = 0 Then b(a2(43)) = a2(43): c2(43) = a2(43) Else GoTo 2430

    a2(17) = s1 - a2(18) - a2(19) - a2(16) - a2(20)
    If a2(17) < a1(m1) Or a2(17) > a1(m2) Then GoTo 2170:
    If b1(a2(17)) = 0 Then GoTo 2170
    If b(a2(17)) = 0 Then b(a2(17)) = a2(17): c2(17) = a2(17) Else GoTo 2170
    
    a2(42) = Pr5 - a2(17):    If b(a2(42)) = 0 Then b(a2(42)) = a2(42): c2(42) = a2(42) Else GoTo 2420

    For jj14 = m1 To m2                                          'a2(14)
    If b(a1(jj14)) = 0 Then b(a1(jj14)) = a1(jj14): c2(14) = a1(jj14) Else GoTo 2140
    a2(14) = a1(jj14)
    
    a2(39) = Pr5 - a2(14):    If b(a2(39)) = 0 Then b(a2(39)) = a2(39): c2(39) = a2(39) Else GoTo 2390
    
    For jj13 = m1 To m2                                          'a2(13)
    If b(a1(jj13)) = 0 Then b(a1(jj13)) = a1(jj13): c2(13) = a1(jj13) Else GoTo 2130
    a2(13) = a1(jj13)

    a2(38) = Pr5 - a2(13):    If b(a2(38)) = 0 Then b(a2(38)) = a2(38): c2(38) = a2(38) Else GoTo 2380

    a2(12) = s1 - a2(13) - a2(14) - a2(11) - a2(15)
    If a2(12) < a1(m1) Or a2(12) > a1(m2) Then GoTo 2120:
    If b1(a2(12)) = 0 Then GoTo 2120
    If b(a2(12)) = 0 Then b(a2(12)) = a2(12): c2(12) = a2(12) Else GoTo 2120

    a2(37) = Pr5 - a2(12):    If b(a2(37)) = 0 Then b(a2(37)) = a2(37): c2(37) = a2(37) Else GoTo 2370

    a2(9) = s1 - a2(14) - a2(19) - a2(4) - a2(24)
    If a2(9) < a1(m1) Or a2(9) > a1(m2) Then GoTo 2090:
    If b1(a2(9)) = 0 Then GoTo 2090
    If b(a2(9)) = 0 Then b(a2(9)) = a2(9): c2(9) = a2(9) Else GoTo 2090
    
    a2(34) = Pr5 - a2(9): If b(a2(34)) = 0 Then b(a2(34)) = a2(34): c2(34) = a2(34) Else GoTo 2340
    
    a2(8) = s1 - a2(13) - a2(18) - a2(3) - a2(23)
    If a2(8) < a1(m1) Or a2(8) > a1(m2) Then GoTo 2080:
    If b1(a2(8)) = 0 Then GoTo 2080
    If b(a2(8)) = 0 Then b(a2(8)) = a2(8): c2(8) = a2(8) Else GoTo 2080
    
    a2(33) = Pr5 - a2(8): If b(a2(33)) = 0 Then b(a2(33)) = a2(33): c2(33) = a2(33) Else GoTo 2330
    
    a2(7) = s1 - a2(12) - a2(17) - a2(2) - a2(22)
    If a2(7) < a1(m1) Or a2(7) > a1(m2) Then GoTo 2070:
    If b1(a2(7)) = 0 Then GoTo 2070
    If b(a2(7)) = 0 Then b(a2(7)) = a2(7): c2(7) = a2(7) Else GoTo 2070

    a2(32) = Pr5 - a2(7): If b(a2(32)) = 0 Then b(a2(32)) = a2(32): c2(32) = a2(32) Else GoTo 2320

                             GoSub 770                             'Fill Left and Right c5()
                             GoSub 780                             'Fill Center         c5()
                             
                             GoSub 800:                            'Back Check Identcal Numbers
                             If fl1 = 1 Then
                                 n9 = n9 + 1: GoSub 1750           'Print results (Cubes)
                                 Return
                             End If
                             
     b(c2(32)) = 0: c2(32) = 0
2320 b(c2(7)) = 0:  c2(7) = 0
2070 b(c2(33)) = 0: c2(33) = 0
2330 b(c2(8)) = 0:  c2(8) = 0
2080 b(c2(34)) = 0: c2(34) = 0
2340 b(c2(9)) = 0:  c2(9) = 0
2090 b(c2(37)) = 0: c2(37) = 0
2370 b(c2(12)) = 0: c2(12) = 0
2120 b(c2(38)) = 0: c2(38) = 0
2380 b(c2(13)) = 0: c2(13) = 0
2130 Next jj13
    
     b(c2(39)) = 0: c2(39) = 0
2390 b(c2(14)) = 0: c2(14) = 0
2140 Next jj14

     b(c2(42)) = 0: c2(42) = 0
2420 b(c2(17)) = 0: c2(17) = 0
2170 b(c2(43)) = 0: c2(43) = 0
2430 b(c2(18)) = 0: c2(18) = 0
2180 Next jj18
     
     b(c2(44)) = 0: c2(44) = 0
2440 b(c2(19)) = 0: c2(19) = 0
2190 Next jj19
     
     fl2 = 0
     
     Return

'   Fill Cube c5()

750
'   Top Square

    For i1 = 1 To 25
        c5(i1) = a(i1)
    Next i1

'   Bottom Square

    c5(101) = Pr5 - a(25):  c5(102) = Pr5 - a(22):  c5(103) = Pr5 - a(23):  c5(104) = Pr5 - a(24):  c5(105) = Pr5 - a(21):
    c5(106) = Pr5 - a(10):  c5(107) = Pr5 - a(7):   c5(108) = Pr5 - a(8):   c5(109) = Pr5 - a(9):   c5(110) = Pr5 - a(6):
    c5(111) = Pr5 - a(15):  c5(112) = Pr5 - a(12):  c5(113) = Pr5 - a(13):  c5(114) = Pr5 - a(14):  c5(115) = Pr5 - a(11):
    c5(116) = Pr5 - a(20):  c5(117) = Pr5 - a(17):  c5(118) = Pr5 - a(18):  c5(119) = Pr5 - a(19):  c5(120) = Pr5 - a(16):
    c5(121) = Pr5 - a(5):   c5(122) = Pr5 - a(2):   c5(123) = Pr5 - a(3):   c5(124) = Pr5 - a(4):   c5(125) = Pr5 - a(1):

    Return

760
'   Back  Square

    c5(26) = a(6):  c5(27) = a(7):  c5(28) = a(8):  c5(29) = a(9):  c5(30) = a(10):
    c5(51) = a(11): c5(52) = a(12): c5(53) = a(13): c5(54) = a(14): c5(55) = a(15):
    c5(76) = a(16): c5(77) = a(17): c5(78) = a(18): c5(79) = a(19): c5(80) = a(20):

'   Front Square

    c5(46) = Pr5 - a(10): c5(47) = Pr5 - a(7):  c5(48) = Pr5 - a(8):  c5(49) = Pr5 - a(9):  c5(50) = Pr5 - a(6):
    c5(71) = Pr5 - a(15): c5(72) = Pr5 - a(12): c5(73) = Pr5 - a(13): c5(74) = Pr5 - a(14): c5(75) = Pr5 - a(11):
    c5(96) = Pr5 - a(20): c5(97) = Pr5 - a(17): c5(98) = Pr5 - a(18): c5(99) = Pr5 - a(19): c5(100) = Pr5 - a(16):

    Return
    
770
'   Left Square
            
    c5(31) = a2(7):  c5(36) = a2(8):  c5(41) = a2(9):
    c5(56) = a2(12): c5(61) = a2(13): c5(66) = a2(14):
    c5(81) = a2(17): c5(86) = a2(18): c5(91) = a2(19):

'   Right Square

    c5(35) = Pr5 - a2(7):  c5(40) = Pr5 - a2(8):  c5(45) = Pr5 - a2(9):
    c5(60) = Pr5 - a2(12): c5(65) = Pr5 - a2(13): c5(70) = Pr5 - a2(14):
    c5(85) = Pr5 - a2(17): c5(90) = Pr5 - a2(18): c5(95) = Pr5 - a2(19):

    Return

780
'   Center

    c5(32) = a3(1):  c5(33) = a3(2):  c5(34) = a3(3):
    c5(37) = a3(4):  c5(38) = a3(5):  c5(39) = a3(6):
    c5(42) = a3(7):  c5(43) = a3(8):  c5(44) = a3(9):
            
    c5(57) = a3(10): c5(58) = a3(11): c5(59) = a3(12):
    c5(62) = a3(13): c5(63) = a3(14): c5(64) = a3(15):
    c5(67) = a3(16): c5(68) = a3(17): c5(69) = a3(18):
            
    c5(82) = a3(19): c5(83) = a3(20): c5(84) = a3(21):
    c5(87) = a3(22): c5(88) = a3(23): c5(89) = a3(24):
    c5(92) = a3(25): c5(93) = a3(26): c5(94) = a3(27):

    Return

'   Exclude solutions with identical numbers

800 fl1 = 1
    For j1 = 1 To 125
       c20 = c5(j1): If c20 = 0 Then GoTo 810
       For j2 = (1 + j1) To 125
           If c20 = c5(j2) Then fl1 = 0: Return
       Next j2
810 Next j1
    Return

'    Print results (selected numbers)

1740 For i1 = 1 To 125
         Cells(n9, i1).Value = c5(i1)
     Next i1
    
     Return

'    Print results (5 plane format)

1750 n2 = n2 + 1
     If n2 = 6 Then
         n2 = 1: k1 = k1 + 30: k2 = 1
     Else
         If n9 > 1 Then k2 = k2 + 6
     End If
       
     For i0 = 1 To 5
         i3 = (5 - i0) * 25
         For i1 = 1 To 5
             For i2 = 1 To 5
                 i3 = i3 + 1
                 Cells(k1 + i1 + (i0 - 1) * 6, k2 + i2).Value = c5(i3)
             Next i2
         Next i1
         If i0 = 1 Then
             Cells(k1 + (i0 - 1) * 6, k2 + 1).Font.Color = -4165632
             Cells(k1 + (i0 - 1) * 6, k2 + 1).Value = "MC5 = " + CStr(s1)
         End If
     Next i0
    
     Return

End Sub

Vorige Pagina About the Author