Vorige Pagina About the Author

' Constructs Magic Squares of order 17
' Based on (Semi) Latin Squares of order 17

' Tested with Office 365 under Windows 10

Sub CnstrSqrs17a()
   
    Dim b(2, 289), a(289), TagNr(2)

    Sheets("Klad1").Select
    
y = MsgBox("Locked", vbCritical, "Routine CnstrSqrs17a")
End

    n2 = 0: n9 = 0: k1 = 1: k2 = 1
    s1 = 2465
    
    t1 = Timer

'   Latin Lines Sorted: L2 ... L8, R2 ... R8 (Base Case)

    For j1 = 1 To 7
    Cells(n9 + 1, 290).Select: Cells(n9 + 1, 290).Value = j1

    For j2 = 1 To 14
    If j2 = j1 Then GoTo 20
        
        j10 = j1: j20 = 1: GoSub 100                 'Read Sudoku Comparable Square 1
        j10 = j2: j20 = 2: GoSub 100                 'Read Sudoku Comparable Square 2
        
        For j4 = 1 To 289
            a(j4) = b(1, j4) + 17 * b(2, j4) + 1
        Next j4
        
        GoSub 300: If fl1 = 0 Then GoTo 20           'Check identical numbers
                           
'       n9 = n9 + 1: GoSub 740                       'Print results (selected numbers)
        n9 = n9 + 1: GoSub 750                       'Print results (squares)

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

End
    
'   Read Sudoku Comparable Squares (Line Format)

100 For i1 = 1 To 289
        b(j20, i1) = Sheets("LatLns17").Cells(j10, i1).Value
    Next i1
    TagNr(j20) = Sheets("LatLns17").Cells(j10, 290).Value
    Return
    
'   Check identical numbers
    
300 fl1 = 1: n10 = 0
    For i1 = 1 To 289
       a2 = a(i1)
       For i2 = (1 + i1) To 289
           If a2 = a(i2) Then fl1 = 0: Return
           ''If a2 = a(i2) Then n10 = n10 + 1
       Next i2
    Next i1
    Return
    
'   Print results (selected numbers)

740 Cells(n9, 170).Select
    For i1 = 1 To 289
        Cells(n9, i1).Value = a(i1)
    Next i1
    Cells(n9, 170).Value = j1
    Cells(n9, 171).Value = j2
''    Cells(n9, 172).Value = n10
    Return

'   Print results (squares)

750 n2 = n2 + 1
    If n2 = 2 Then
       n2 = 1: k1 = k1 + 18: k2 = 1
    Else
       If n9 > 1 Then k2 = k2 + 18
    End If
     
    Cells(k1, k2 + 1).Select
    Cells(k1, k2 + 1).Font.Color = -4165632
    Cells(k1, k2 + 1).Value = n9
    Cells(k1, k2 + 2).Value = TagNr(1) ''j1
    Cells(k1, k2 + 6).Value = TagNr(2) ''j2
   
    i3 = 0
    For i1 = 1 To 17
       For i2 = 1 To 17
           i3 = i3 + 1
           Cells(k1 + i1, k2 + i2).Value = a(i3)
       Next i2
    Next i1
    
    Return
    
End Sub

Vorige Pagina About the Author