Vorige Pagina Volgende Pagina About the Author

' Generates Bordered Magic Cubes of order 7 (Prime Numbers)
' Part III: Putting it all together (f)

' Tested with Office 365 under Windows 10

Sub PrimeCubes71f()

Dim a(49), c5(125), c7(343)

y = MsgBox("Locked", vbCritical, "Routine PrimeCubes71f")
End

    n2 = 0: n9 = 0: k1 = 1: k2 = 1
    ShtNm1 = "Lines125"             ' Center Cube
    ShtNm2 = "TopSqrs7"             ' Top    Square
    ShtNm3 = "BackSqrs7"            ' Back   Square
    ShtNm4 = "LeftSqrs7"            ' Left   Square
    
    Sheets("Klad1").Select
    
    t1 = Timer
    
For j100 = 2 To 2
    
    Rcrd1a = Sheets(ShtNm2).Cells(j100, 51).Value
    MC7a = Sheets(ShtNm2).Cells(j100, 50).Value
    
    Rcrd1b = Sheets(ShtNm3).Cells(j100, 51).Value
    MC7b = Sheets(ShtNm3).Cells(j100, 50).Value
    
    Rcrd1c = Sheets(ShtNm4).Cells(j100, 51).Value
    MC7c = Sheets(ShtNm4).Cells(j100, 50).Value
   
'   Check Input
   
    If Rcrd1a <> Rcrd1b Or Rcrd1a <> Rcrd1c Then
        y = MsgBox("Conflicting Data", vbCritical, "Check Input: " + CStr(j100))
        End
    End If

    If MC7a <> MC7b Or MC7a <> MC7c Then
        y = MsgBox("Conflicting Data", vbCritical, "Check Input: " + CStr(j100))
        End
    End If
    
    Pr7 = 2 * MC7a / 7: s7 = MC7a

'   Read Top Square / Determine Bottom Square

    For i1 = 1 To 49
        a(i1) = Sheets(ShtNm2).Cells(j100, i1).Value
    Next i1
    GoSub 1760

'   Read Back Square / Determine Front Square

    For i1 = 1 To 49
        a(i1) = Sheets(ShtNm3).Cells(j100, i1).Value
    Next i1
    GoSub 1770

'   Read Left Square / Determine Right Square

    For i1 = 1 To 49
        a(i1) = Sheets(ShtNm4).Cells(j100, i1).Value
    Next i1
    GoSub 1780
    
'   Read Center Cube

    For i1 = 1 To 125
        c5(i1) = Sheets(ShtNm1).Cells(Rcrd1a, i1).Value
    Next i1
    GoSub 1790
    
'   Back Check Identical Numbers
    
    GoSub 800
    If fl1 = 1 Then
'       Print Cube
        n9 = n9 + 1: GoSub 1750
    End If
    
Next j100

End

'   Exclude solutions with identical numbers

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

'    Print results (7 plane format)

1750 n2 = n2 + 1
     If n2 = 4 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

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

1780
'   Left Square

    c7(1) = a(1):    c7(8) = a(2):    c7(15) = a(3):   c7(22) = a(4):   c7(29) = a(5):   c7(36) = a(6):   c7(43) = a(7):
    c7(50) = a(8):   c7(57) = a(9):   c7(64) = a(10):  c7(71) = a(11):  c7(78) = a(12):  c7(85) = a(13):  c7(92) = a(14):
    c7(99) = a(15):  c7(106) = a(16): c7(113) = a(17): c7(120) = a(18): c7(127) = a(19): c7(134) = a(20): c7(141) = a(21):
    c7(148) = a(22): c7(155) = a(23): c7(162) = a(24): c7(169) = a(25): c7(176) = a(26): c7(183) = a(27): c7(190) = a(28):
    c7(197) = a(29): c7(204) = a(30): c7(211) = a(31): c7(218) = a(32): c7(225) = a(33): c7(232) = a(34): c7(239) = a(35):
    c7(246) = a(36): c7(253) = a(37): c7(260) = a(38): c7(267) = a(39): c7(274) = a(40): c7(281) = a(41): c7(288) = a(42):
    c7(295) = a(43): c7(302) = a(44): c7(309) = a(45): c7(316) = a(46): c7(323) = a(47): c7(330) = a(48): c7(337) = a(49):

