Vorige Pagina About the Author

' Constructs 14 x 14 Composed Magic Squares (Distinct Integers)
' Overlapping Sub Squares

' Tested with Office 365 under Windows 10

' Constructs 14 x 14 Composed Magic Squares (Distinct Integers)
' Overlapping Sub Squares

' Tested with Office 365 under Windows 10

Sub MgcSqrs14b()

    Dim a1(196), a14(196), a(36), b1(196), b(196), c(36), d2(2)

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

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

'   Generate Squares

    Sheets("Klad1").Select
    
    t1 = Timer

For j100 = 1 To 10                          'Read Center Square

    GoSub 2210                              'Redefine Integers
    
'   Read Center Square

        For i1 = 1 To 36
            a(i1) = Sheets("Lines6").Cells(j100, i1).Value
        Next i1

        GoSub 700                           'Assign Center Square
        n32 = 36: GoSub 900                 'Remove used integers a() from available integers b1()
                             
'     Complete  Eccentrc Squares A1/2 (8 x 8)

      d2(1) = a14(63) + a14(78) + a14(93) + a14(108)
      d2(2) = a14(89) + a14(104) + a14(119) + a14(134)

      For n10 = 1 To 2
        
         Erase a, b, c
         GoSub 5000: If fl1 = 0 Then GoTo 1000
        
         Select Case n10
           
               Case 1:
               
                    a14(33) = a(1): a14(34) = a(2):   a14(35) = a(3):   a14(36) = a(4):
                    a14(37) = a(5): a14(38) = a(6):   a14(39) = a(7):   a14(40) = a(8):
                    a14(47) = a(9): a14(48) = a(10):  a14(49) = a(11):  a14(50) = a(12):
                    a14(51) = a(13): a14(52) = a(14): a14(53) = a(15):  a14(54) = a(16):
                                                      a14(67) = a(17):  a14(68) = a(18):
                                                      a14(81) = a(19):  a14(82) = a(20):
                                                      a14(95) = a(21):  a14(96) = a(22):
                                                      a14(109) = a(23): a14(110) = a(24):
                                                      a14(123) = a(25): a14(124) = a(26):
                                                      a14(137) = a(27): a14(138) = a(28):
                    
                    n32 = 28: GoSub 900              'Remove used integers from available integers
                    
               Case 2:
       
                    a14(59) = a(28):  a14(60) = a(27):
                    a14(73) = a(26):  a14(74) = a(25):
                    a14(87) = a(24):  a14(88) = a(23):
                    a14(101) = a(22): a14(102) = a(21):
                    a14(115) = a(20): a14(116) = a(19):
                    a14(129) = a(18): a14(130) = a(17):
                    a14(143) = a(16): a14(144) = a(15): a14(145) = a(14): a14(146) = a(13):
                    a14(147) = a(12): a14(148) = a(11): a14(149) = a(10): a14(150) = a(9):
                    a14(157) = a(8):  a14(158) = a(7):  a14(159) = a(6):  a14(160) = a(5):
                    a14(161) = a(4):  a14(162) = a(3):  a14(163) = a(2):  a14(164) = a(1):
             
                    n32 = 28: GoSub 900              'Remove used integers from available integers
                    
          End Select
        
     Next n10
                             
