Vorige Pagina About the Author

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

' Tested with Office 365 under Windows 11

Sub SelfOrth8c()

Dim a1(8), a2(64), a(64)
Dim b(8), s(32)

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

n2 = 0: n9 = 0: k1 = 1: k2 = 1
s1 = 28: s2 = 7: s4 = 14

    Sheets("Klad1").Select

    t1 = Timer

For j100 = 1 To 384          'Idemppotent Squares (1 To 384: Associated)
Cells(2, 1).Value = j100

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

For j200 = 1 To 40320        'Series order 8

    For i1 = 1 To 8
        a1(i1) = Sheets("MgcLns8").Cells(j200, i1).Value
    Next i1
    
    For i1 = 1 To 64
        i2 = a2(i1) + 1     'Index in a1()
        a(i1) = a1(i2)
    Next i1
    
''  GoSub  950: If fl1 = 0 Then GoTo 5    'Check Associated
''  GoSub  900: If fl1 = 0 Then GoTo 5    'Check Pan Diagonals    
''  GoSub 1050: If fl1 = 0 Then GoTo 5    'Check Complete

    GoSub 1300: If fl1 = 0 Then GoTo 5    'Check Center Square (4 x 4)
   
    n9 = n9 + 1: ''GoSub 2650             'Print Squares
                   Cells(1, 1).Value = n9 'Counting
    
''End

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 SelfOrth8c")

End

'   Select Pan Magic Squares (Back Check)

900 fl1 = 1

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

    s(9) = a(8) + a(15) + a(22) + a(29) + a(36) + a(43) + a(50) + a(57)
    s(10) = a(7) + a(14) + a(21) + a(28) + a(35) + a(42) + a(49) + a(64)
    s(11) = a(6) + a(13) + a(20) + a(27) + a(34) + a(41) + a(56) + a(63)
    s(12) = a(5) + a(12) + a(19) + a(26) + a(33) + a(48) + a(55) + a(62)
    s(13) = a(4) + a(11) + a(18) + a(25) + a(40) + a(47) + a(54) + a(61)
    s(14) = a(3) + a(10) + a(17) + a(32) + a(39) + a(46) + a(53) + a(60)
    s(15) = a(2) + a(9) + a(24) + a(31) + a(38) + a(45) + a(52) + a(59)
    s(16) = a(1) + a(16) + a(23) + a(30) + a(37) + a(44) + a(51) + a(58)
 
    For j20 = 1 To 16
        If s(j20) <> s1 Then fl1 = 0: Exit For
    Next j20
    
    Return
    
'   Select Associated Magic Squares (Back Check)

950 fl1 = 1

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

'   Select Complete Magic Squares

1050 fl1 = 1

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

'   Check Center Square (4 x 4)
    
1300 fl1 = 1

    s(1) = a(19) + a(20) + a(21) + a(22)
    s(2) = a(27) + a(28) + a(29) + a(30)
    s(3) = a(35) + a(36) + a(37) + a(38)
    s(4) = a(43) + a(44) + a(45) + a(46)

    s(5) = a(19) + a(27) + a(35) + a(43)
    s(6) = a(20) + a(28) + a(36) + a(44)
    s(7) = a(21) + a(29) + a(37) + a(45)
    s(8) = a(22) + a(30) + a(38) + a(46)

    s(9) = a(19) + a(28) + a(37) + a(46)
    s(10) = a(22) + a(29) + a(36) + a(43)
    
    For j20 = 1 To 10
        If s(j20) <> s4 Then fl1 = 0: Exit For
    Next j20

    Return
 
'    Print results (selected numbers)

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

'    Print results (squares)

2650 n2 = n2 + 1
     If n2 = 5 Then
         n2 = 1: k1 = k1 + 9: k2 = 1
     Else
         If n9 > 1 Then k2 = k2 + 9
     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
     
''   Cells(k1, k2 + 7).Value = s4   'Option
    
     i3 = 0
     For i1 = 1 To 8
         For i2 = 1 To 8
             i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = a(i3)
         Next i2
     Next i1
    
     Return

End Sub

Vorige Pagina About the Author