Vorige Pagina About the Author

' Constructs Prime Number Magic Squares of order 6

' Tested with Office 2007 under Windows 7

Sub CnstrSqrs6b()

Dim a2(6), b2(6), a(36), b(36), c(36)
   
y = MsgBox("Locked", vbExclamation, "Routine CnstrSqrs6b")
End

    n2 = 0: n9 = 0: k1 = 1: k2 = 1
    
    Sheets("Klad1").Select

    t1 = Timer
    
For j1 = 2 To 25

'   Read (Balanced) Magic Lines

    For j2 = 1 To 6: a2(j2) = Sheets("Att63").Cells(j1, j2).Value: Next j2
    For j2 = 1 To 6: b2(j2) = Sheets("Att63").Cells(j1, j2 + 7).Value: Next j2
    s1 = Sheets("Att63").Cells(j1, 17).Value
    
'   Construct squares a() and b()

    GoSub 200

'   Calculate Square c()

    For j2 = 1 To 36
        c(j2) = a(j2) + b(j2)
    Next j2

'   Print results

    GoSub 800: If fl1 = 0 Then GoTo 70

'   n9 = n9 + 1: GoSub 640  'Lines
    n9 = n9 + 1: GoSub 650  'Squares

70 Next j1
    
    t2 = Timer
    
    t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s1)
    y = MsgBox(t10, vbInformation, "Routine CnstrSqrs6b")
    
End

'   Construct squares a() and b()

200

'   Simple Magic (Symmetric Diagonals)

''    a(1) = a2(6):   a(2) = a2(2):   a(3) = a2(3):   a(4) = a2(4):   a(5) = a2(5):   a(6) = a2(1):
''    a(7) = a2(1):   a(8) = a2(5):   a(9) = a2(3):   a(10) = a2(4):  a(11) = a2(2):  a(12) = a2(6):
''    a(13) = a2(1):  a(14) = a2(2):  a(15) = a2(4):  a(16) = a2(3):  a(17) = a2(5):  a(18) = a2(6):
''    a(19) = a2(6):  a(20) = a2(2):  a(21) = a2(4):  a(22) = a2(3):  a(23) = a2(5):  a(24) = a2(1):
''    a(25) = a2(1):  a(26) = a2(5):  a(27) = a2(4):  a(28) = a2(3):  a(29) = a2(2):  a(30) = a2(6):
''    a(31) = a2(6):  a(32) = a2(5):  a(33) = a2(3):  a(34) = a2(4):  a(35) = a2(2):  a(36) = a2(1):
    
''    b(1) = b2(1):   b(2) = b2(6):   b(3) = b2(1):   b(4) = b2(6):   b(5) = b2(6):   b(6) = b2(1):
''    b(7) = b2(2):   b(8) = b2(2):   b(9) = b2(5):   b(10) = b2(5):  b(11) = b2(2):  b(12) = b2(5):
''    b(13) = b2(4):  b(14) = b2(3):  b(15) = b2(3):  b(16) = b2(3):  b(17) = b2(4):  b(18) = b2(4):
''    b(19) = b2(3):  b(20) = b2(4):  b(21) = b2(4):  b(22) = b2(4):  b(23) = b2(3):  b(24) = b2(3):
''    b(25) = b2(5):  b(26) = b2(5):  b(27) = b2(2):  b(28) = b2(2):  b(29) = b2(5):  b(30) = b2(2):
''    b(31) = b2(6):  b(32) = b2(1):  b(33) = b2(6):  b(34) = b2(1):  b(35) = b2(1):  b(36) = b2(6):

'   Square of the Sun

''    a(1) = a2(1):   a(2) = a2(5):   a(3) = a2(4):   a(4) = a2(3):   a(5) = a2(2):   a(6) = a2(6):
''    a(7) = a2(6):   a(8) = a2(2):   a(9) = a2(4):   a(10) = a2(3):  a(11) = a2(5):  a(12) = a2(1):
''    a(13) = a2(6):  a(14) = a2(5):  a(15) = a2(3):  a(16) = a2(4):  a(17) = a2(2):  a(18) = a2(1):
''    a(19) = a2(1):  a(20) = a2(5):  a(21) = a2(3):  a(22) = a2(4):  a(23) = a2(2):  a(24) = a2(6):
''    a(25) = a2(6):  a(26) = a2(2):  a(27) = a2(3):  a(28) = a2(4):  a(29) = a2(5):  a(30) = a2(1):
''    a(31) = a2(1):  a(32) = a2(2):  a(33) = a2(4):  a(34) = a2(3):  a(35) = a2(5):  a(36) = a2(6):

