Vorige Pagina About the Author

' Generates Order 9 Border / Diamond Combinations with 4 x 5 Even Corner Numbers
' Suitable for Concentric Lozenge Squares of order 11

' Tested with Office 365 under Windows 10

Sub Priem9e()

Dim a1(121), a(121), a9(81), a11(121), b(121), b1(121), c(81)

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

    n5 = 0: n9 = 0: n10 = 0: k1 = 1: k2 = 1

    Sheets("Klad1").Select
    
    t1 = Timer

    m1 = 1: m2 = 121: s1 = 549: p2 = 122
    For i1 = 1 To m2
        a1(i1) = i1: b1(i1) = i1
    Next i1

For j100 = 2 To 61

'   Read Diamond Inlay / Order 7 Concentric Square Combination

    For i1 = 1 To 121
        a(i1) = Sheets("DiaLns6").Cells(j100, i1):
        If a(i1) <> 0 Then b(a(i1)) = a(i1)
    Next i1

'   Store Center Square in a9()

    Erase a9
        
    a9(4) = a(16):  a9(5) = a(17):  a9(6) = a(18):
    a9(11) = a(25): a9(12) = a(26): a9(13) = a(27): a9(14) = a(28): a9(15) = a(29): a9(16) = a(30): a9(17) = a(31):
    a9(20) = a(36): a9(21) = a(37): a9(22) = a(38): a9(23) = a(39): a9(24) = a(40): a9(25) = a(41): a9(26) = a(42):

    a9(28) = a(46): a9(29) = a(47): a9(30) = a(48): a9(31) = a(49): a9(32) = a(50): a9(33) = a(51): a9(34) = a(52): 
    a9(35) = a(53): a9(36) = a(54):
    a9(37) = a(57): a9(38) = a(58): a9(39) = a(59): a9(40) = a(60): a9(41) = a(61): a9(42) = a(62): a9(43) = a(63): 
    a9(44) = a(64): a9(45) = a(65):
    a9(46) = a(68): a9(47) = a(69): a9(48) = a(70): a9(49) = a(71): a9(50) = a(72): a9(51) = a(73): a9(52) = a(74): 
    a9(53) = a(75): a9(54) = a(76):

    a9(56) = a(80):  a9(57) = a(81):  a9(58) = a(82):  a9(59) = a(83): a9(60) = a(84): a9(61) = a(85): a9(62) = a(86):
    a9(65) = a(91):  a9(66) = a(92):  a9(67) = a(93):  a9(68) = a(94): a9(69) = a(95): a9(70) = a(96): a9(71) = a(97):
    a9(76) = a(104): a9(77) = a(105): a9(78) = a(106):

