Vorige Pagina About the Author

' Generates Semi-Latin Squares of order 12
' Pan Magic Sub Squares, Barink Restrictions

' Tested with Office 365 under Windows 10

Sub CompLat12a()

Dim a(144), b(12)

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

n2 = 0: n9 = 0
m1 = 0: m2 = 11: s1 = 66
k1 = 1: k2 = 1

Pr12 = 11

'   Generate data
    
    Sheets("Klad1").Select
    
    t1 = Timer

For j144 = m1 To m2                                            'a(144)
a(144) = j144

For j143 = m1 To m2                                            'a(143)
a(143) = j143

For j142 = m1 To m2                                            'a(142)
a(142) = j142

a(141) = 2 * Pr12 - a(142) - a(143) - a(144): If a(141) < 0 Or a(141) > 11 Then GoTo 1420

For j140 = m1 To m2                                            'a(140)
a(140) = j140

a(139) = -a(140) + a(143) + a(144): If a(139) < 0 Or a(139) > 11 Then GoTo 1400
a(138) = -a(140) + a(142) + a(144): If a(138) < 0 Or a(138) > 11 Then GoTo 1400
a(137) = 2 * Pr12 + a(140) - a(142) - a(143) - 2 * a(144): If a(137) < 0 Or a(137) > 11 Then GoTo 1400

For j136 = m1 To m2                                             'a(136)
a(136) = j136

a(135) = -a(136) + a(143) + a(144): j135 = a(135): If a(135) < 0 Or a(135) > 11 Then GoTo 1360
a(134) = -a(136) + a(142) + a(144): j134 = a(134): If a(134) < 0 Or a(134) > 11 Then GoTo 1360
a(133) = 2 * Pr12 + a(136) - a(142) - a(143) - 2 * a(144): j133 = a(133): If a(133) < 0 Or a(133) > 11 Then GoTo 1360

' Check Row 1

For i1 = 133 To 144: b(i1 - 132) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 1360

For j132 = m1 To m2                                             'a(132)
a(132) = j132

a(131) = 2 * Pr12 - a(132) - a(143) - a(144): If a(131) < 0 Or a(131) > 11 Then GoTo 1320
a(130) = a(132) - a(142) + a(144): If a(130) < 0 Or a(130) > 11 Then GoTo 1320
a(129) = -a(132) + a(142) + a(143): If a(129) < 0 Or a(129) > 11 Then GoTo 1320
a(128) = a(132) - a(140) + a(144): If a(128) < 0 Or a(128) > 11 Then GoTo 1320
a(127) = 2 * Pr12 - a(132) + a(140) - a(143) - 2 * a(144): If a(127) < 0 Or a(127) > 11 Then GoTo 1320
a(126) = a(132) + a(140) - a(142): If a(126) < 0 Or a(126) > 11 Then GoTo 1320
a(125) = -a(132) - a(140) + a(142) + a(143) + a(144): If a(125) < 0 Or a(125) > 11 Then GoTo 1320
a(124) = a(132) - a(136) + a(144): If a(124) < 0 Or a(124) > 11 Then GoTo 1320
a(123) = 2 * Pr12 - a(132) + a(136) - a(143) - 2 * a(144): If a(123) < 0 Or a(123) > 11 Then GoTo 1320
a(122) = a(132) + a(136) - a(142): If a(122) < 0 Or a(122) > 11 Then GoTo 1320
a(121) = -a(132) - a(136) + a(142) + a(143) + a(144): If a(121) < 0 Or a(121) > 11 Then GoTo 1320

' Check Row 2

For i1 = 121 To 132: b(i1 - 120) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 1320