'    Complete  Eccentrc Squares B1/2 (10 x 10)

     d2(1) = a14(35) + a14(50) + a14(65) + a14(80) + a14(95) + a14(110)
     d2(2) = a14(87) + a14(102) + a14(117) + a14(132) + a14(147) + a14(162)

      For n10 = 1 To 2
        
         Erase a, b, c
         GoSub 7000: If fl1 = 0 Then GoTo 1000
        
         Select Case n10
           
               Case 1:
               
                    a14(5) = a(1):   a14(6) = a(2):   a14(7) = a(3):   a14(8) = a(4):    a14(9) = a(5):
                    a14(10) = a(6):  a14(11) = a(7):  a14(12) = a(8):  a14(13) = a(9):   a14(14) = a(10):
                    a14(19) = a(11): a14(20) = a(12): a14(21) = a(13): a14(22) = a(14):  a14(23) = a(15):
                    a14(24) = a(16): a14(25) = a(17): a14(26) = a(18): a14(27) = a(19):  a14(28) = a(20):
                                                                       a14(41) = a(21):  a14(42) = a(22):
                                                                       a14(55) = a(23):  a14(56) = a(24):
                                                                       a14(69) = a(25):  a14(70) = a(26):
                                                                       a14(83) = a(27):  a14(84) = a(28):
                                                                       a14(97) = a(29):  a14(98) = a(30):
                                                                       a14(111) = a(31): a14(112) = a(32):
                                                                       a14(125) = a(33): a14(126) = a(34):
                                                                       a14(139) = a(35): a14(140) = a(36):
                    
                    n32 = 36: GoSub 900              'Remove used integers from available integers
                    
               Case 2:
       
                    a14(57) = a(36):  a14(58) = a(35):
                    a14(71) = a(34):  a14(72) = a(33):
                    a14(85) = a(32):  a14(86) = a(31):
                    a14(99) = a(30):  a14(100) = a(29):
                    a14(113) = a(28): a14(114) = a(27):
                    a14(127) = a(26): a14(128) = a(25):
                    a14(141) = a(24): a14(142) = a(23):
                    a14(155) = a(22): a14(156) = a(21):
                    a14(169) = a(20): a14(170) = a(19): a14(171) = a(18): a14(172) = a(17): a14(173) = a(16):
                    a14(174) = a(15): a14(175) = a(14): a14(176) = a(13): a14(177) = a(12): a14(178) = a(11):
                    a14(183) = a(10): a14(184) = a(9):  a14(185) = a(8):  a14(186) = a(7):  a14(187) = a(6):
                    a14(188) = a(5):  a14(189) = a(4):  a14(190) = a(3):  a14(191) = a(2):  a14(192) = a(1):
             
                    n32 = 36: GoSub 900              'Remove used integers from available integers
                    
          End Select
        
     Next n10

'    Generate (Pan) Magic Squares Pm1/2 ( 4  x 4)
     
     For n10 = 1 To 2
       
          Erase a, b, c
          GoSub 4000: If fl1 = 0 Then GoTo 1000
        
          Select Case n10
           
               Case 1:
                              
                    a14(1) = a(1):   a14(2) = a(2):   a14(3) = a(3):   a14(4) = a(4):
                    a14(15) = a(5):  a14(16) = a(6):  a14(17) = a(7):  a14(18) = a(8):
                    a14(29) = a(9):  a14(30) = a(10): a14(31) = a(11): a14(32) = a(12):
                    a14(43) = a(13): a14(44) = a(14): a14(45) = a(15): a14(46) = a(16):
                    
                    n32 = 16: GoSub 900                 'Remove used integers from available integers
                   
               Case 2:
                             
                    a14(151) = a(1): a14(152) = a(2): a14(153) = a(3): a14(154) = a(4):
                    a14(165) = a(5): a14(166) = a(6): a14(167) = a(7): a14(168) = a(8):
                    a14(179) = a(9): a14(180) = a(10): a14(181) = a(11): a14(182) = a(12):
                    a14(193) = a(13): a14(194) = a(14): a14(195) = a(15): a14(196) = a(16):
             
                    n32 = 16: GoSub 900                 'Remove used integers from available integers
             
          End Select
        
     Next n10
           
             GoSub 850                                  'Double Check Identical Integers
             If fl1 = 1 Then
                n9 = n9 + 1: GoSub 1650                 'Print results (squares)
'               n9 = n9 + 1: GoSub 1640                 'Print results (lines)
             End If

1000 Erase b1, b, c
     Next j100

    t2 = Timer
    
    t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s11)
    y = MsgBox(t10, 0, "Routine MgcSqrs14b")
    
End

'    Define integer

2210 Pr4 = 197:  nVar = 196
     n10 = 0
        
     s10 = 5 * Pr4                                  'MC10
     s8 = 4 * Pr4                                   'MC8
     s6 = 3 * Pr4                                   'MC6
     s4 = 2 * Pr4                                   'MC4
     s14 = 1379                                     'MC14

     Erase b1
     For i1 = 1 To nVar
         a1(i1) = i1: b1(i1) = i1
     Next i1
     m1 = 1: m2 = nVar
    
     Return

'    Generate Simple Magic Squares M1/2 (4 x 4)

4000 fl1 = 1

