Vorige Pagina About the Author

' Generates Concentric Magic Squares of order 7 with 4 Even Corner Numbers
' Suitable for Concentric Lozenge Squares of order 11

' Tested with Office 2007 under Windows 7

Sub Priem7d()

Dim a1(121), a(25), a7(49), b(121), b1(121), c7(49)

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

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

    Sheets("Klad1").Select
    
    t1 = Timer

    m1 = 1: m2 = 121: s7 = 427: s2 = 122
    For i1 = 1 To m2
        a1(i1) = i1: b1(i1) = i1
    Next i1

For j100 = 2 To 201

'   Read Center Square

    For i1 = 1 To 25
        a(i1) = Sheets("Center5").Cells(j100, i1):  b(a(i1)) = a(i1)
    Next i1

'   store Center Square in a7()

    Erase a7
    a7(9) = a(1):   a7(10) = a(2):  a7(11) = a(3):  a7(12) = a(4):  a7(13) = a(5):
    a7(16) = a(6):  a7(17) = a(7):  a7(18) = a(8):  a7(19) = a(9):  a7(20) = a(10):
    a7(23) = a(11): a7(24) = a(12): a7(25) = a(13): a7(26) = a(14): a7(27) = a(15):
    a7(30) = a(16): a7(31) = a(17): a7(32) = a(18): a7(33) = a(19): a7(34) = a(20):
    a7(37) = a(21): a7(38) = a(22): a7(39) = a(23): a7(40) = a(24): a7(41) = a(25):

'   Complete Border(s)

n10 = 0
For j49 = m1 + 1 To m2 - 1 Step 2                                            'a7(49) even
If b(a1(j49)) = 0 Then b(a1(j49)) = a1(j49): c7(49) = a1(j49) Else GoTo 2490
a7(49) = a1(j49)
     
a7(1) = s2 - a7(49): If b(a7(1)) = 0 Then b(a7(1)) = a7(1): c7(1) = a7(1) Else GoTo 2010
       
For j48 = m1 To m2 Step 2                                                    'a7(48) odd
If b(a1(j48)) = 0 Then b(a1(j48)) = a1(j48): c7(48) = a1(j48) Else GoTo 2480
a7(48) = a1(j48)

a7(6) = s2 - a7(48): If b(a7(6)) = 0 Then b(a7(6)) = a7(6): c7(6) = a7(6) Else GoTo 2060

For j47 = m1 To m2 Step 2                                                    'a7(47) odd
If b(a1(j47)) = 0 Then b(a1(j47)) = a1(j47): c7(47) = a1(j47) Else GoTo 2470
a7(47) = a1(j47)

a7(5) = s2 - a7(47): If b(a7(5)) = 0 Then b(a7(5)) = a7(5): c7(5) = a7(5) Else GoTo 2050
     
For j46 = m1 To m2 Step 2                                                    'a7(46) odd
If b(a1(j46)) = 0 Then b(a1(j46)) = a1(j46): c7(46) = a1(j46) Else GoTo 2460
a7(46) = a1(j46)

a7(4) = s2 - a7(46): If b(a7(4)) = 0 Then b(a7(4)) = a7(4): c7(4) = a7(4) Else GoTo 2040
     
For j45 = m1 To m2 Step 2                                                    'a7(45) odd
If b(a1(j45)) = 0 Then b(a1(j45)) = a1(j45): c7(45) = a1(j45) Else GoTo 2450
a7(45) = a1(j45)

a7(3) = s2 - a7(45): If b(a7(3)) = 0 Then b(a7(3)) = a7(3): c7(3) = a7(3) Else GoTo 2030
     
For j44 = m1 To m2 Step 2                                                    'a7(44) odd
If b(a1(j44)) = 0 Then b(a1(j44)) = a1(j44): c7(44) = a1(j44) Else GoTo 2440
a7(44) = a1(j44)
          
a7(43) = s7 - a7(44) - a7(45) - a7(46) - a7(47) - a7(48) - a7(49)
If CInt(a7(43) / 2) <> a7(43) / 2 Then GoTo 2430                             'a7(43) even
If a7(43) < a1(m1) Or a7(43) > a1(m2) Then GoTo 2430
If b1(a7(43)) = 0 Then GoTo 2430
If b(a7(43)) = 0 Then b(a7(43)) = a7(43): c7(43) = a7(43) Else GoTo 2430

a7(7) = s2 - a7(43): If b(a7(7)) = 0 Then b(a7(7)) = a7(7): c7(7) = a7(7) Else GoTo 2070
a7(2) = s2 - a7(44): If b(a7(2)) = 0 Then b(a7(2)) = a7(2): c7(2) = a7(2) Else GoTo 2020
     
For j42 = m1 To m2 Step 2                                                    'a7(42) odd
If b(a1(j42)) = 0 Then b(a1(j42)) = a1(j42): c7(42) = a1(j42) Else GoTo 2420
a7(42) = a1(j42)

