Vorige Pagina About the Author

' Generates Eccentric Magic Squares of order 10, based on supplementar rows and columns

' Tested with Office 2007 under Windows 7

Sub MgcSqr10c()

Dim a(100), a1(64), b(100), c(100)

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

'   Defining Pan Magic Square (8 x 8)

a1(1) = 33:  a1(2) = 26:  a1(3) = 35:  a1(4) = 28:  a1(5) = 40:  a1(6) = 31:  a1(7) = 38:  a1(8) = 29:
a1(9) = 48:  a1(10) = 23: a1(11) = 46: a1(12) = 21: a1(13) = 41: a1(14) = 18: a1(15) = 43: a1(16) = 20:
a1(17) = 49: a1(18) = 10: a1(19) = 51: a1(20) = 12: a1(21) = 56: a1(22) = 15: a1(23) = 54: a1(24) = 13:
a1(25) = 64: a1(26) = 7:  a1(27) = 62: a1(28) = 5:  a1(29) = 57: a1(30) = 2:  a1(31) = 59: a1(32) = 4:
a1(33) = 25: a1(34) = 34: a1(35) = 27: a1(36) = 36: a1(37) = 32: a1(38) = 39: a1(39) = 30: a1(40) = 37:
a1(41) = 24: a1(42) = 47: a1(43) = 22: a1(44) = 45: a1(45) = 17: a1(46) = 42: a1(47) = 19: a1(48) = 44:
a1(49) = 9:  a1(50) = 50: a1(51) = 11: a1(52) = 52: a1(53) = 16: a1(54) = 55: a1(55) = 14: a1(56) = 53:
a1(57) = 8:  a1(58) = 63: a1(59) = 6:  a1(60) = 61: a1(61) = 1:  a1(62) = 58: a1(63) = 3:  a1(64) = 60:

'   Defining Eccentric Square (8 x 8)

'a1(1) = 6:   a1(2) = 58:  a1(3) = 55:  a1(4) = 11:  a1(5) = 57:  a1(6) = 9:   a1(7) = 63:  a1(8) = 1:
'a1(9) = 7:   a1(10) = 59: a1(11) = 10: a1(12) = 54: a1(13) = 8:  a1(14) = 56: a1(15) = 2:  a1(16) = 64:
'a1(17) = 62: a1(18) = 3:  a1(19) = 19: a1(20) = 22: a1(21) = 21: a1(22) = 42: a1(23) = 50: a1(24) = 41:
'a1(25) = 53: a1(26) = 12: a1(27) = 43: a1(28) = 46: a1(29) = 44: a1(30) = 23: a1(31) = 15: a1(32) = 24:
'a1(33) = 61: a1(34) = 4:  a1(35) = 17: a1(36) = 48: a1(37) = 32: a1(38) = 35: a1(39) = 38: a1(40) = 25:
'a1(41) = 5:  a1(42) = 60: a1(43) = 20: a1(44) = 45: a1(45) = 37: a1(46) = 26: a1(47) = 31: a1(48) = 36:
'a1(49) = 14: a1(50) = 51: a1(51) = 47: a1(52) = 18: a1(53) = 27: a1(54) = 40: a1(55) = 33: a1(56) = 30:
'a1(57) = 52: a1(58) = 13: a1(59) = 49: a1(60) = 16: a1(61) = 34: a1(62) = 29: a1(63) = 28: a1(64) = 39:


    n2 = 0: n9 = 0
    m1 = 1: m2 = 100: s1 = 505

    
    Sheets("Klad1").Select
    
    t1 = Timer
   
'   Initiate a(..)

For j1 = 23 To 100
    
    Select Case j1
        Case 23 To 30
             a(j1) = a1(j1 - 22) + 18: b(a(j1)) = a(j1): c(j1) = a(j1)
        Case 33 To 40
             a(j1) = a1(j1 - 24) + 18: b(a(j1)) = a(j1): c(j1) = a(j1)
        Case 43 To 50
             a(j1) = a1(j1 - 26) + 18: b(a(j1)) = a(j1): c(j1) = a(j1)
        Case 53 To 60
             a(j1) = a1(j1 - 28) + 18: b(a(j1)) = a(j1): c(j1) = a(j1)
        Case 63 To 70
             a(j1) = a1(j1 - 30) + 18: b(a(j1)) = a(j1): c(j1) = a(j1)
        Case 73 To 80
             a(j1) = a1(j1 - 32) + 18: b(a(j1)) = a(j1): c(j1) = a(j1)
        Case 83 To 90
             a(j1) = a1(j1 - 34) + 18: b(a(j1)) = a(j1): c(j1) = a(j1)
        Case 93 To 100
             a(j1) = a1(j1 - 36) + 18: b(a(j1)) = a(j1): c(j1) = a(j1)
    End Select

Next j1
    
'   Generate Squares
    