a(120) = Pr12 - a(142): If a(120) < 0 Or a(120) > 11 Then GoTo 1320
a(119) = -Pr12 + a(142) + a(143) + a(144): If a(119) < 0 Or a(119) > 11 Then GoTo 1320
a(118) = Pr12 - a(144): If a(118) < 0 Or a(118) > 11 Then GoTo 1320
a(117) = Pr12 - a(143): If a(117) < 0 Or a(117) > 11 Then GoTo 1320
a(116) = Pr12 + a(140) - a(142) - a(144): If a(116) < 0 Or a(116) > 11 Then GoTo 1320
a(115) = -Pr12 - a(140) + a(142) + a(143) + 2 * a(144): If a(115) < 0 Or a(115) > 11 Then GoTo 1320
a(114) = Pr12 - a(140): If a(114) < 0 Or a(114) > 11 Then GoTo 1320
a(113) = Pr12 + a(140) - a(143) - a(144): If a(113) < 0 Or a(113) > 11 Then GoTo 1320
a(112) = Pr12 + a(136) - a(142) - a(144): If a(112) < 0 Or a(112) > 11 Then GoTo 1320
a(111) = -Pr12 - a(136) + a(142) + a(143) + 2 * a(144): If a(111) < 0 Or a(111) > 11 Then GoTo 1320
a(110) = Pr12 - a(136): If a(110) < 0 Or a(110) > 11 Then GoTo 1320
a(109) = Pr12 + a(136) - a(143) - a(144): If a(109) < 0 Or a(109) > 11 Then GoTo 1320
 
' Check Row 3

For i1 = 109 To 120: b(i1 - 108) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 1320

a(108) = Pr12 - a(132) + a(142) - a(144): If a(108) < 0 Or a(108) > 11 Then GoTo 1320
a(107) = Pr12 + a(132) - a(142) - a(143): If a(107) < 0 Or a(107) > 11 Then GoTo 1320
a(106) = Pr12 - a(132): If a(106) < 0 Or a(106) > 11 Then GoTo 1320
a(105) = -Pr12 + a(132) + a(143) + a(144): If a(105) < 0 Or a(105) > 11 Then GoTo 1320
a(104) = Pr12 - a(132) - a(140) + a(142): If a(104) < 0 Or a(104) > 11 Then GoTo 1320
a(103) = Pr12 + a(132) + a(140) - a(142) - a(143) - a(144): If a(103) < 0 Or a(103) > 11 Then GoTo 1320
a(102) = Pr12 - a(132) + a(140) - a(144): If a(102) < 0 Or a(102) > 11 Then GoTo 1320
a(101) = -Pr12 + a(132) - a(140) + a(143) + 2 * a(144): If a(101) < 0 Or a(101) > 11 Then GoTo 1320
a(100) = Pr12 - a(132) - a(136) + a(142): If a(100) < 0 Or a(100) > 11 Then GoTo 1320
a(99) = Pr12 + a(132) + a(136) - a(142) - a(143) - a(144): If a(99) < 0 Or a(99) > 11 Then GoTo 1320
a(98) = Pr12 - a(132) + a(136) - a(144): If a(98) < 0 Or a(98) > 11 Then GoTo 1320
a(97) = -Pr12 + a(132) - a(136) + a(143) + 2 * a(144): If a(97) < 0 Or a(97) > 11 Then GoTo 1320

' Check Row 4
For i1 = 97 To 108: b(i1 - 96) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 1320

For j96 = m1 To m2                                          'a(96)
a(96) = j96