'   Right Square

    c7(63) = Pr7 - c7(57):   c7(70) = Pr7 - c7(64):   c7(77) = Pr7 - c7(71):   c7(84) = Pr7 - c7(78):   c7(91) = Pr7 - c7(85):
    c7(112) = Pr7 - c7(106): c7(119) = Pr7 - c7(113): c7(126) = Pr7 - c7(120): c7(133) = Pr7 - c7(127): c7(140) = Pr7 - c7(134):
    c7(161) = Pr7 - c7(155): c7(168) = Pr7 - c7(162): c7(175) = Pr7 - c7(169): c7(182) = Pr7 - c7(176): c7(189) = Pr7 - c7(183):
    c7(210) = Pr7 - c7(204): c7(217) = Pr7 - c7(211): c7(224) = Pr7 - c7(218): c7(231) = Pr7 - c7(225): c7(238) = Pr7 - c7(232):
    c7(259) = Pr7 - c7(253): c7(266) = Pr7 - c7(260): c7(273) = Pr7 - c7(267): c7(280) = Pr7 - c7(274): c7(287) = Pr7 - c7(281):

    Return
    
1790
'   Center Cube

    c7(58) = c5(1):   c7(59) = c5(2):   c7(60) = c5(3):   c7(61) = c5(4):   c7(62) = c5(5):
    c7(65) = c5(6):   c7(66) = c5(7):   c7(67) = c5(8):   c7(68) = c5(9):   c7(69) = c5(10):
    c7(72) = c5(11):  c7(73) = c5(12):  c7(74) = c5(13):  c7(75) = c5(14):  c7(76) = c5(15):
    c7(79) = c5(16):  c7(80) = c5(17):  c7(81) = c5(18):  c7(82) = c5(19):  c7(83) = c5(20):
    c7(86) = c5(21):  c7(87) = c5(22):  c7(88) = c5(23):  c7(89) = c5(24):  c7(90) = c5(25):

    c7(107) = c5(26): c7(108) = c5(27): c7(109) = c5(28): c7(110) = c5(29): c7(111) = c5(30):
    c7(114) = c5(31): c7(115) = c5(32): c7(116) = c5(33): c7(117) = c5(34): c7(118) = c5(35):
    c7(121) = c5(36): c7(122) = c5(37): c7(123) = c5(38): c7(124) = c5(39): c7(125) = c5(40):
    c7(128) = c5(41): c7(129) = c5(42): c7(130) = c5(43): c7(131) = c5(44): c7(132) = c5(45):
    c7(135) = c5(46): c7(136) = c5(47): c7(137) = c5(48): c7(138) = c5(49): c7(139) = c5(50):

    c7(156) = c5(51): c7(157) = c5(52): c7(158) = c5(53): c7(159) = c5(54): c7(160) = c5(55):
    c7(163) = c5(56): c7(164) = c5(57): c7(165) = c5(58): c7(166) = c5(59): c7(167) = c5(60):
    c7(170) = c5(61): c7(171) = c5(62): c7(172) = c5(63): c7(173) = c5(64): c7(174) = c5(65):
    c7(177) = c5(66): c7(178) = c5(67): c7(179) = c5(68): c7(180) = c5(69): c7(181) = c5(70):
    c7(184) = c5(71): c7(185) = c5(72): c7(186) = c5(73): c7(187) = c5(74): c7(188) = c5(75):

    c7(205) = c5(76): c7(206) = c5(77): c7(207) = c5(78): c7(208) = c5(79): c7(209) = c5(80):
    c7(212) = c5(81): c7(213) = c5(82): c7(214) = c5(83): c7(215) = c5(84): c7(216) = c5(85):
    c7(219) = c5(86): c7(220) = c5(87): c7(221) = c5(88): c7(222) = c5(89): c7(223) = c5(90):
    c7(226) = c5(91): c7(227) = c5(92): c7(228) = c5(93): c7(229) = c5(94): c7(230) = c5(95):
    c7(233) = c5(96): c7(234) = c5(97): c7(235) = c5(98): c7(236) = c5(99): c7(237) = c5(100):

    c7(254) = c5(101): c7(255) = c5(102): c7(256) = c5(103): c7(257) = c5(104): c7(258) = c5(105):
    c7(261) = c5(106): c7(262) = c5(107): c7(263) = c5(108): c7(264) = c5(109): c7(265) = c5(110):
    c7(268) = c5(111): c7(269) = c5(112): c7(270) = c5(113): c7(271) = c5(114): c7(272) = c5(115):
    c7(275) = c5(116): c7(276) = c5(117): c7(277) = c5(118): c7(278) = c5(119): c7(279) = c5(120):
    c7(282) = c5(121): c7(283) = c5(122): c7(284) = c5(123): c7(285) = c5(124): c7(286) = c5(125):

    Return

End Sub

Vorige Pagina Volgende Pagina About the Author