For j16 = m1 To m2                                          'a(16)
If b1(a1(j16)) = 0 Then GoTo 4160
If b(a1(j16)) = 0 Then b(a1(j16)) = a1(j16): c(16) = a1(j16) Else GoTo 4160
a(16) = a1(j16)

For j11 = m1 To m2                                          'a(11)
If b1(a1(j11)) = 0 Then GoTo 4110
If b(a1(j11)) = 0 Then b(a1(j11)) = a1(j11): c(11) = a1(j11) Else GoTo 4110
a(11) = a1(j11)

For j6 = m1 To m2                                          'a(6)
If b1(a1(j6)) = 0 Then GoTo 4060
If b(a1(j6)) = 0 Then b(a1(j6)) = a1(j6): c(6) = a1(j6) Else GoTo 4060
a(6) = a1(j6)

a(1) = s4 - a(6) - a(11) - a(16)
If a(1) < a1(m1) Or a(1) > a1(m2) Then GoTo 4010
If b1(a(1)) = 0 Then GoTo 4010
If b(a(1)) = 0 Then b(a(1)) = a(1): c(1) = a(1) Else GoTo 4010

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

For j10 = m1 To m2                                          'a(10)
If b1(a1(j10)) = 0 Then GoTo 4100
If b(a1(j10)) = 0 Then b(a1(j10)) = a1(j10): c(10) = a1(j10) Else GoTo 4100
a(10) = a1(j10)

a(7) = s4 - a(6) - a(10) - a(11)
If a(7) < a1(m1) Or a(7) > a1(m2) Then GoTo 4070
If b1(a(7)) = 0 Then GoTo 4070
If b(a(7)) = 0 Then b(a(7)) = a(7): c(7) = a(7) Else GoTo 4070

a(4) = s4 - a(7) - a(10) - a(13)
If a(4) < a1(m1) Or a(4) > a1(m2) Then GoTo 4040
If b1(a(4)) = 0 Then GoTo 4040
If b(a(4)) = 0 Then b(a(4)) = a(4): c(4) = a(4) Else GoTo 4040

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

a(14) = s4 - a(13) - a(15) - a(16)
If a(14) < a1(m1) Or a(14) > a1(m2) Then GoTo 4140
If b1(a(14)) = 0 Then GoTo 4140
If b(a(14)) = 0 Then b(a(14)) = a(14): c(14) = a(14) Else GoTo 4140

a(3) = s4 - a(7) - a(11) - a(15)
If a(3) < a1(m1) Or a(3) > a1(m2) Then GoTo 4030
If b1(a(3)) = 0 Then GoTo 4030
If b(a(3)) = 0 Then b(a(3)) = a(3): c(3) = a(3) Else GoTo 4030

a(2) = s4 - a(1) - a(3) - a(4)
If a(2) < a1(m1) Or a(2) > a1(m2) Then GoTo 4020
If b1(a(2)) = 0 Then GoTo 4020
If b(a(2)) = 0 Then b(a(2)) = a(2): c(2) = a(2) Else GoTo 4020

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

a(9) = s4 - a(10) - a(11) - a(12)
If a(9) < a1(m1) Or a(9) > a1(m2) Then GoTo 4090
If b1(a(9)) = 0 Then GoTo 4090
If b(a(9)) = 0 Then b(a(9)) = a(9): c(9) = a(9) Else GoTo 4090

a(8) = s4 - a(4) - a(12) - a(16)
If a(8) < a1(m1) Or a(8) > a1(m2) Then GoTo 4080
If b1(a(8)) = 0 Then GoTo 4080
If b(a(8)) = 0 Then b(a(8)) = a(8): c(8) = a(8) Else GoTo 4080

a(5) = s4 - a(1) - a(9) - a(13)
If a(5) < a1(m1) Or a(5) > a1(m2) Then GoTo 4050
If b1(a(5)) = 0 Then GoTo 4050
If b(a(5)) = 0 Then b(a(5)) = a(5): c(5) = a(5) Else GoTo 4050

'                 Exclude solutions with identical numbers (M4)
    
                  n32 = 16: GoSub 800: If fl1 = 0 Then GoTo 5
    
     Return

5
     b(c(5)) = 0: c(5) = 0