a(95) = -a(96) + a(143) + a(144): If a(95) < 0 Or a(95) > 11 Then GoTo 960
a(94) = a(96) + a(142) - a(144): If a(94) < 0 Or a(94) > 11 Then GoTo 960
a(93) = 2 * Pr12 - a(96) - a(142) - a(143): If a(93) < 0 Or a(93) > 11 Then GoTo 960
a(92) = a(96) + a(140) - a(144): If a(92) < 0 Or a(92) > 11 Then GoTo 960
a(91) = -a(96) - a(140) + a(143) + 2 * a(144): If a(91) < 0 Or a(91) > 11 Then GoTo 960
a(90) = a(96) - a(140) + a(142): If a(90) < 0 Or a(90) > 11 Then GoTo 960
a(89) = 2 * Pr12 - a(96) + a(140) - a(142) - a(143) - a(144): If a(89) < 0 Or a(89) > 11 Then GoTo 960
a(88) = a(96) + a(136) - a(144): If a(88) < 0 Or a(88) > 11 Then GoTo 960
a(87) = -a(96) - a(136) + a(143) + 2 * a(144): If a(87) < 0 Or a(87) > 11 Then GoTo 960
a(86) = a(96) - a(136) + a(142): If a(86) < 0 Or a(86) > 11 Then GoTo 960
a(85) = 2 * Pr12 - a(96) + a(136) - a(142) - a(143) - a(144): If a(85) < 0 Or a(85) > 11 Then GoTo 960

' Check Row 5
    
For i1 = 85 To 96: b(i1 - 84) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 960
    
a(84) = -a(96) + a(132) + a(144): If a(84) < 0 Or a(84) > 11 Then GoTo 960
a(83) = 2 * Pr12 + a(96) - a(132) - a(143) - 2 * a(144): If a(83) < 0 Or a(83) > 11 Then GoTo 960
a(82) = -a(96) + a(132) - a(142) + 2 * a(144): If a(82) < 0 Or a(82) > 11 Then GoTo 960
a(81) = a(96) - a(132) + a(142) + a(143) - a(144): If a(81) < 0 Or a(81) > 11 Then GoTo 960
a(80) = -a(96) + a(132) - a(140) + 2 * a(144): If a(80) < 0 Or a(80) > 11 Then GoTo 960
a(79) = 2 * Pr12 + a(96) - a(132) + a(140) - a(143) - 3 * a(144): If a(79) < 0 Or a(79) > 11 Then GoTo 960
a(78) = -a(96) + a(132) + a(140) - a(142) + a(144): If a(78) < 0 Or a(78) > 11 Then GoTo 960
a(77) = a(96) - a(132) - a(140) + a(142) + a(143): If a(77) < 0 Or a(77) > 11 Then GoTo 960
a(76) = -a(96) + a(132) - a(136) + 2 * a(144): If a(76) < 0 Or a(76) > 11 Then GoTo 960
a(75) = 2 * Pr12 + a(96) - a(132) + a(136) - a(143) - 3 * a(144): If a(75) < 0 Or a(75) > 11 Then GoTo 960
a(74) = -a(96) + a(132) + a(136) - a(142) + a(144): If a(74) < 0 Or a(74) > 11 Then GoTo 960
a(73) = a(96) - a(132) - a(136) + a(142) + a(143): If a(73) < 0 Or a(73) > 11 Then GoTo 960
    
' Check Row 6
    
For i1 = 73 To 84: b(i1 - 72) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 960
    
a(72) = Pr12 - a(96) - a(142) + a(144): If a(72) < 0 Or a(72) > 11 Then GoTo 960
a(71) = -Pr12 + a(96) + a(142) + a(143): If a(71) < 0 Or a(71) > 11 Then GoTo 960
a(70) = Pr12 - a(96): If a(70) < 0 Or a(70) > 11 Then GoTo 960
a(69) = Pr12 + a(96) - a(143) - a(144): If a(69) < 0 Or a(69) > 11 Then GoTo 960
a(68) = Pr12 - a(96) + a(140) - a(142): If a(68) < 0 Or a(68) > 11 Then GoTo 960
a(67) = -Pr12 + a(96) - a(140) + a(142) + a(143) + a(144): If a(67) < 0 Or a(67) > 11 Then GoTo 960
a(66) = Pr12 - a(96) - a(140) + a(144): If a(66) < 0 Or a(66) > 11 Then GoTo 960
a(65) = Pr12 + a(96) + a(140) - a(143) - 2 * a(144): If a(65) < 0 Or a(65) > 11 Then GoTo 960
a(64) = Pr12 - a(96) + a(136) - a(142): If a(64) < 0 Or a(64) > 11 Then GoTo 960
a(63) = -Pr12 + a(96) - a(136) + a(142) + a(143) + a(144): If a(63) < 0 Or a(63) > 11 Then GoTo 960
a(62) = Pr12 - a(96) - a(136) + a(144): If a(62) < 0 Or a(62) > 11 Then GoTo 960
a(61) = Pr12 + a(96) + a(136) - a(143) - 2 * a(144): If a(61) < 0 Or a(61) > 11 Then GoTo 960