'   Complete Border(s)

    n10 = 0
    For j81 = m1 + 1 To m2 - 1 Step 2                                     'a9(81) even
    If b(a1(j81)) = 0 Then b(a1(j81)) = a1(j81): c(81) = a1(j81) Else GoTo 810
    a9(81) = a1(j81)
   
    a9(1) = p2 - a9(81): If b(a9(1)) = 0 Then b(a9(1)) = a9(1): c(1) = a9(1) Else GoTo 10
    
    For j80 = m1 + 1 To m2 - 1 Step 2                                     'a9(80) even
    If b(a1(j80)) = 0 Then b(a1(j80)) = a1(j80): c(80) = a1(j80) Else GoTo 800
    a9(80) = a1(j80)
   
    a9(8) = p2 - a9(80): If b(a9(8)) = 0 Then b(a9(8)) = a9(8): c(8) = a9(8) Else GoTo 80
    
    For j79 = m1 + 1 To m2 - 1 Step 2                                      'a9(79)even
    If b(a1(j79)) = 0 Then b(a1(j79)) = a1(j79): c(79) = a1(j79) Else GoTo 790
    a9(79) = a1(j79)
   
    a9(7) = p2 - a9(79): If b(a9(7)) = 0 Then b(a9(7)) = a9(7): c(7) = a9(7) Else GoTo 70
    
    For j75 = m1 + 1 To m2 - 1 Step 2                                      'a9(75) even
    If b(a1(j75)) = 0 Then b(a1(j75)) = a1(j75): c(75) = a1(j75) Else GoTo 750
    a9(75) = a1(j75)
   
    a9(3) = p2 - a9(75): If b(a9(3)) = 0 Then b(a9(3)) = a9(3): c(3) = a9(3) Else GoTo 30
    
    For j74 = m1 + 1 To m2 - 1 Step 2                                      'a9(74) even
    If b(a1(j74)) = 0 Then b(a1(j74)) = a1(j74): c(74) = a1(j74) Else GoTo 740
    a9(74) = a1(j74)
   
    a9(73) = s1 - a9(74) - a9(75) - a9(76) - a9(77) - a9(78) - a9(79) - a9(80) - a9(81)
    If CInt(a9(73) / 2) <> a9(73) / 2 Then GoTo 730                          'a9(73) even
    If a9(73) < a1(m1) Or a9(73) > a1(m2) Then GoTo 730
    If b1(a9(73)) = 0 Then GoTo 730
    If b(a9(73)) = 0 Then b(a9(73)) = a9(73): c(73) = a9(73) Else GoTo 730
    
    a9(9) = p2 - a9(73): If b(a9(9)) = 0 Then b(a9(9)) = a9(9): c(9) = a9(9) Else GoTo 90
    a9(2) = p2 - a9(74): If b(a9(2)) = 0 Then b(a9(2)) = a9(2): c(2) = a9(2) Else GoTo 20
    
    For j72 = m1 + 1 To m2 - 1 Step 2                                      'a9(72) even
    If b(a1(j72)) = 0 Then b(a1(j72)) = a1(j72): c(72) = a1(j72) Else GoTo 720
    a9(72) = a1(j72)
    
    a9(64) = p2 - a9(72): If b(a9(64)) = 0 Then b(a9(64)) = a9(64): c(64) = a9(64) Else GoTo 640
    
    For j63 = m1 + 1 To m2 - 1 Step 2                                     'a9(63) even
    If b(a1(j63)) = 0 Then b(a1(j63)) = a1(j63): c(63) = a1(j63) Else GoTo 630
    a9(63) = a1(j63)
    
    a9(55) = p2 - a9(63): If b(a9(55)) = 0 Then b(a9(55)) = a9(55): c(55) = a9(55) Else GoTo 550
    
    For j27 = m1 + 1 To m2 - 1 Step 2                                      'a9(27) even
    If b(a1(j27)) = 0 Then b(a1(j27)) = a1(j27): c(27) = a1(j27) Else GoTo 270
    a9(27) = a1(j27)
    
    a9(19) = p2 - a9(27): If b(a9(19)) = 0 Then b(a9(19)) = a9(19): c(19) = a9(19) Else GoTo 190
    
    a9(18) = 7 * p2 / 2 - a9(27) - a9(36) - a9(45) - a9(54) - a9(63) - a9(72) + a9(73) - a9(81)
    If CInt(a9(18) / 2) <> a9(18) / 2 Then GoTo 180                          'a9(18) even
    If a9(18) < a1(m1) Or a9(18) > a1(m2) Then GoTo 180
    If b1(a9(18)) = 0 Then GoTo 180
    If b(a9(18)) = 0 Then b(a9(18)) = a9(18): c(18) = a9(18) Else GoTo 180
    
    a9(10) = p2 - a9(18): If b(a9(10)) = 0 Then b(a9(10)) = a9(10): c(10) = a9(10) Else GoTo 100
    
'                               Exclude solutions with identical numbers

                                GoSub 1800: If fl1 = 0 Then GoTo 5
    
                                n9 = n9 + 1
                                GoSub 2700              'Fill Print Area a11()
                                
                                GoSub 2650              'Print results (squares)
 '                              GoSub 2645              'Print results (selected numbers)

                                Erase b, c: GoTo 1000   'Print only first square

5
        b(c(10)) = 0: c(10) = 0
100     b(c(18)) = 0: c(18) = 0
180     b(c(19)) = 0: c(19) = 0
190     b(c(27)) = 0: c(27) = 0
270     Next j27
        
        b(c(55)) = 0: c(55) = 0
550     b(c(63)) = 0: c(63) = 0
630     Next j63
        
        b(c(64)) = 0: c(64) = 0
640     b(c(72)) = 0: c(72) = 0
720     Next j72
    
        b(c(2)) = 0: c(2) = 0