4050 b(c(8)) = 0: c(8) = 0
4080 b(c(9)) = 0: c(9) = 0
4090 b(c(12)) = 0: c(12) = 0
4120 Next j12

     b(c(2)) = 0: c(2) = 0
4020 b(c(3)) = 0: c(3) = 0
4030 b(c(14)) = 0: c(14) = 0
4140 b(c(15)) = 0: c(15) = 0
4150 Next j15

     b(c(4)) = 0: c(4) = 0
4040 b(c(7)) = 0: c(7) = 0
4070 b(c(10)) = 0: c(10) = 0
4100 Next j10
     b(c(13)) = 0: c(13) = 0
4130 Next j13

     b(c(1)) = 0: c(1) = 0
4010 b(c(6)) = 0: c(6) = 0
4060 Next j6
     b(c(11)) = 0: c(11) = 0
4110 Next j11
     b(c(16)) = 0: c(16) = 0
4160 Next j16

Return
     
'    Complete  Eccentrc Squares A1/2 (8 x 8)

5000 fl1 = 1

'   Determine Main Diagonal and related pairs

    For j1 = m1 To m2
    If b1(a1(j1)) = 0 Then GoTo 10
    If b(a1(j1)) = 0 Then b(a1(j1)) = a1(j1): c(1) = a1(j1) Else GoTo 10
    a(1) = a1(j1)
    
    a(9) = Pr4 - a(1): If b(a(9)) = 0 Then b(a(9)) = a(9): c(9) = a(9) Else GoTo 90
   
    For j2 = m2 To m1 Step -1
    If b1(a1(j2)) = 0 Then GoTo 20
    If b(a1(j2)) = 0 Then b(a1(j2)) = a1(j2): c(2) = a1(j2) Else GoTo 20
    a(2) = a1(j2)
  
    a(10) = Pr4 - a(2): If b(a(10)) = 0 Then b(a(10)) = a(10): c(10) = a(10) Else GoTo 100
  
    For j25 = m1 To m2
    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(26) = Pr4 - a(25): If b(a(26)) = 0 Then b(a(26)) = a(26): c(26) = a(26) Else GoTo 260
    
    a(28) = s8 - d2(n10) - a(25) - a(10) - a(1)
    If a(28) < a1(m1) Or a(28) > a1(m2) Then GoTo 280:
    If b1(a(28)) = 0 Then GoTo 280
    If b(a(28)) = 0 Then b(a(28)) = a(28): c(28) = a(28) Else GoTo 280
    
    a(27) = Pr4 - a(28): If b(a(27)) = 0 Then b(a(27)) = a(27): c(27) = a(27) Else GoTo 270