' Check Row 7
    
For i1 = 61 To 72: b(i1 - 60) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 960

a(60) = Pr12 + a(96) - a(132) + a(142) - 2 * a(144): If a(60) < 0 Or a(60) > 11 Then GoTo 960
a(59) = Pr12 - a(96) + a(132) - a(142) - a(143) + a(144): If a(59) < 0 Or a(59) > 11 Then GoTo 960
a(58) = Pr12 + a(96) - a(132) - a(144): If a(58) < 0 Or a(58) > 11 Then GoTo 960
a(57) = -Pr12 - a(96) + a(132) + a(143) + 2 * a(144): If a(57) < 0 Or a(57) > 11 Then GoTo 960
a(56) = Pr12 + a(96) - a(132) - a(140) + a(142) - a(144): If a(56) < 0 Or a(56) > 11 Then GoTo 960
a(55) = Pr12 - a(96) + a(132) + a(140) - a(142) - a(143): If a(55) < 0 Or a(55) > 11 Then GoTo 960
a(54) = Pr12 + a(96) - a(132) + a(140) - 2 * a(144): If a(54) < 0 Or a(54) > 11 Then GoTo 960
a(53) = -Pr12 - a(96) + a(132) - a(140) + a(143) + 3 * a(144): If a(53) < 0 Or a(53) > 11 Then GoTo 960
a(52) = Pr12 + a(96) - a(132) - a(136) + a(142) - a(144): If a(52) < 0 Or a(52) > 11 Then GoTo 960
a(51) = Pr12 - a(96) + a(132) + a(136) - a(142) - a(143): If a(51) < 0 Or a(51) > 11 Then GoTo 960
a(50) = Pr12 + a(96) - a(132) + a(136) - 2 * a(144): If a(50) < 0 Or a(50) > 11 Then GoTo 960
a(49) = -Pr12 - a(96) + a(132) - a(136) + a(143) + 3 * a(144): If a(49) < 0 Or a(49) > 11 Then GoTo 960

' Check Row 8
    
For i1 = 49 To 60: b(i1 - 48) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 960

For j48 = m1 To m2                                          'a(48)
a(48) = j48

a(47) = -a(48) + a(143) + a(144): If a(47) < 0 Or a(47) > 11 Then GoTo 480
a(46) = a(48) + a(142) - a(144): If a(46) < 0 Or a(46) > 11 Then GoTo 480
a(45) = 2 * Pr12 - a(48) - a(142) - a(143): If a(45) < 0 Or a(45) > 11 Then GoTo 480
a(44) = a(48) + a(140) - a(144): If a(44) < 0 Or a(44) > 11 Then GoTo 480
a(43) = -a(48) - a(140) + a(143) + 2 * a(144): If a(43) < 0 Or a(43) > 11 Then GoTo 480
a(42) = a(48) - a(140) + a(142): If a(42) < 0 Or a(42) > 11 Then GoTo 480
a(41) = 2 * Pr12 - a(48) + a(140) - a(142) - a(143) - a(144): If a(41) < 0 Or a(41) > 11 Then GoTo 480
a(40) = a(48) + a(136) - a(144): If a(40) < 0 Or a(40) > 11 Then GoTo 480
a(39) = -a(48) - a(136) + a(143) + 2 * a(144): If a(39) < 0 Or a(39) > 11 Then GoTo 480
a(38) = a(48) - a(136) + a(142): If a(38) < 0 Or a(38) > 11 Then GoTo 480
a(37) = 2 * Pr12 - a(48) + a(136) - a(142) - a(143) - a(144): If a(37) < 0 Or a(37) > 11 Then GoTo 480