For j92 = 94 To 94
    If b(j92) = 0 Then b(j92) = j92: c(92) = j92 Else GoTo 920
    a(92) = j92

    a(91) = 101 - a(92): If a(91) <= 0 Or a(91) > 100 Then GoTo 910
    If b(a(91)) = 0 Then b(a(91)) = a(91): c(91) = a(91) Else GoTo 910

For j82 = 98 To 98
    If b(j82) = 0 Then b(j82) = j82: c(82) = j82 Else GoTo 820
    a(82) = j82

    a(81) = 101 - a(82): If a(81) <= 0 Or a(81) > 100 Then GoTo 810
    If b(a(81)) = 0 Then b(a(81)) = a(81): c(81) = a(81) Else GoTo 810

For j72 = 6 To 6
    If b(j72) = 0 Then b(j72) = j72: c(72) = j72 Else GoTo 720
    a(72) = j72

    a(71) = 101 - a(72): If a(71) <= 0 Or a(71) > 100 Then GoTo 710
    If b(a(71)) = 0 Then b(a(71)) = a(71): c(71) = a(71) Else GoTo 710

For j62 = 10 To 10
    If b(j62) = 0 Then b(j62) = j62: c(62) = j62 Else GoTo 620
    a(62) = j62

    a(61) = 101 - a(62): If a(61) <= 0 Or a(61) > 100 Then GoTo 610
    If b(a(61)) = 0 Then b(a(61)) = a(61): c(61) = a(61) Else GoTo 610

For j52 = 92 To 92
    If b(j52) = 0 Then b(j52) = j52: c(52) = j52 Else GoTo 520
    a(52) = j52

    a(51) = 101 - a(52): If a(51) <= 0 Or a(51) > 100 Then GoTo 510
    If b(a(51)) = 0 Then b(a(51)) = a(51): c(51) = a(51) Else GoTo 510

For j42 = m1 To m2 '13
    If b(j42) = 0 Then b(j42) = j42: c(42) = j42 Else GoTo 420
    a(42) = j42

    a(41) = 101 - a(42): If a(41) <= 0 Or a(41) > 100 Then GoTo 410
    If b(a(41)) = 0 Then b(a(41)) = a(41): c(41) = a(41) Else GoTo 410

For j32 = m1 To m2 '89
    If b(j32) = 0 Then b(j32) = j32: c(32) = j32 Else GoTo 320
    a(32) = j32

    a(31) = 101 - a(32): If a(31) <= 0 Or a(31) > 100 Then GoTo 310
    If b(a(31)) = 0 Then b(a(31)) = a(31): c(31) = a(31) Else GoTo 310

For j22 = m1 To m2 '1
    If b(j22) = 0 Then b(j22) = j22: c(22) = j22 Else GoTo 220
    a(22) = j22

    a(21) = 101 - a(22): If a(21) <= 0 Or a(21) > 100 Then GoTo 210
    If b(a(21)) = 0 Then b(a(21)) = a(21): c(21) = a(21) Else GoTo 210

For j20 = 15 To 15
    If b(j20) = 0 Then b(j20) = j20: c(20) = j20 Else GoTo 200
    a(20) = j20

    a(19) = 404 + a(20) - a(28) - a(37) - a(46) - a(55) - a(64) - a(73) - a(82) - a(91)
    If a(19) <= 0 Or a(19) > 100 Then GoTo 190
    If b(a(19)) = 0 Then b(a(19)) = a(19): c(19) = a(19) Else GoTo 190
    
    a(10) = 101 - a(20): If a(10) <= 0 Or a(10) > 100 Then GoTo 100
    If b(a(10)) = 0 Then b(a(10)) = a(10): c(10) = a(10) Else GoTo 100
    
    a(9) = 101 - a(19): If a(9) <= 0 Or a(9) > 100 Then GoTo 90
    If b(a(9)) = 0 Then b(a(9)) = a(9): c(9) = a(9) Else GoTo 90

For j18 = 87 To 87
    If b(j18) = 0 Then b(j18) = j18: c(18) = j18 Else GoTo 180
    a(18) = j18

    a(8) = 101 - a(18): If a(8) <= 0 Or a(8) > 100 Then GoTo 80
    If b(a(8)) = 0 Then b(a(8)) = a(8): c(8) = a(8) Else GoTo 80

For j17 = 97 To 97
    If b(j17) = 0 Then b(j17) = j17: c(17) = j17 Else GoTo 170
    a(17) = j17

    a(7) = 101 - a(17): If a(7) <= 0 Or a(7) > 100 Then GoTo 70
    If b(a(7)) = 0 Then b(a(7)) = a(7): c(7) = a(7) Else GoTo 70

For j16 = 93 To 93
    If b(j16) = 0 Then b(j16) = j16: c(16) = j16 Else GoTo 160
    a(16) = j16

    a(6) = 101 - a(16): If a(6) <= 0 Or a(6) > 100 Then GoTo 60
    If b(a(6)) = 0 Then b(a(6)) = a(6): c(6) = a(6) Else GoTo 60

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

    a(5) = 101 - a(15): If a(5) <= 0 Or a(5) > 100 Then GoTo 50
    If b(a(5)) = 0 Then b(a(5)) = a(5): c(5) = a(5) Else GoTo 50

