Vorige Pagina About the Author

' Constructs Orthogonal Semi-Latin - and Magic Squares of order 6

' Tested with Office 2007 under Windows 7

Sub CnstrSqrs6a()

    Dim b(2, 36), a(36), m(36)

    Sheets("Klad1").Select
    
y = MsgBox("Locked", vbExclamation, "Routine CnstrSqrs6a")
End

    n2 = 0: n9 = 0: k1 = 1: k2 = 1
    s1 = 111
    
    t1 = Timer
    
    For j1 = 2 To 5
    For j2 = 2 To 5
    If j2 = j1 Then GoTo 20
        
        j10 = j1: j20 = 1: GoSub 100                        'Read Semi-Latin Square 1
        j10 = j2: j20 = 2: GoSub 100                        'Read Semi-Latin Square 2
        
        For j4 = 1 To 36
            a(j4) = b(1, j4) + 6 * b(2, j4) + 1             'Semi  Magic Square
''          m(j4) = CStr(b(1, j4)) + ", " + CStr(b(2, j4))  'Orthogonal  Square
        Next j4
        
        GoSub 300: If fl1 = 0 Then GoTo 20                  'Check identical numbers
''      GoSub 200: If nDia <> 2 Then GoTo 20
                           
'       n9 = n9 + 1: GoSub 640 'Print results (selected numbers)
        n9 = n9 + 1: GoSub 650 'Print results (squares)
'       n9 = n9 + 1: GoSub 600 'Print results (Euler Squares)

''End

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

End

'   Read Latin Squares (Line Format)

100 For i1 = 1 To 36
        b(j20, i1) = Sheets("Lines6").Cells(j10, i1).Value
    Next i1
    
    Return
    
'   Check Diagonals
    
200 nDia = 0
    
    If a(1) + a(8) + a(15) + a(22) + a(29) + a(36) = 111 Then nDia = nDia + 1
    If a(6) + a(11) + a(16) + a(21) + a(26) + a(31) = 111 Then nDia = nDia + 1
    
    Return
    
'   Check identical numbers
    
300 fl1 = 1
    For i1 = 1 To 36
       a2 = a(i1)
       For i2 = (1 + i1) To 36
           If a2 = a(i2) Then fl1 = 0: Return
       Next i2
    Next i1
    Return
    
'   Print results (Orthogonal Squares)

600 n1 = n1 + 1
    If n1 = 5 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 = n9
    
    i3 = 0
    For i1 = 1 To 6
        For i2 = 1 To 6
            i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = m(i3)
        Next i2
    Next i1
    Return
    
'   Print results (selected numbers)

640 Cells(n9, 40).Select
    For i1 = 1 To 36
        Cells(n9, i1).Value = a(i1)
    Next i1
    Cells(n9, 37).Value = n9
    Cells(n9, 38).Value = j1 - 1
    Cells(n9, 39).Value = j2 - 1
'   Cells(n9, 40).Value = nDia
    Return

'   Print results (squares)

650 n1 = n1 + 1
    If n1 = 5 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 = n9
    
    i3 = 0
    For i1 = 1 To 6
        For i2 = 1 To 6
            i3 = i3 + 1
            Cells(k1 + i1, k2 + i2).Value = a(i3)
        Next i2
    Next i1
    Return
    
End Sub

Vorige Pagina About the Author