' Check Row 9
    
For i1 = 37 To 48: b(i1 - 36) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 480

a(36) = -a(48) + a(132) + a(144): If a(36) < 0 Or a(36) > 11 Then GoTo 480
a(35) = 2 * Pr12 + a(48) - a(132) - a(143) - 2 * a(144): If a(35) < 0 Or a(35) > 11 Then GoTo 480
a(34) = -a(48) + a(132) - a(142) + 2 * a(144): If a(34) < 0 Or a(34) > 11 Then GoTo 480
a(33) = a(48) - a(132) + a(142) + a(143) - a(144): If a(33) < 0 Or a(33) > 11 Then GoTo 480
a(32) = -a(48) + a(132) - a(140) + 2 * a(144): If a(32) < 0 Or a(32) > 11 Then GoTo 480
a(31) = 2 * Pr12 + a(48) - a(132) + a(140) - a(143) - 3 * a(144): If a(31) < 0 Or a(31) > 11 Then GoTo 480
a(30) = -a(48) + a(132) + a(140) - a(142) + a(144): If a(30) < 0 Or a(30) > 11 Then GoTo 480
a(29) = a(48) - a(132) - a(140) + a(142) + a(143): If a(29) < 0 Or a(29) > 11 Then GoTo 480
a(28) = -a(48) + a(132) - a(136) + 2 * a(144): If a(28) < 0 Or a(28) > 11 Then GoTo 480
a(27) = 2 * Pr12 + a(48) - a(132) + a(136) - a(143) - 3 * a(144): If a(27) < 0 Or a(27) > 11 Then GoTo 480
a(26) = -a(48) + a(132) + a(136) - a(142) + a(144): If a(26) < 0 Or a(26) > 11 Then GoTo 480
a(25) = a(48) - a(132) - a(136) + a(142) + a(143): If a(25) < 0 Or a(25) > 11 Then GoTo 480

' Check Row 10
    
For i1 = 25 To 36: b(i1 - 24) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 480

a(24) = Pr12 - a(48) - a(142) + a(144): If a(24) < 0 Or a(24) > 11 Then GoTo 480
a(23) = -Pr12 + a(48) + a(142) + a(143): If a(23) < 0 Or a(23) > 11 Then GoTo 480
a(22) = Pr12 - a(48): If a(22) < 0 Or a(22) > 11 Then GoTo 480
a(21) = Pr12 + a(48) - a(143) - a(144): If a(21) < 0 Or a(21) > 11 Then GoTo 480
a(20) = Pr12 - a(48) + a(140) - a(142): If a(20) < 0 Or a(20) > 11 Then GoTo 480
a(19) = -Pr12 + a(48) - a(140) + a(142) + a(143) + a(144): If a(19) < 0 Or a(19) > 11 Then GoTo 480
a(18) = Pr12 - a(48) - a(140) + a(144): If a(18) < 0 Or a(18) > 11 Then GoTo 480
a(17) = Pr12 + a(48) + a(140) - a(143) - 2 * a(144): If a(17) < 0 Or a(17) > 11 Then GoTo 480
a(16) = Pr12 - a(48) + a(136) - a(142): If a(16) < 0 Or a(16) > 11 Then GoTo 480
a(15) = -Pr12 + a(48) - a(136) + a(142) + a(143) + a(144): If a(15) < 0 Or a(15) > 11 Then GoTo 480
a(14) = Pr12 - a(48) - a(136) + a(144): If a(14) < 0 Or a(14) > 11 Then GoTo 480
a(13) = Pr12 + a(48) + a(136) - a(143) - 2 * a(144): If a(13) < 0 Or a(13) > 11 Then GoTo 480

' Check Row 11
    