'   Determine remainder of the pairs

    For j7 = m1 To m2
    If b1(a1(j7)) = 0 Then GoTo 70
    If b(a1(j7)) = 0 Then b(a1(j7)) = a1(j7): c(7) = a1(j7) Else GoTo 70
    a(7) = a1(j7)
    
    a(16) = Pr4 - a(7): If b(a(16)) = 0 Then b(a(16)) = a(16): c(16) = a(16) Else GoTo 160

    For j8 = m2 To m1 Step -1
    If b1(a1(j8)) = 0 Then GoTo 80
    If b(a1(j8)) = 0 Then b(a1(j8)) = a1(j8): c(8) = a1(j8) Else GoTo 80
    a(8) = a1(j8)
    
    a(15) = Pr4 - a(8): If b(a(15)) = 0 Then b(a(15)) = a(15): c(15) = a(15) Else GoTo 150

    For j3 = m2 To m1 Step -1
    If b1(a1(j3)) = 0 Then GoTo 30
    If b(a1(j3)) = 0 Then b(a1(j3)) = a1(j3): c(3) = a1(j3) Else GoTo 30
    a(3) = a1(j3)
    
    a(11) = Pr4 - a(3): If b(a(11)) = 0 Then b(a(11)) = a(11): c(11) = a(11) Else GoTo 110

    For j4 = m1 To m2
    If b1(a1(j4)) = 0 Then GoTo 40
    If b(a1(j4)) = 0 Then b(a1(j4)) = a1(j4): c(4) = a1(j4) Else GoTo 40
    a(4) = a1(j4)
    
    a(12) = Pr4 - a(4): If b(a(12)) = 0 Then b(a(12)) = a(12): c(12) = a(12) Else GoTo 120

    For j5 = m1 To m2
    If b1(a1(j5)) = 0 Then GoTo 50
    If b(a1(j5)) = 0 Then b(a1(j5)) = a1(j5): c(5) = a1(j5) Else GoTo 50
    a(5) = a1(j5)
    
    a(13) = Pr4 - a(5): If b(a(13)) = 0 Then b(a(13)) = a(13): c(13) = a(13) Else GoTo 130

    a(6) = s8 - a(1) - a(2) - a(3) - a(4) - a(5) - a(7) - a(8)
    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(14) = Pr4 - a(6): If b(a(14)) = 0 Then b(a(14)) = a(14): c(14) = a(14) Else GoTo 140

    For j17 = m2 To m1 Step -1
    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(18) = Pr4 - a(17): If b(a(18)) = 0 Then b(a(18)) = a(18): c(18) = a(18) Else GoTo 180

    For j19 = m1 To m2
    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(20) = Pr4 - a(19): If b(a(20)) = 0 Then b(a(20)) = a(20): c(20) = a(20) Else GoTo 200

    For j21 = m2 To m1 Step -1
    If b1(a1(j21)) = 0 Then GoTo 210
    If b(a1(j21)) = 0 Then b(a1(j21)) = a1(j21): c(21) = a1(j21) Else GoTo 210
    a(21) = a1(j21)
    
    a(22) = Pr4 - a(21): If b(a(22)) = 0 Then b(a(22)) = a(22): c(22) = a(22) Else GoTo 220

    a(23) = s8 - a(7) - a(15) - a(17) - a(19) - a(21) - a(25) - a(27)
    If a(23) < a1(m1) Or a(23) > a1(m2) Then GoTo 230:
    If b1(a(23)) = 0 Then GoTo 230
    If b(a(23)) = 0 Then b(a(23)) = a(23): c(23) = a(23) Else GoTo 230
    
    a(24) = Pr4 - a(23): If b(a(24)) = 0 Then b(a(24)) = a(24): c(24) = a(24) Else GoTo 240

Return

    b(c(24)) = 0: c(24) = 0
240 b(c(23)) = 0: c(23) = 0
230 b(c(22)) = 0: c(22) = 0
220 b(c(21)) = 0: c(21) = 0
210 Next j21

    b(c(20)) = 0: c(20) = 0
200 b(c(19)) = 0: c(19) = 0
190 Next j19

    b(c(18)) = 0: c(18) = 0
180 b(c(17)) = 0: c(17) = 0
170 Next j17

    b(c(14)) = 0: c(14) = 0
140 b(c(6)) = 0: c(6) = 0
60  b(c(13)) = 0: c(13) = 0
130 b(c(5)) = 0: c(5) = 0
50  Next j5

    b(c(12)) = 0: c(12) = 0
120 b(c(4)) = 0: c(4) = 0
40  Next j4
    b(c(11)) = 0: c(11) = 0
110 b(c(3)) = 0: c(3) = 0
30  Next j3

    b(c(15)) = 0: c(15) = 0
150 b(c(8)) = 0: c(8) = 0
80  Next j8
    b(c(16)) = 0: c(16) = 0
160 b(c(7)) = 0: c(7) = 0
70  Next j7

     b(c(27)) = 0: c(27) = 0
270  b(c(28)) = 0: c(28) = 0
280  b(c(26)) = 0: c(26) = 0
260  b(c(25)) = 0: c(25) = 0
250  Next j25

    b(c(10)) = 0: c(10) = 0
100 b(c(2)) = 0: c(2) = 0
20  Next j2

   b(c(9)) = 0: c(9) = 0
90 b(c(1)) = 0: c(1) = 0
10 Next j1

     fl1 = 0
     Return

'    Complete  Eccentrc Squares B1/2 (10 x 10)

7000 fl1 = 1