20      b(c(9)) = 0: c(9) = 0
90      b(c(73)) = 0: c(73) = 0
730     b(c(74)) = 0: c(74) = 0
740     Next j74
        b(c(3)) = 0: c(3) = 0
30      b(c(75)) = 0: c(75) = 0
750     Next j75
        
        b(c(7)) = 0: c(7) = 0
70      b(c(79)) = 0: c(79) = 0
790     Next j79
        b(c(8)) = 0: c(8) = 0
80      b(c(80)) = 0: c(80) = 0
800     Next j80
        b(c(1)) = 0: c(1) = 0
10      b(c(81)) = 0: c(81) = 0
810     Next j81
     
     n10 = 0: Erase b, c
1000 Next j100

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

End

'   Fill Print Area a11()

2700 Erase a11

    a11(13) = a9(1):    a11(14) = a9(2):    a11(15) = a9(3):    a11(16) = a9(4):    a11(17) = a9(5):    a11(18) = a9(6):    
    a11(19) = a9(7):    a11(20) = a9(8):    a11(21) = a9(9):
    a11(24) = a9(10):   a11(25) = a9(11):   a11(26) = a9(12):   a11(27) = a9(13):   a11(28) = a9(14):   a11(29) = a9(15):   
    a11(30) = a9(16):   a11(31) = a9(17):   a11(32) = a9(18):
    a11(35) = a9(19):   a11(36) = a9(20):   a11(37) = a9(21):   a11(38) = a9(22):   a11(39) = a9(23):   a11(40) = a9(24):   
    a11(41) = a9(25):   a11(42) = a9(26):   a11(43) = a9(27):
    a11(46) = a9(28):   a11(47) = a9(29):   a11(48) = a9(30):   a11(49) = a9(31):   a11(50) = a9(32):   a11(51) = a9(33):   
    a11(52) = a9(34):   a11(53) = a9(35):   a11(54) = a9(36):
    a11(57) = a9(37):   a11(58) = a9(38):   a11(59) = a9(39):   a11(60) = a9(40):   a11(61) = a9(41):   a11(62) = a9(42):   
    a11(63) = a9(43):   a11(64) = a9(44):   a11(65) = a9(45):
    a11(68) = a9(46):   a11(69) = a9(47):   a11(70) = a9(48):   a11(71) = a9(49):   a11(72) = a9(50):   a11(73) = a9(51):   
    a11(74) = a9(52):   a11(75) = a9(53):   a11(76) = a9(54):
    a11(79) = a9(55):   a11(80) = a9(56):   a11(81) = a9(57):   a11(82) = a9(58):   a11(83) = a9(59):   a11(84) = a9(60):   
    a11(85) = a9(61):   a11(86) = a9(62):   a11(87) = a9(63):
    a11(90) = a9(64):   a11(91) = a9(65):   a11(92) = a9(66):   a11(93) = a9(67):   a11(94) = a9(68):   a11(95) = a9(69):   
    a11(96) = a9(70):   a11(97) = a9(71):   a11(98) = a9(72):
    a11(101) = a9(73):  a11(102) = a9(74):  a11(103) = a9(75):  a11(104) = a9(76):  a11(105) = a9(77):  a11(106) = a9(78):  
    a11(107) = a9(79):  a11(108) = a9(80):  a11(109) = a9(81):

    a11(6) = a(6): a11(56) = a(56): a11(66) = a(66): a11(116) = a(116):

    Return
     
'   Print results (selected numbers)

2645 For i1 = 1 To 121
         Cells(n9, i1).Value = a11(i1)
     Next i1
     Cells(n9, 122).Value = n9
     Return

'   Print results (squares)

2650 n5 = n5 + 1
     If n5 = 4 Then
         n5 = 1: k1 = k1 + 12: k2 = 1
     Else
         If n9 > 1 Then k2 = k2 + 12
     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 11
         For i2 = 1 To 11
             i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = a11(i3)
         Next i2
     Next i1
    
     Return
     
'   Exclude solutions with identical numbers

1800 fl1 = 1
     For j1 = 1 To 81
        a2 = a9(j1): If a2 = 0 Then GoTo 1810
        For j2 = (1 + j1) To 81
            If a2 = a9(j2) Then fl1 = 0: Return
        Next j2
1810 Next j1
     Return

End Sub

Vorige Pagina About the Author