Vorige Pagina About the Author

' Generates SelfOrthogonal Latin Diagonal Squares (7 x 7)
' Based on Idempotent Squares (Permutations)

' Tested with Office 365 under Windows 11

Sub SelfOrth7c()

Dim a1(7), a2(49), a(49)
Dim b(7), s(24)

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

n2 = 0: n9 = 0: k1 = 1: k2 = 1
s1 = 21: s2 = 6

    Sheets("Klad1").Select

    t1 = Timer

For j100 = 1 To 64                      'Idemppotent Squares

    For i1 = 1 To 49
        a2(i1) = Sheets("BaseLns7").Cells(j100, i1).Value
    Next i1

For j200 = 1 To 5040                    'Series order 7

    For i1 = 1 To 7
        a1(i1) = Sheets("MgcLns7").Cells(j200, i1).Value
    Next i1
    
    For i1 = 1 To 49
        i2 = a2(i1) + 1                 'Index in a1()
        a(i1) = a1(i2)
    Next i1
    
''  GoSub 900 : If fl1 = 0 Then GoTo 5   'Check Pan Diagonals
''  GoSub 950 : If fl1 = 0 Then GoTo 5   'Check Associated
''  GoSub 1200: If fl1 = 0 Then GoTo 5   'Check Diamond Inlay

   
''  n9 = n9 + 1: GoSub 2650             'Print Squares
''  n9 = n9 + 1: GoSub 2645             'Print lines
    n9 = n9 + 1: Cells(1, 1).Value = n9 'Counting

5

2000 Next j200
1000 Next j100

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

End

'   Select Pan Magic Squares (Back Check)

900 fl1 = 1

'   Check Pan Diagonals
   
    b(1) = a(1): b(2) = a(9): b(3) = a(17): b(4) = a(25): b(5) = a(33): b(6) = a(41): b(7) = a(49):  
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(2): b(2) = a(10): b(3) = a(18): b(4) = a(26): b(5) = a(34): b(6) = a(42): b(7) = a(43): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(3): b(2) = a(11): b(3) = a(19): b(4) = a(27): b(5) = a(35): b(6) = a(36): b(7) = a(44): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(4): b(2) = a(12): b(3) = a(20): b(4) = a(28): b(5) = a(29): b(6) = a(37): b(7) = a(45): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(5): b(2) = a(13): b(3) = a(21): b(4) = a(22): b(5) = a(30): b(6) = a(38): b(7) = a(46): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(6): b(2) = a(14): b(3) = a(15): b(4) = a(23): b(5) = a(31): b(6) = a(39): b(7) = a(47): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(7): b(2) = a(8): b(3) = a(16): b(4) = a(24): b(5) = a(32): b(6) = a(40): b(7) = a(48):  
    GoSub 860: If fl1 = 0 Then Return
    
    b(1) = a(43): b(2) = a(37): b(3) = a(31): b(4) = a(25): b(5) = a(19): b(6) = a(13): b(7) = a(7): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(44): b(2) = a(38): b(3) = a(32): b(4) = a(26): b(5) = a(20): b(6) = a(14): b(7) = a(1): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(45): b(2) = a(39): b(3) = a(33): b(4) = a(27): b(5) = a(21): b(6) = a(8): b(7) = a(2):  
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(46): b(2) = a(40): b(3) = a(34): b(4) = a(28): b(5) = a(15): b(6) = a(9): b(7) = a(3):  
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(47): b(2) = a(41): b(3) = a(35): b(4) = a(22): b(5) = a(16): b(6) = a(10): b(7) = a(4): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(48): b(2) = a(42): b(3) = a(29): b(4) = a(23): b(5) = a(17): b(6) = a(11): b(7) = a(5): 
    GoSub 860: If fl1 = 0 Then Return
    b(1) = a(49): b(2) = a(36): b(3) = a(30): b(4) = a(24): b(5) = a(18): b(6) = a(12): b(7) = a(6): 
    GoSub 860: If fl1 = 0 Then Return
    
    Return
    
860 fl1 = 1
    For j1 = 1 To 7
       b20 = b(j1)
       For j2 = (1 + j1) To 7
           If b20 = b(j2) Then fl1 = 0: Return
       Next j2
    Next j1
    Return
    
'   Select Associated Magic Squares (Back Check)

950 fl1 = 1

        s(1) = a(1) + a(49):   s(2) = a(2) + a(48):   s(3) = a(3) + a(47):   s(4) = a(4) + a(46)
        s(5) = a(5) + a(45):   s(6) = a(6) + a(44):   s(7) = a(7) + a(43):   s(8) = a(8) + a(42)
        s(9) = a(9) + a(41):   s(10) = a(10) + a(40): s(11) = a(11) + a(39): s(12) = a(12) + a(38)
        s(13) = a(13) + a(37): s(14) = a(14) + a(36): s(15) = a(15) + a(35): s(16) = a(16) + a(34)
        s(17) = a(17) + a(33): s(18) = a(18) + a(32): s(19) = a(19) + a(31): s(20) = a(20) + a(30)
        s(21) = a(21) + a(29): s(22) = a(22) + a(28): s(23) = a(23) + a(27): s(24) = a(24) + a(26)
    
        For j20 = 1 To 24
            If s(j20) <> s2 Then fl1 = 0: Exit For
        Next j20
        
    Return

'   Check Diamond Inlay Order 3 (Center)

1200 fl1 = 1

    s(1) = a(23) + a(17) + a(11)
    s(2) = a(31) + a(25) + a(19)
    s(3) = a(39) + a(33) + a(27)
        
    s(4) = a(27) + a(19) + a(11)
    s(5) = a(33) + a(25) + a(17)
    s(6) = a(39) + a(31) + a(23)
        
    s(7) = a(23) + a(25) + a(27)
    s(8) = a(11) + a(25) + a(39)

    s3 = s(1)
    For j20 = 1 To 8
        If s(j20) <> s3 Then fl1 = 0: Exit For
    Next j20

    Return

'   Print results (selected numbers)

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

'    Print results (squares)

2650 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).Font.Color = -4165632
     Cells(k1, k2 + 1).Value = n9
     
     Cells(k1, k2 + 2).Value = j100
     Cells(k1, k2 + 3).Value = j200
   
     i3 = 0
     For i1 = 1 To 7
         For i2 = 1 To 7
             i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = a(i3)
         Next i2
     Next i1
    
     Return

End Sub

Vorige Pagina About the Author