'    Determine Main Diagonal and related pairs

    For j1 = m1 To m2
    If b1(a1(j1)) = 0 Then GoTo 7010
    If b(a1(j1)) = 0 Then b(a1(j1)) = a1(j1): c(1) = a1(j1) Else GoTo 7010
    a(1) = a1(j1)
    
    a(11) = Pr4 - a(1): If b(a(11)) = 0 Then b(a(11)) = a(11): c(11) = a(11) Else GoTo 7110
   
    For j2 = m2 To m1 Step -1
    If b1(a1(j2)) = 0 Then GoTo 7020
    If b(a1(j2)) = 0 Then b(a1(j2)) = a1(j2): c(2) = a1(j2) Else GoTo 7020
    a(2) = a1(j2)
  
    a(12) = Pr4 - a(2): If b(a(12)) = 0 Then b(a(12)) = a(12): c(12) = a(12) Else GoTo 7120
  
    For j33 = m1 To m2
    If b1(a1(j33)) = 0 Then GoTo 7330
    If b(a1(j33)) = 0 Then b(a1(j33)) = a1(j33): c(33) = a1(j33) Else GoTo 7330
    a(33) = a1(j33)
    
    a(34) = Pr4 - a(33): If b(a(34)) = 0 Then b(a(34)) = a(34): c(34) = a(34) Else GoTo 7340
    
    a(36) = s10 - d2(n10) - a(33) - a(12) - a(1)
    If a(36) < a1(m1) Or a(36) > a1(m2) Then GoTo 7360:
    If b1(a(36)) = 0 Then GoTo 7360
    If b(a(36)) = 0 Then b(a(36)) = a(36): c(36) = a(36) Else GoTo 7360
    
    a(35) = Pr4 - a(36): If b(a(35)) = 0 Then b(a(35)) = a(35): c(35) = a(35) Else GoTo 7350

    For j3 = m2 To m1 Step -1
    If b1(a1(j3)) = 0 Then GoTo 7030
    If b(a1(j3)) = 0 Then b(a1(j3)) = a1(j3): c(3) = a1(j3) Else GoTo 7030
    a(3) = a1(j3)
    
    a(13) = Pr4 - a(3): If b(a(13)) = 0 Then b(a(13)) = a(13): c(13) = a(13) Else GoTo 7130

    For j4 = m1 To m2
    If b1(a1(j4)) = 0 Then GoTo 7040
    If b(a1(j4)) = 0 Then b(a1(j4)) = a1(j4): c(4) = a1(j4) Else GoTo 7040
    a(4) = a1(j4)
    
    a(14) = Pr4 - a(4): If b(a(14)) = 0 Then b(a(14)) = a(14): c(14) = a(14) Else GoTo 7140

    For j5 = m2 To m1 Step -1
    If b1(a1(j5)) = 0 Then GoTo 7050
    If b(a1(j5)) = 0 Then b(a1(j5)) = a1(j5): c(5) = a1(j5) Else GoTo 7050
    a(5) = a1(j5)
    
    a(15) = Pr4 - a(5): If b(a(15)) = 0 Then b(a(15)) = a(15): c(15) = a(15) Else GoTo 7150

    For j6 = m1 To m2
    If b1(a1(j6)) = 0 Then GoTo 7060
    If b(a1(j6)) = 0 Then b(a1(j6)) = a1(j6): c(6) = a1(j6) Else GoTo 7060
    a(6) = a1(j6)
    
    a(16) = Pr4 - a(6): If b(a(16)) = 0 Then b(a(16)) = a(16): c(16) = a(16) Else GoTo 7160

    For j7 = m2 To m1 Step -1
    If b1(a1(j7)) = 0 Then GoTo 7070
    If b(a1(j7)) = 0 Then b(a1(j7)) = a1(j7): c(7) = a1(j7) Else GoTo 7070
    a(7) = a1(j7)
    
    a(17) = Pr4 - a(7): If b(a(17)) = 0 Then b(a(17)) = a(17): c(17) = a(17) Else GoTo 7170

    For j9 = m2 To m1 Step -1
    If b1(a1(j9)) = 0 Then GoTo 7090
    If b(a1(j9)) = 0 Then b(a1(j9)) = a1(j9): c(9) = a1(j9) Else GoTo 7090
    a(9) = a1(j9)
    
    a(20) = Pr4 - a(9): If b(a(20)) = 0 Then b(a(20)) = a(20): c(20) = a(20) Else GoTo 7200

    For j10 = m1 To m2
    If b1(a1(j10)) = 0 Then GoTo 7100
    If b(a1(j10)) = 0 Then b(a1(j10)) = a1(j10): c(10) = a1(j10) Else GoTo 7100
    a(10) = a1(j10)
    
    a(19) = Pr4 - a(10): If b(a(19)) = 0 Then b(a(19)) = a(19): c(19) = a(19) Else GoTo 7190

    a(8) = s10 - a(1) - a(2) - a(3) - a(4) - a(5) - a(6) - a(7) - a(9) - a(10)
    If a(8) < a1(m1) Or a(8) > a1(m2) Then GoTo 7080:
    If b1(a(8)) = 0 Then GoTo 7080
    If b(a(8)) = 0 Then b(a(8)) = a(8): c(8) = a(8) Else GoTo 7080
    
    a(18) = Pr4 - a(8): If b(a(18)) = 0 Then b(a(18)) = a(18): c(18) = a(18) Else GoTo 7180

    For j21 = m2 To m1 Step -1
    If b1(a1(j21)) = 0 Then GoTo 7210
    If b(a1(j21)) = 0 Then b(a1(j21)) = a1(j21): c(21) = a1(j21) Else GoTo 7210
    a(21) = a1(j21)
    
    a(22) = Pr4 - a(21): If b(a(22)) = 0 Then b(a(22)) = a(22): c(22) = a(22) Else GoTo 7220

    For j23 = m1 To m2
    If b1(a1(j23)) = 0 Then GoTo 7230
    If b(a1(j23)) = 0 Then b(a1(j23)) = a1(j23): c(23) = a1(j23) Else GoTo 7230
    a(23) = a1(j23)
    
    a(24) = Pr4 - a(23): If b(a(24)) = 0 Then b(a(24)) = a(24): c(24) = a(24) Else GoTo 7240

    For j25 = m2 To m1 Step -1
    If b1(a1(j25)) = 0 Then GoTo 7250
    If b(a1(j25)) = 0 Then b(a1(j25)) = a1(j25): c(25) = a1(j25) Else GoTo 7250
    a(25) = a1(j25)
    
    a(26) = Pr4 - a(25): If b(a(26)) = 0 Then b(a(26)) = a(26): c(26) = a(26) Else GoTo 7260

    For j27 = m1 To m2
    If b1(a1(j27)) = 0 Then GoTo 7270
    If b(a1(j27)) = 0 Then b(a1(j27)) = a1(j27): c(27) = a1(j27) Else GoTo 7270
    a(27) = a1(j27)
    
    a(28) = Pr4 - a(27): If b(a(28)) = 0 Then b(a(28)) = a(28): c(28) = a(28) Else GoTo 7280

    For j29 = m2 To m1 Step -1
    If b1(a1(j29)) = 0 Then GoTo 7290
    If b(a1(j29)) = 0 Then b(a1(j29)) = a1(j29): c(29) = a1(j29) Else GoTo 7290
    a(29) = a1(j29)
    
    a(30) = Pr4 - a(29): If b(a(30)) = 0 Then b(a(30)) = a(30): c(30) = a(30) Else GoTo 7300

    a(31) = s10 - a(9) - a(19) - a(21) - a(23) - a(25) - a(27) - a(29) - a(33) - a(35)
    If a(31) < a1(m1) Or a(31) > a1(m2) Then GoTo 7310:
    If b1(a(31)) = 0 Then GoTo 7310
    If b(a(31)) = 0 Then b(a(31)) = a(31): c(31) = a(31) Else GoTo 7310
    
    a(32) = Pr4 - a(31): If b(a(32)) = 0 Then b(a(32)) = a(32): c(32) = a(32) Else GoTo 7320