''    b(1) = b2(1):   b(2) = b2(6):   b(3) = b2(6):   b(4) = b2(1):   b(5) = b2(6):   b(6) = b2(1):
''    b(7) = b2(5):   b(8) = b2(2):   b(9) = b2(5):   b(10) = b2(5):  b(11) = b2(2):  b(12) = b2(2):
''    b(13) = b2(4):  b(14) = b2(4):  b(15) = b2(3):  b(16) = b2(3):  b(17) = b2(3):  b(18) = b2(4):
''    b(19) = b2(3):  b(20) = b2(3):  b(21) = b2(4):  b(22) = b2(4):  b(23) = b2(4):  b(24) = b2(3):
''    b(25) = b2(2):  b(26) = b2(5):  b(27) = b2(2):  b(28) = b2(2):  b(29) = b2(5):  b(30) = b2(5):
''    b(31) = b2(6):  b(32) = b2(1):  b(33) = b2(1):  b(34) = b2(6):  b(35) = b2(1):  b(36) = b2(6):

'   Almost Associated

    a(1) = a2(6):   a(2) = a2(2):   a(3) = a2(4):   a(4) = a2(1):   a(5) = a2(5):   a(6) = a2(3):
    a(7) = a2(3):   a(8) = a2(5):   a(9) = a2(1):   a(10) = a2(6):  a(11) = a2(2):  a(12) = a2(4):
    a(13) = a2(4):  a(14) = a2(2):  a(15) = a2(3):  a(16) = a2(1):  a(17) = a2(5):  a(18) = a2(6):
    a(19) = a2(1):  a(20) = a2(2):  a(21) = a2(6):  a(22) = a2(4):  a(23) = a2(5):  a(24) = a2(3):
    a(25) = a2(3):  a(26) = a2(5):  a(27) = a2(1):  a(28) = a2(6):  a(29) = a2(2):  a(30) = a2(4):
    a(31) = a2(4):  a(32) = a2(5):  a(33) = a2(6):  a(34) = a2(3):  a(35) = a2(2):  a(36) = a2(1):

    b(1) = b2(6):   b(2) = b2(1):   b(3) = b2(6):   b(4) = b2(3):   b(5) = b2(1):   b(6) = b2(4):
    b(7) = b2(2):   b(8) = b2(5):   b(9) = b2(2):   b(10) = b2(2):  b(11) = b2(5):  b(12) = b2(5):
    b(13) = b2(1):  b(14) = b2(4):  b(15) = b2(3):  b(16) = b2(6):  b(17) = b2(4):  b(18) = b2(3):
    b(19) = b2(4):  b(20) = b2(3):  b(21) = b2(1):  b(22) = b2(4):  b(23) = b2(3):  b(24) = b2(6):
    b(25) = b2(5):  b(26) = b2(2):  b(27) = b2(5):  b(28) = b2(5):  b(29) = b2(2):  b(30) = b2(2):
    b(31) = b2(3):  b(32) = b2(6):  b(33) = b2(4):  b(34) = b2(1):  b(35) = b2(6):  b(36) = b2(1):

    Return

'   Exclude solutions with identical numbers

800 fl1 = 1
    For j10 = 1 To 36
       c2 = c(j10)
       For j20 = (1 + j10) To 36
           If c2 = c(j20) Then fl1 = 0: Return
       Next j20
    Next j10
    Return

'   Print results (selected numbers)

640 Cells(n9, 37).Select
    For i1 = 1 To 36
        Cells(n9, i1).Value = c(i1)
    Next i1
    Cells(n9, 37).Value = n9
    Return

'   Print results (squares)

650 n1 = n1 + 1
    If n1 = 4 Then
        n1 = 1: k1 = k1 + 7: k2 = 1
    Else
        If n9 > 1 Then k2 = k2 + 7
    End If
    
    Cells(k1, k2 + 1).Select
    Cells(k1, k2 + 1).Font.Color = -4165632
    Cells(k1, k2 + 1).Value = s1
    
    i3 = 0
    For i1 = 1 To 6
        For i2 = 1 To 6
            i3 = i3 + 1
            Cells(k1 + i1, k2 + i2).Value = c(i3)
        Next i2
    Next i1
    Return
    
End Sub

Vorige Pagina About the Author