For i1 = 13 To 24: b(i1 - 12) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 480

a(12) = Pr12 + a(48) - a(132) + a(142) - 2 * a(144): If a(12) < 0 Or a(12) > 11 Then GoTo 480
a(11) = Pr12 - a(48) + a(132) - a(142) - a(143) + a(144): If a(11) < 0 Or a(11) > 11 Then GoTo 480
a(10) = Pr12 + a(48) - a(132) - a(144): If a(10) < 0 Or a(10) > 11 Then GoTo 480
a(9) = -Pr12 - a(48) + a(132) + a(143) + 2 * a(144): If a(9) < 0 Or a(9) > 11 Then GoTo 480
a(8) = Pr12 + a(48) - a(132) - a(140) + a(142) - a(144): If a(8) < 0 Or a(8) > 11 Then GoTo 480
a(7) = Pr12 - a(48) + a(132) + a(140) - a(142) - a(143): If a(7) < 0 Or a(7) > 11 Then GoTo 480
a(6) = Pr12 + a(48) - a(132) + a(140) - 2 * a(144): If a(6) < 0 Or a(6) > 11 Then GoTo 480
a(5) = -Pr12 - a(48) + a(132) - a(140) + a(143) + 3 * a(144): If a(5) < 0 Or a(5) > 11 Then GoTo 480
a(4) = Pr12 + a(48) - a(132) - a(136) + a(142) - a(144): If a(4) < 0 Or a(4) > 11 Then GoTo 480
a(3) = Pr12 - a(48) + a(132) + a(136) - a(142) - a(143): If a(3) < 0 Or a(3) > 11 Then GoTo 480
a(2) = Pr12 + a(48) - a(132) + a(136) - 2 * a(144): If a(2) < 0 Or a(2) > 11 Then GoTo 480
a(1) = -Pr12 - a(48) + a(132) - a(136) + a(143) + 3 * a(144): If a(1) < 0 Or a(1) > 11 Then GoTo 480

' Check Row 12
    
For i1 = 1 To 12: b(i1 - 0) = a(i1): Next i1
GoSub 1800: If fl1 = 0 Then GoTo 480

'Check Diagonal 1
i2 = 1
For i1 = 1 To 12:
    b(i1) = a(i2): i2 = i2 + 13
Next i1
GoSub 1800: If fl1 = 0 Then GoTo 480

'Check Diagonal 2
i2 = 12
For i1 = 1 To 12:
    b(i1) = a(i2): i2 = i2 + 11
Next i1
GoSub 1800: If fl1 = 0 Then GoTo 480

                        n9 = n9 + 1
'                       GoSub 2650             'Print results (squares)
                        GoSub 2645             'Print results (selected numbers)
'                       Cells(1, 1).Value = n9 'Counting

480 Next j48

960 Next j96

1320 Next j132
     
1360 Next j136

1400 Next j140
1420 Next j142
1430 Next j143
1440 Next j144

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

End

'   Exclude solutions with identical numbers Latin Lines Order 12

1800 fl1 = 1
     For j1 = 1 To 12
        a2 = b(j1):
        For j2 = (1 + j1) To 12
            If a2 = b(j2) Then fl1 = 0: Return
        Next j2
1810 Next j1
     Return

'   Print results (selected numbers)

2645 Cells(1, 146).Value = n9
     For i1 = 1 To 144
         Cells(n9, i1).Value = a(i1)
     Next i1
     Cells(n9, 145).Value = n9
     Return

'   Print results (squares)

2650 n2 = n2 + 1
     If n2 = 3 Then
         n2 = 1: k1 = k1 + 13: k2 = 1
     Else
         If n9 > 1 Then k2 = k2 + 13
     End If
     Cells(k1 + 1, k2 + 1).Select
    
     i3 = 0
     For i1 = 1 To 12
         For i2 = 1 To 12
             i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = a(i3)
         Next i2
     Next i1
    
     Return
     
End Sub

Vorige Pagina About the Author