Return

     b(c(32)) = 0: c(32) = 0
7320 b(c(31)) = 0: c(31) = 0
7310 b(c(30)) = 0: c(30) = 0
7300 b(c(29)) = 0: c(29) = 0
7290 Next j29

     b(c(28)) = 0: c(28) = 0
7280 b(c(27)) = 0: c(27) = 0
7270 Next j27

     b(c(26)) = 0: c(26) = 0
7260 b(c(25)) = 0: c(25) = 0
7250 Next j25

     b(c(24)) = 0: c(24) = 0
7240 b(c(23)) = 0: c(23) = 0
7230 Next j23

     b(c(22)) = 0: c(22) = 0
7220 b(c(21)) = 0: c(21) = 0
7210 Next j21

     b(c(18)) = 0: c(18) = 0
7180 b(c(8)) = 0: c(8) = 0
7080 b(c(19)) = 0: c(19) = 0
7190 b(c(10)) = 0: c(10) = 0
7100 Next j10

     b(c(20)) = 0: c(20) = 0
7200 b(c(9)) = 0: c(9) = 0
7090 Next j9

     b(c(17)) = 0: c(17) = 0
7170 b(c(7)) = 0: c(7) = 0
7070 Next j7

     b(c(16)) = 0: c(16) = 0
7160 b(c(6)) = 0: c(6) = 0
7060 Next j6

     b(c(15)) = 0: c(15) = 0