For j14 = m1 To m2 '83
    If b(j14) = 0 Then b(j14) = j14: c(14) = j14 Else GoTo 140
    a(14) = j14

    a(4) = 101 - a(14): If a(4) <= 0 Or a(4) > 100 Then GoTo 40
    If b(a(4)) = 0 Then b(a(4)) = a(4): c(4) = a(4) Else GoTo 40

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

    a(12) = 50.5 + 0.5 * (-a(13) - a(14) - a(15) - a(16) - a(17) - a(18) - a(19) - a(20) + a(21) + a(31) + a(41) + a(51) + a(61) + a(71) + a(81) + a(91))
    If Int(a(12)) <> a(12) Then GoTo 120
    If a(12) <= 0 Or a(12) > 100 Then GoTo 120
    If b(a(12)) = 0 Then b(a(12)) = a(12): c(12) = a(12) Else GoTo 120
    
    a(11) = 505 - a(12) - a(13) - a(14) - a(15) - a(16) - a(17) - a(18) - a(19) - a(20)
    If a(11) <= 0 Or a(11) > 100 Then GoTo 110
    If b(a(11)) = 0 Then b(a(11)) = a(11): c(11) = a(11) Else GoTo 110
   
    a(3) = 101 - a(13): If a(3) <= 0 Or a(3) > 100 Then GoTo 30
    If b(a(3)) = 0 Then b(a(3)) = a(3): c(3) = a(3) Else GoTo 30
   
    a(2) = 101 - a(11): If a(2) <= 0 Or a(2) > 100 Then GoTo 20
    If b(a(2)) = 0 Then b(a(2)) = a(2): c(2) = a(2) Else GoTo 20

    a(1) = 101 - a(12): If a(1) <= 0 Or a(1) > 100 Then GoTo 10
    If b(a(1)) = 0 Then b(a(1)) = a(1): c(1) = a(1) Else GoTo 10

    n9 = n9 + 1
    GoSub 2650 'Print results (squares)
'   GoSub 2645 'Print results (selected numbers)

    b(c(1)) = 0: c(1) = 0
10  b(c(2)) = 0: c(2) = 0
20  b(c(3)) = 0: c(3) = 0
30  b(c(11)) = 0: c(11) = 0
110 b(c(12)) = 0: c(12) = 0
120 b(c(13)) = 0: c(13) = 0
130 Next j13

    b(c(4)) = 0: c(4) = 0
40  b(c(14)) = 0: c(14) = 0
140 Next j14
    b(c(5)) = 0: c(5) = 0
50  b(c(15)) = 0: c(15) = 0
150 Next j15
    b(c(6)) = 0: c(6) = 0
60  b(c(16)) = 0: c(16) = 0
160 Next j16
    b(c(7)) = 0: c(7) = 0
70  b(c(17)) = 0: c(17) = 0
170 Next j17
    b(c(8)) = 0: c(8) = 0
80  b(c(18)) = 0: c(18) = 0
180 Next j18

    b(c(9)) = 0: c(9) = 0
90  b(c(10)) = 0: c(10) = 0
100 b(c(19)) = 0: c(19) = 0
190 b(c(20)) = 0: c(20) = 0
200 Next j20

    b(c(21)) = 0: c(21) = 0
210 b(c(22)) = 0: c(22) = 0
220 Next j22
    b(c(31)) = 0: c(31) = 0
310 b(c(32)) = 0: c(32) = 0
320 Next j32
    b(c(41)) = 0: c(41) = 0
410 b(c(42)) = 0: c(42) = 0
420 Next j42
    b(c(51)) = 0: c(51) = 0
510 b(c(52)) = 0: c(52) = 0
520 Next j52
    b(c(61)) = 0: c(61) = 0
610 b(c(62)) = 0: c(62) = 0
620 Next j62
    b(c(71)) = 0: c(71) = 0
710 b(c(72)) = 0: c(72) = 0
720 Next j72
    b(c(81)) = 0: c(81) = 0
810 b(c(82)) = 0: c(82) = 0
820 Next j82
    b(c(91)) = 0: c(91) = 0
910 b(c(92)) = 0: c(92) = 0
920 Next j92
    
    t2 = Timer
    
    t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s1)
    y = MsgBox(t10, 0, "Routine MgcSqr10c")

End

'    Print results (selected numbers)

2645 For i1 = 1 To 100
        Cells(n9, i1).Value = a(i1)
     Next i1
    
     Return

'    Print results (squares)

2650 n2 = n2 + 1
     If n2 = 5 Then
         n2 = 1: k1 = k1 + 11: k2 = 0
     Else
         If n9 > 1 Then k2 = k2 + 11
     End If

     Cells(k1 + 1, k2 + 1).Select

     i3 = 0
     For i1 = 1 To 10
         For i2 = 1 To 10
             i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = a(i3)
         Next i2
     Next i1

     Return

End Sub

Vorige Pagina About the Author