Vorige Pagina Volgende Pagina About the Author

' Generates Inlaid Magic Squares of order 11, Integers 1 ... 121, Part I

' Tested with Office 2007 under Windows 7

Sub Priem11k1()

   Dim a(121), b(121), c(121), a5(5), b4(4), s(4)

y = MsgBox("Locked", vbCritical, "Routine Priem11k1")
End
 
    n1 = 0: n2 = 0: n3 = 0: k1 = 1: k2 = 1: n9 = 0: n10 = 0

    Sheets("Klad1").Select
    
    t1 = Timer

For j100 = 2 To 463               'Read Magic Lines Order 5 (Test Case = 333)

    For i1 = 1 To 5
        a5(i1) = Sheets("MgcLns5").Cells(j100, i1).Value
    Next i1    
    
    For j200 = 2 To 331           'Read Magic Lines Order 4 (Test Case = 235)
    
        For i1 = 1 To 4
            b4(i1) = Sheets("MgcLns4").Cells(j200, i1).Value
        Next i1
         
        GoSub 600    'Construct Square a()
        GoSub 700    'Construct Square b()
        
        For i1 = 1 To 121
            
            Select Case i1
                Case 1 To 11, 111 To 121, 12, 22, 23, 33, 34, 44, 45, 55, 56, 66, 67, 77, 78, 88, 89, 99, 100, 110
                Case Else
                    c(i1) = a(i1) + 11 * b(i1) + 1
            End Select
       
        Next i1
        
        GoSub 1300: If fl1 = 0 Then GoTo 5  'Check Identical Numbers

''      n9 = n9 + 1: GoSub 1650             'Print Square
        n9 = n9 + 1: GoSub 1640             'Print Lines
5
    Next j200

Next j100

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

End

'    Construct Square a()

600
     a(13) = a5(1):  a(14) = a5(2):  a(15) = a5(3):  a(16) = a5(4):  a(17) = a5(5):
     a(24) = a5(3):  a(25) = a5(4):  a(26) = a5(5):  a(27) = a5(1):  a(28) = a5(2):
     a(35) = a5(5):  a(36) = a5(1):  a(37) = a5(2):  a(38) = a5(3):  a(39) = a5(4):
     a(46) = a5(2):  a(47) = a5(3):  a(48) = a5(4):  a(49) = a5(5):  a(50) = a5(1):
     a(57) = a5(4):  a(58) = a5(5):  a(59) = a5(1):  a(60) = a5(2):  a(61) = a5(3):
     
                          a(62) = 10 - a(60):  a(63) = 10 - a(59):  a(64) = 10 - a(58):  a(65) = 10 - a(57):
     a(72) = 10 - a(50):  a(73) = 10 - a(49):  a(74) = 10 - a(48):  a(75) = 10 - a(47):  a(76) = 10 - a(46):
     a(83) = 10 - a(39):  a(84) = 10 - a(38):  a(85) = 10 - a(37):  a(86) = 10 - a(36):  a(87) = 10 - a(35):
     a(94) = 10 - a(28):  a(95) = 10 - a(27):  a(96) = 10 - a(26):  a(97) = 10 - a(25):  a(98) = 10 - a(24):
     a(105) = 10 - a(17): a(106) = 10 - a(16): a(107) = 10 - a(15): a(108) = 10 - a(14): a(109) = 10 - a(13):
     
     a(18) = b4(1):  a(19) = b4(2):  a(20) = b4(3):  a(21) = b4(4):
     a(29) = b4(4):  a(30) = b4(3):  a(31) = b4(2):  a(32) = b4(1):
     a(40) = b4(2):  a(41) = b4(1):  a(42) = b4(4):  a(43) = b4(3):
     a(51) = b4(3):  a(52) = b4(4):  a(53) = b4(1):  a(54) = b4(2):

     a(68) = 10 - a(54):  a(69) = 10 - a(53):  a(70) = 10 - a(52):  a(71) = 10 - a(51):
     a(79) = 10 - a(43):  a(80) = 10 - a(42):  a(81) = 10 - a(41):  a(82) = 10 - a(40):
     a(90) = 10 - a(32):  a(91) = 10 - a(31):  a(92) = 10 - a(30):  a(93) = 10 - a(29):
     a(101) = 10 - a(21): a(102) = 10 - a(20): a(103) = 10 - a(19): a(104) = 10 - a(18):

     Return
     
'    Construct Square b()