7150 b(c(5)) = 0: c(5) = 0
7050 Next j5

     b(c(14)) = 0: c(14) = 0
7140 b(c(4)) = 0: c(4) = 0
7040 Next j4

     b(c(13)) = 0: c(13) = 0
7130 b(c(3)) = 0: c(3) = 0
7030 Next j3

      b(c(35)) = 0: c(35) = 0
7350  b(c(36)) = 0: c(36) = 0
7360  b(c(34)) = 0: c(34) = 0
7340  b(c(33)) = 0: c(33) = 0
7330  Next j33

     b(c(12)) = 0: c(12) = 0
7120 b(c(2)) = 0: c(2) = 0
7020 Next j2

     b(c(11)) = 0: c(11) = 0
7110 b(c(1)) = 0: c(1) = 0
7010 Next j1

     fl1 = 0
     Return
     
'    Print results (Selecyted Integers)

1640
     For i1 = 1 To 196
         Cells(n9, i1).Value = a14(i1)
     Next i1
     Cells(n9, 197).Value = s14
     Cells(n9, 198).Value = j100
     Return

'    Print results (Squares)

1650 n2 = n2 + 1
     If n2 = 3 Then
         n2 = 1: k1 = k1 + 15: k2 = 1
     Else
         If n9 > 1 Then k2 = k2 + 15
     End If

     Cells(k1, k2 + 1).Select
     Cells(k1, k2 + 1).Font.Color = -4165632
     Cells(k1, k2 + 1).Value = j100
    
     i3 = 0
     For i1 = 1 To 14
         For i2 = 1 To 14
             i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = a14(i3)
         Next i2
     Next i1
     Return

'    Assign Center Square

700
     a14(61) = a(1):   a14(62) = a(2):   a14(63) = a(3):   a14(64) = a(4):   a14(65) = a(5):   a14(66) = a(6):
     a14(75) = a(7):   a14(76) = a(8):   a14(77) = a(9):   a14(78) = a(10):  a14(79) = a(11):  a14(80) = a(12):
     a14(89) = a(13):  a14(90) = a(14):  a14(91) = a(15):  a14(92) = a(16):  a14(93) = a(17):  a14(94) = a(18):
     a14(103) = a(19): a14(104) = a(20): a14(105) = a(21): a14(106) = a(22): a14(107) = a(23): a14(108) = a(24):
     a14(117) = a(25): a14(118) = a(26): a14(119) = a(27): a14(120) = a(28): a14(121) = a(29): a14(122) = a(30):
     a14(131) = a(31): a14(132) = a(32): a14(133) = a(33): a14(134) = a(34): a14(135) = a(35): a14(136) = a(36):

     Return

'    Exclude solutions with identical numbers a()

800  fl1 = 1
     For j1 = 1 To n32
        a20 = a(j1)
        For j2 = (1 + j1) To n32
            If a20 = a(j2) Then fl1 = 0: Return
        Next j2
     Next j1
     Return

'    Exclude solutions with identical numbers a14()

850  fl1 = 1
     For j1 = 1 To 196
        a20 = a14(j1): If a20 = 0 Then GoTo 855
        For j2 = (1 + j1) To 196
            If a20 = a14(j2) Then fl1 = 0: Return
        Next j2
855  Next j1
     Return

'    Remove used integers a() from available integers b1()

900  For i1 = 1 To n32
         b1(a(i1)) = 0
     Next i1
     Return

End Sub

Vorige Pagina About the Author