a7(36) = s2 - a7(42): If b(a7(36)) = 0 Then b(a7(36)) = a7(36): c7(36) = a7(36) Else GoTo 2360

For j35 = m1 To m2 Step 2                                                    'a7(35) odd
If b(a1(j35)) = 0 Then b(a1(j35)) = a1(j35): c7(35) = a1(j35) Else GoTo 2350
a7(35) = a1(j35)

a7(29) = s2 - a7(35): If b(a7(29)) = 0 Then b(a7(29)) = a7(29): c7(29) = a7(29) Else GoTo 2290
     
For j28 = m1 To m2 Step 2                                                    'a7(28) odd
If b(a1(j28)) = 0 Then b(a1(j28)) = a1(j28): c7(28) = a1(j28) Else GoTo 2280
a7(28) = a1(j28)

a7(22) = s2 - a7(28): If b(a7(22)) = 0 Then b(a7(22)) = a7(22): c7(22) = a7(22) Else GoTo 2220

For j21 = m1 To m2 Step 2                                                    'a7(21) odd
If b(a1(j21)) = 0 Then b(a1(j21)) = a1(j21): c7(21) = a1(j21) Else GoTo 2210
a7(21) = a1(j21)
     
a7(15) = s2 - a7(21): If b(a7(15)) = 0 Then b(a7(15)) = a7(15): c7(15) = a7(15) Else GoTo 2150
     
a7(14) = -3 * s2 / 2 + a7(15) + a7(22) + a7(29) + a7(36) + a7(43) - a7(49)
If CInt(a7(14) / 2) = a7(14) / 2 Then GoTo 2140                              'a14(14) odd
If a7(14) < a1(m1) Or a7(14) > a1(m2) Then GoTo 2140
If b1(a7(14)) = 0 Then GoTo 2140
If b(a7(14)) = 0 Then b(a7(14)) = a7(14): c7(14) = a7(14) Else GoTo 2140

a7(8) = s2 - a7(14): If b(a7(8)) = 0 Then b(a7(8)) = a7(8): c7(8) = a7(8) Else GoTo 2080

                            GoSub 800: If fl1 = 0 Then GoTo 5      '(Back Check)

'                           n9 = n9 + 1: GoSub 640   'Print results (selected numbers)
                            n9 = n9 + 1: GoSub 660   'Print results (squares)
                            
                            Erase b, c7: GoTo 500    'Print only first square

5
     b(c7(8)) = 0: c7(8) = 0
2080 b(c7(14)) = 0: c7(14) = 0
2140 b(c7(15)) = 0: c7(15) = 0
2150 b(c7(21)) = 0: c7(21) = 0
2210 Next j21

     b(c7(22)) = 0: c7(22) = 0
2220 b(c7(28)) = 0: c7(28) = 0
2280 Next j28

     b(c7(29)) = 0: c7(29) = 0
2290 b(c7(35)) = 0: c7(35) = 0
2350 Next j35

     b(c7(36)) = 0: c7(36) = 0
2360 b(c7(42)) = 0: c7(42) = 0
2420 Next j42

     b(c7(2)) = 0: c7(2) = 0
2020 b(c7(7)) = 0: c7(7) = 0
2070 b(c7(43)) = 0: c7(43) = 0
2430 b(c7(44)) = 0: c7(44) = 0
2440 Next j44

     b(c7(3)) = 0: c7(3) = 0
2030 b(c7(45)) = 0: c7(45) = 0
2450 Next j45

     b(c7(4)) = 0: c7(4) = 0
2040 b(c7(46)) = 0: c7(46) = 0
2460 Next j46

     b(c7(5)) = 0: c7(5) = 0
2050 b(c7(47)) = 0: c7(47) = 0
2470 Next j47

     b(c7(6)) = 0: c7(6) = 0
2060 b(c7(48)) = 0: c7(48) = 0
2480 Next j48

     b(c7(1)) = 0: c7(1) = 0
2010 b(c7(49)) = 0: c7(49) = 0
2490 Next j49

    Erase b, c7
500 Next j100

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

End

'   Print results (selected numbers)

640 For i1 = 1 To 49
        Cells(n9, i1).Value = a7(i1)
    Next i1
    Cells(n9, 50).Value = n9
    Cells(n9, 50).Select
    Return

'   Print Square a7()

660 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, k2 + 1).Select
    Cells(k1, k2 + 1).Font.Color = -4165632
    Cells(k1, k2 + 1).Value = n9
    
    i3 = 0
    For i1 = 1 To 7
        For i2 = 1 To 7
            i3 = i3 + 1
            Cells(k1 + i1, k2 + i2).Value = a7(i3)
        Next i2
    Next i1

    Return
    
'   Exclude solutions with identical numbers

800 fl1 = 1
    For j1 = 1 To 49
       a2 = a7(j1): If a2 = 0 Then GoTo 810
       For j2 = (1 + j1) To 49
           If a2 = a7(j2) Then fl1 = 0: Return
       Next j2
810 Next j1
    Return

End Sub

Vorige Pagina About the Author