Vorige Pagina About the Author

' Constructs Associated Compact Pan Magic Squares of order 9, based on Sudoku Comparable Squares
' Quadrant (P2, P3, P4, P5) Magic

' Tested with Office 365 under Windows 10

Sub CnstrSqrs94()

    Dim b(2, 81), a(81), c(81), s9(20)

    Sheets("Klad1").Select
    
y = MsgBox("Locked", vbCritical, "Routine CnstrSqrs94")
End
    
    n4 = 64

    ShtNm1 = "LtnLns934"

    n2 = 0: n9 = 0: k1 = 1: k2 = 1
    s1 = 369
    
    t1 = Timer
    
    For j1 = 2 To n4 + 1
    
    For j2 = 2 To n4 + 1
    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 81
            a(j4) = b(1, j4) + 9 * b(2, j4) + 1
        Next j4
        
        GoSub 300: If fl1 = 0 Then GoTo 20           'Check identical numbers
        GoSub 500: If fl1 = 0 Then GoTo 20           'Check Quadrant Magic Property
                           
'       Check Unique
                          
        If a(1) < a(81) Or a(9) < a(81) Or a(73) < a(81) Then GoTo 20
        If a(73) > a(9) Then GoTo 20
                           
'       n9 = n9 + 1: GoSub 740                       'Print results (selected numbers)
        n9 = n9 + 1: GoSub 750                       'Print results (squares)
'       n9 = n9 + 1: Cells(1, 1).Value = n9          'Counting

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

End
    
'   Read Sudoku Comparable Squares (Line Format)

100 For i1 = 1 To 81
        b(j20, i1) = Sheets(ShtNm1).Cells(j10, i1).Value
    Next i1
    Return
    
'   Check identical numbers
    
300 fl1 = 1
    For i1 = 1 To 81
       a2 = a(i1)
       For i2 = (1 + i1) To 81
           If a2 = a(i2) Then fl1 = 0: Return
       Next i2
    Next i1
    Return
   
'   Check Quadrant Magic

500 fl1 = 1
    
    s9(1) = a(3) + a(11) + a(13) + a(19) + a(21) + a(23) + a(29) + a(31) + a(39)  'P3 Magic
    s9(2) = a(7) + a(15) + a(17) + a(23) + a(25) + a(27) + a(33) + a(35) + a(43)
    s9(3) = a(39) + a(47) + a(49) + a(55) + a(57) + a(59) + a(65) + a(67) + a(75)
    s9(4) = a(43) + a(51) + a(53) + a(59) + a(61) + a(63) + a(69) + a(71) + a(79)
    
    s9(5) = a(1) + a(12) + a(5) + a(20) + a(21) + a(22) + a(37) + a(30) + a(41)   'P4 Magic
    s9(6) = a(5) + a(16) + a(9) + a(24) + a(25) + a(26) + a(41) + a(34) + a(45)
    s9(7) = a(37) + a(48) + a(41) + a(56) + a(57) + a(58) + a(73) + a(66) + a(77)
    s9(8) = a(41) + a(52) + a(45) + a(60) + a(61) + a(62) + a(77) + a(70) + a(81)

    For i1 = 1 To 8
        If s9(i1) <> 369 Then fl1 = 0: Return
    Next i1

    Return
   
'   Print results (selected numbers)

740 Cells(n9, 81).Select
    For i1 = 1 To 81
        Cells(n9, i1).Value = a(i1)
    Next i1
    Cells(n9, 82).Value = j1
    Cells(n9, 83).Value = j2
    Return

'   Print results (squares)

750 n2 = n2 + 1
    If n2 = 5 Then
       n2 = 1: k1 = k1 + 10: k2 = 1
    Else
       If n9 > 1 Then k2 = k2 + 10
    End If
     
    Cells(1, 1).Value = n9
    Cells(k1, k2 + 1).Font.Color = -4165632
    Cells(k1, k2 + 1).Value = n9
   
    i3 = 0
    For i1 = 1 To 9
       For i2 = 1 To 9
           i3 = i3 + 1
           Cells(k1 + i1, k2 + i2).Value = a(i3)
       Next i2
    Next i1
    
    Return
    
End Sub

Vorige Pagina About the Author