700
     b(13) = a(13):  b(14) = a(24):  b(15) = a(35):  b(16) = a(46):  b(17) = a(57):
     b(24) = a(14):  b(25) = a(25):  b(26) = a(36):  b(27) = a(47):  b(28) = a(58):
     b(35) = a(15):  b(36) = a(26):  b(37) = a(37):  b(38) = a(48):  b(39) = a(59):
     b(46) = a(16):  b(47) = a(27):  b(48) = a(38):  b(49) = a(49):  b(50) = a(60):
     b(57) = a(17):  b(58) = a(28):  b(59) = a(39):  b(60) = a(50):  b(61) = a(61):

                     b(62) = a(72):  b(63) = a(83):  b(64) = a(94):  b(65) = a(105):
     b(72) = a(62):  b(73) = a(73):  b(74) = a(84):  b(75) = a(95):  b(76) = a(106):
     b(83) = a(63):  b(84) = a(74):  b(85) = a(85):  b(86) = a(96):  b(87) = a(107):
     b(94) = a(64):  b(95) = a(75):  b(96) = a(86):  b(97) = a(97):  b(98) = a(108):
     b(105) = a(65): b(106) = a(76): b(107) = a(87): b(108) = a(98): b(109) = a(109):

     b(18) = 10 - a(18): b(19) = 10 - a(29): b(20) = 10 - a(40): b(21) = 10 - a(51):
     b(29) = 10 - a(19): b(30) = 10 - a(30): b(31) = 10 - a(41): b(32) = 10 - a(52):
     b(40) = 10 - a(20): b(41) = 10 - a(31): b(42) = 10 - a(42): b(43) = 10 - a(53):
     b(51) = 10 - a(21): b(52) = 10 - a(32): b(53) = 10 - a(43): b(54) = 10 - a(54):

     b(68) = 10 - a(68):  b(69) = 10 - a(79):  b(70) = 10 - a(90):  b(71) = 10 - a(101):
     b(79) = 10 - a(69):  b(80) = 10 - a(80):  b(81) = 10 - a(91):  b(82) = 10 - a(102):
     b(90) = 10 - a(70):  b(91) = 10 - a(81):  b(92) = 10 - a(92):  b(93) = 10 - a(103):
     b(101) = 10 - a(71): b(102) = 10 - a(82): b(103) = 10 - a(93): b(104) = 10 - a(104):

     Return

'    Exclude solutions with identical numbers

1300 fl1 = 1
     For j10 = 1 To 121
       c2 = c(j10): If c2 = 0 Then GoTo 1310
       For j20 = (1 + j10) To 121
           If c2 = c(j20) Then fl1 = 0: Return
       Next j20
1310 Next j10

     Return

'    Print results (lines)

1640 Cells(n9, 127).Select
     For i1 = 1 To 121
         Cells(n9, i1).Value = c(i1)
     Next i1
     
     s(1) = c(13) + c(14) + c(15) + c(16) + c(17):
     s(2) = c(18) + c(19) + c(20) + c(21):
     s(3) = c(68) + c(69) + c(70) + c(71):
     s(4) = c(61) + c(62) + c(63) + c(64) + c(65):
     For i1 = 1 To 4
        Cells(n9, 121 + i1).Value = s(i1)
     Next i1
     
     Cells(n9, 126).Value = j100
     Cells(n9, 127).Value = j200
     Cells(n9, 127).Select
     Return

'    Print results (squares)

1650 n2 = n2 + 1
     If n2 = 2 Then
         n2 = 1: k1 = k1 + 12: k2 = 1
     Else
         If n9 > 1 Then k2 = k2 + 12
     End If
     
     Cells(k1, k2 + 1).Select
     Cells(k1, k2 + 1).Font.Color = -4165632
     Cells(k1, k2 + 1).Value = "a" + CStr(n9)
    
     Cells(k1, k2 + 1 + 12).Select
     Cells(k1, k2 + 1 + 12).Font.Color = -4165632
     Cells(k1, k2 + 1 + 12).Value = "b" + CStr(n9)
    
     Cells(k1, k2 + 1 + 24).Select
     Cells(k1, k2 + 1 + 24).Font.Color = -4165632
     Cells(k1, k2 + 1 + 24).Value = "c" + CStr(n9)
    
     i3 = 0
     For i1 = 1 To 11
         For i2 = 1 To 11
             i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = a(i3)
             Cells(k1 + i1, k2 + i2 + 12).Value = b(i3)
             Cells(k1 + i1, k2 + i2 + 24).Value = c(i3)
         Next i2
     Next i1
    
     Return

End Sub

Vorige Pagina Volgende Pagina About the Author