Vorige Pagina About the Author

' Generates Most Perfect Franklin Magic Squares of order 16, Magic Sum 2056 (Barink Restrictions)

' Tested with Office 2007 under Windows 7

Sub MgcSqr16c()

Dim a(256), b(256), c(256)

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

n2 = 0: n9 = 0
m1 = 1: m2 = 256: s1 = 2056

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

For j256 = m1 To m2                                               'a(256)

If b(j256) = 0 Then b(j256) = j256: c(256) = j256 Else GoTo 2560
a(256) = j256
For j255 = m1 To m2                                               'a(255)
If b(j255) = 0 Then b(j255) = j255: c(255) = j255 Else GoTo 2550
a(255) = j255
For j254 = m1 To m2                                               'a(254)
If b(j254) = 0 Then b(j254) = j254: c(254) = j254 Else GoTo 2540
a(254) = j254

jj = 254
a(253) = 514 - a(254) - a(255) - a(256): j = 253: GoSub 3000: If fl1 = 1 Then GoTo 2540

For j252 = m1 To m2                                               'a(252)
If b(j252) = 0 Then b(j252) = j252: c(252) = j252 Else GoTo 2520
a(252) = j252

jj = 252
a(251) = -a(252) + a(255) + a(256): j = 251: GoSub 3000: If fl1 = 1 Then GoTo 2520
a(250) = -a(252) + a(254) + a(256): j = 250: GoSub 3000: If fl1 = 1 Then GoTo 2520
a(249) = 514 + a(252) - a(254) - a(255) - 2 * a(256): j = 249: GoSub 3000: If fl1 = 1 Then GoTo 2520

For j248 = m1 To m1                                               'a(248)
If b(j248) = 0 Then b(j248) = j248: c(248) = j248 Else GoTo 2480
a(248) = j248

jj = 248
a(247) = -a(248) + a(255) + a(256): j = 247: GoSub 3000: If fl1 = 1 Then GoTo 2480
a(246) = -a(248) + a(254) + a(256): j = 246: GoSub 3000: If fl1 = 1 Then GoTo 2480
a(245) = 514 + a(248) - a(254) - a(255) - 2 * a(256): j = 245: GoSub 3000: If fl1 = 1 Then GoTo 2480

For j244 = m1 To m2                                               'a(244)
If b(j244) = 0 Then b(j244) = j244: c(244) = j244 Else GoTo 2440
a(244) = j244

jj = 244
a(243) = -a(244) + a(255) + a(256): j = 243: GoSub 3000: If fl1 = 1 Then GoTo 2440
a(242) = -a(244) + a(254) + a(256): j = 242: GoSub 3000: If fl1 = 1 Then GoTo 2440
a(241) = 514 + a(244) - a(254) - a(255) - 2 * a(256): j = 241: GoSub 3000: If fl1 = 1 Then GoTo 2440

For j240 = m1 To m2                                               'a(240)
If b(j240) = 0 Then b(j240) = j240: c(240) = j240 Else GoTo 2400
a(240) = j240

jj = 240
a(239) = 514 - a(240) - a(255) - a(256): j = 239: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(238) = a(240) - a(254) + a(256): j = 238: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(237) = -a(240) + a(254) + a(255): j = 237: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(236) = a(240) - a(252) + a(256): j = 236: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(235) = 514 - a(240) + a(252) - a(255) - 2 * a(256): j = 235: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(234) = a(240) + a(252) - a(254): j = 234: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(233) = -a(240) - a(252) + a(254) + a(255) + a(256): j = 233: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(232) = a(240) - a(248) + a(256): j = 232: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(231) = 514 - a(240) + a(248) - a(255) - 2 * a(256): j = 231: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(230) = a(240) + a(248) - a(254): j = 230: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(229) = -a(240) - a(248) + a(254) + a(255) + a(256): j = 229: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(228) = a(240) - a(244) + a(256): j = 228: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(227) = 514 - a(240) + a(244) - a(255) - 2 * a(256): j = 227: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(226) = a(240) + a(244) - a(254): j = 226: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(225) = -a(240) - a(244) + a(254) + a(255) + a(256): j = 225: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(224) = 257 - a(254): j = 224: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(223) = -257 + a(254) + a(255) + a(256): j = 223: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(222) = 257 - a(256): j = 222: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(221) = 257 - a(255): j = 221: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(220) = 257 + a(252) - a(254) - a(256): j = 220: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(219) = -257 - a(252) + a(254) + a(255) + 2 * a(256): j = 219: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(218) = 257 - a(252): j = 218: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(217) = 257 + a(252) - a(255) - a(256): j = 217: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(216) = 257 + a(248) - a(254) - a(256): j = 216: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(215) = -257 - a(248) + a(254) + a(255) + 2 * a(256): j = 215: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(214) = 257 - a(248): j = 214: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(213) = 257 + a(248) - a(255) - a(256): j = 213: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(212) = 257 + a(244) - a(254) - a(256): j = 212: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(211) = -257 - a(244) + a(254) + a(255) + 2 * a(256): j = 211: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(210) = 257 - a(244): j = 210: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(209) = 257 + a(244) - a(255) - a(256): j = 209: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(208) = 257 - a(240) + a(254) - a(256): j = 208: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(207) = 257 + a(240) - a(254) - a(255): j = 207: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(206) = 257 - a(240): j = 206: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(205) = -257 + a(240) + a(255) + a(256): j = 205: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(204) = 257 - a(240) - a(252) + a(254): j = 204: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(203) = 257 + a(240) + a(252) - a(254) - a(255) - a(256): j = 203: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(202) = 257 - a(240) + a(252) - a(256): j = 202: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(201) = -257 + a(240) - a(252) + a(255) + 2 * a(256): j = 201: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(200) = 257 - a(240) - a(248) + a(254): j = 200: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(199) = 257 + a(240) + a(248) - a(254) - a(255) - a(256): j = 199: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(198) = 257 - a(240) + a(248) - a(256): j = 198: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(197) = -257 + a(240) - a(248) + a(255) + 2 * a(256): j = 197: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(196) = 257 - a(240) - a(244) + a(254): j = 196: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(195) = 257 + a(240) + a(244) - a(254) - a(255) - a(256): j = 195: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(194) = 257 - a(240) + a(244) - a(256): j = 194: GoSub 3000: If fl1 = 1 Then GoTo 2400
a(193) = -257 + a(240) - a(244) + a(255) + 2 * a(256): j = 193: GoSub 3000: If fl1 = 1 Then GoTo 2400

For j192 = m1 To m2                                               'a(192)
If b(j192) = 0 Then b(j192) = j192: c(192) = j192 Else GoTo 1920
a(192) = j192

jj = 192
a(191) = -a(192) + a(255) + a(256): j = 191: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(190) = a(192) + a(254) - a(256): j = 190: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(189) = 514 - a(192) - a(254) - a(255): j = 189: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(188) = a(192) + a(252) - a(256): j = 188: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(187) = -a(192) - a(252) + a(255) + 2 * a(256): j = 187: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(186) = a(192) - a(252) + a(254): j = 186: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(185) = 514 - a(192) + a(252) - a(254) - a(255) - a(256): j = 185: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(184) = a(192) + a(248) - a(256): j = 184: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(183) = -a(192) - a(248) + a(255) + 2 * a(256): j = 183: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(182) = a(192) - a(248) + a(254): j = 182: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(181) = 514 - a(192) + a(248) - a(254) - a(255) - a(256): j = 181: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(180) = a(192) + a(244) - a(256): j = 180: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(179) = -a(192) - a(244) + a(255) + 2 * a(256): j = 179: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(178) = a(192) - a(244) + a(254): j = 178: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(177) = 514 - a(192) + a(244) - a(254) - a(255) - a(256): j = 177: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(176) = -a(192) + a(240) + a(256): j = 176: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(175) = 514 + a(192) - a(240) - a(255) - 2 * a(256): j = 175: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(174) = -a(192) + a(240) - a(254) + 2 * a(256): j = 174: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(173) = a(192) - a(240) + a(254) + a(255) - a(256): j = 173: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(172) = -a(192) + a(240) - a(252) + 2 * a(256): j = 172: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(171) = 514 + a(192) - a(240) + a(252) - a(255) - 3 * a(256): j = 171: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(170) = -a(192) + a(240) + a(252) - a(254) + a(256): j = 170: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(169) = a(192) - a(240) - a(252) + a(254) + a(255): j = 169: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(168) = -a(192) + a(240) - a(248) + 2 * a(256): j = 168: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(167) = 514 + a(192) - a(240) + a(248) - a(255) - 3 * a(256): j = 167: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(166) = -a(192) + a(240) + a(248) - a(254) + a(256): j = 166: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(165) = a(192) - a(240) - a(248) + a(254) + a(255): j = 165: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(164) = -a(192) + a(240) - a(244) + 2 * a(256): j = 164: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(163) = 514 + a(192) - a(240) + a(244) - a(255) - 3 * a(256): j = 163: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(162) = -a(192) + a(240) + a(244) - a(254) + a(256): j = 162: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(161) = a(192) - a(240) - a(244) + a(254) + a(255): j = 161: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(160) = 257 - a(192) - a(254) + a(256): j = 160: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(159) = -257 + a(192) + a(254) + a(255): j = 159: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(158) = 257 - a(192): j = 158: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(157) = 257 + a(192) - a(255) - a(256): j = 157: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(156) = 257 - a(192) + a(252) - a(254): j = 156: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(155) = -257 + a(192) - a(252) + a(254) + a(255) + a(256): j = 155: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(154) = 257 - a(192) - a(252) + a(256): j = 154: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(153) = 257 + a(192) + a(252) - a(255) - 2 * a(256): j = 153: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(152) = 257 - a(192) + a(248) - a(254): j = 152: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(151) = -257 + a(192) - a(248) + a(254) + a(255) + a(256): j = 151: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(150) = 257 - a(192) - a(248) + a(256): j = 150: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(149) = 257 + a(192) + a(248) - a(255) - 2 * a(256): j = 149: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(148) = 257 - a(192) + a(244) - a(254): j = 148: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(147) = -257 + a(192) - a(244) + a(254) + a(255) + a(256): j = 147: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(146) = 257 - a(192) - a(244) + a(256): j = 146: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(145) = 257 + a(192) + a(244) - a(255) - 2 * a(256): j = 145: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(144) = 257 + a(192) - a(240) + a(254) - 2 * a(256): j = 144: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(143) = 257 - a(192) + a(240) - a(254) - a(255) + a(256): j = 143: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(142) = 257 + a(192) - a(240) - a(256): j = 142: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(141) = -257 - a(192) + a(240) + a(255) + 2 * a(256): j = 141: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(140) = 257 + a(192) - a(240) - a(252) + a(254) - a(256): j = 140: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(139) = 257 - a(192) + a(240) + a(252) - a(254) - a(255): j = 139: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(138) = 257 + a(192) - a(240) + a(252) - 2 * a(256): j = 138: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(137) = -257 - a(192) + a(240) - a(252) + a(255) + 3 * a(256): j = 137: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(136) = 257 + a(192) - a(240) - a(248) + a(254) - a(256): j = 136: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(135) = 257 - a(192) + a(240) + a(248) - a(254) - a(255): j = 135: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(134) = 257 + a(192) - a(240) + a(248) - 2 * a(256): j = 134: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(133) = -257 - a(192) + a(240) - a(248) + a(255) + 3 * a(256): j = 133: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(132) = 257 + a(192) - a(240) - a(244) + a(254) - a(256): j = 132: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(131) = 257 - a(192) + a(240) + a(244) - a(254) - a(255): j = 131: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(130) = 257 + a(192) - a(240) + a(244) - 2 * a(256): j = 130: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(129) = -257 - a(192) + a(240) - a(244) + a(255) + 3 * a(256): j = 129: GoSub 3000: If fl1 = 1 Then GoTo 1920

For j128 = m1 To m2                                               'a(128)
If b(j128) = 0 Then b(j128) = j128: c(128) = j128 Else GoTo 1280
a(128) = j128

jj = 128
a(127) = -a(128) + a(255) + a(256): j = 127: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(126) = a(128) + a(254) - a(256): j = 126: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(125) = 514 - a(128) - a(254) - a(255): j = 125: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(124) = a(128) + a(252) - a(256): j = 124: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(123) = -a(128) - a(252) + a(255) + 2 * a(256): j = 123: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(122) = a(128) - a(252) + a(254): j = 122: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(121) = 514 - a(128) + a(252) - a(254) - a(255) - a(256): j = 121: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(120) = a(128) + a(248) - a(256): j = 120: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(119) = -a(128) - a(248) + a(255) + 2 * a(256): j = 119: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(118) = a(128) - a(248) + a(254): j = 118: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(117) = 514 - a(128) + a(248) - a(254) - a(255) - a(256): j = 117: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(116) = a(128) + a(244) - a(256): j = 116: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(115) = -a(128) - a(244) + a(255) + 2 * a(256): j = 115: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(114) = a(128) - a(244) + a(254): j = 114: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(113) = 514 - a(128) + a(244) - a(254) - a(255) - a(256): j = 113: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(112) = -a(128) + a(240) + a(256): j = 112: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(111) = 514 + a(128) - a(240) - a(255) - 2 * a(256): j = 111: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(110) = -a(128) + a(240) - a(254) + 2 * a(256): j = 110: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(109) = a(128) - a(240) + a(254) + a(255) - a(256): j = 109: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(108) = -a(128) + a(240) - a(252) + 2 * a(256): j = 108: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(107) = 514 + a(128) - a(240) + a(252) - a(255) - 3 * a(256): j = 107: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(106) = -a(128) + a(240) + a(252) - a(254) + a(256): j = 106: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(105) = a(128) - a(240) - a(252) + a(254) + a(255): j = 105: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(104) = -a(128) + a(240) - a(248) + 2 * a(256): j = 104: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(103) = 514 + a(128) - a(240) + a(248) - a(255) - 3 * a(256): j = 103: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(102) = -a(128) + a(240) + a(248) - a(254) + a(256): j = 102: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(101) = a(128) - a(240) - a(248) + a(254) + a(255): j = 101: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(100) = -a(128) + a(240) - a(244) + 2 * a(256): j = 100: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(99) = 514 + a(128) - a(240) + a(244) - a(255) - 3 * a(256): j = 99: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(98) = -a(128) + a(240) + a(244) - a(254) + a(256): j = 98: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(97) = a(128) - a(240) - a(244) + a(254) + a(255): j = 97: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(96) = 257 - a(128) - a(254) + a(256): j = 96: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(95) = -257 + a(128) + a(254) + a(255): j = 95: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(94) = 257 - a(128): j = 94: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(93) = 257 + a(128) - a(255) - a(256): j = 93: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(92) = 257 - a(128) + a(252) - a(254): j = 92: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(91) = -257 + a(128) - a(252) + a(254) + a(255) + a(256): j = 91: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(90) = 257 - a(128) - a(252) + a(256): j = 90: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(89) = 257 + a(128) + a(252) - a(255) - 2 * a(256): j = 89: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(88) = 257 - a(128) + a(248) - a(254): j = 88: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(87) = -257 + a(128) - a(248) + a(254) + a(255) + a(256): j = 87: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(86) = 257 - a(128) - a(248) + a(256): j = 86: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(85) = 257 + a(128) + a(248) - a(255) - 2 * a(256): j = 85: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(84) = 257 - a(128) + a(244) - a(254): j = 84: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(83) = -257 + a(128) - a(244) + a(254) + a(255) + a(256): j = 83: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(82) = 257 - a(128) - a(244) + a(256): j = 82: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(81) = 257 + a(128) + a(244) - a(255) - 2 * a(256): j = 81: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(80) = 257 + a(128) - a(240) + a(254) - 2 * a(256): j = 80: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(79) = 257 - a(128) + a(240) - a(254) - a(255) + a(256): j = 79: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(78) = 257 + a(128) - a(240) - a(256): j = 78: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(77) = -257 - a(128) + a(240) + a(255) + 2 * a(256): j = 77: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(76) = 257 + a(128) - a(240) - a(252) + a(254) - a(256): j = 76: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(75) = 257 - a(128) + a(240) + a(252) - a(254) - a(255): j = 75: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(74) = 257 + a(128) - a(240) + a(252) - 2 * a(256): j = 74: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(73) = -257 - a(128) + a(240) - a(252) + a(255) + 3 * a(256): j = 73: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(72) = 257 + a(128) - a(240) - a(248) + a(254) - a(256): j = 72: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(71) = 257 - a(128) + a(240) + a(248) - a(254) - a(255): j = 71: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(70) = 257 + a(128) - a(240) + a(248) - 2 * a(256): j = 70: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(69) = -257 - a(128) + a(240) - a(248) + a(255) + 3 * a(256): j = 69: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(68) = 257 + a(128) - a(240) - a(244) + a(254) - a(256): j = 68: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(67) = 257 - a(128) + a(240) + a(244) - a(254) - a(255): j = 67: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(66) = 257 + a(128) - a(240) + a(244) - 2 * a(256): j = 66: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(65) = -257 - a(128) + a(240) - a(244) + a(255) + 3 * a(256): j = 65: GoSub 3000: If fl1 = 1 Then GoTo 1280

For j64 = m1 To m2                                                 'a(64)
If b(j64) = 0 Then b(j64) = j64: c(64) = j64 Else GoTo 640
a(64) = j64

jj = 64
a(63) = -a(64) + a(255) + a(256): j = 63: GoSub 3000: If fl1 = 1 Then GoTo 640
a(62) = a(64) + a(254) - a(256): j = 62: GoSub 3000: If fl1 = 1 Then GoTo 640
a(61) = 514 - a(64) - a(254) - a(255): j = 61: GoSub 3000: If fl1 = 1 Then GoTo 640
a(60) = a(64) + a(252) - a(256): j = 60: GoSub 3000: If fl1 = 1 Then GoTo 640
a(59) = -a(64) - a(252) + a(255) + 2 * a(256): j = 59: GoSub 3000: If fl1 = 1 Then GoTo 640
a(58) = a(64) - a(252) + a(254): j = 58: GoSub 3000: If fl1 = 1 Then GoTo 640
a(57) = 514 - a(64) + a(252) - a(254) - a(255) - a(256): j = 57: GoSub 3000: If fl1 = 1 Then GoTo 640
a(56) = a(64) + a(248) - a(256): j = 56: GoSub 3000: If fl1 = 1 Then GoTo 640
a(55) = -a(64) - a(248) + a(255) + 2 * a(256): j = 55: GoSub 3000: If fl1 = 1 Then GoTo 640
a(54) = a(64) - a(248) + a(254): j = 54: GoSub 3000: If fl1 = 1 Then GoTo 640
a(53) = 514 - a(64) + a(248) - a(254) - a(255) - a(256): j = 53: GoSub 3000: If fl1 = 1 Then GoTo 640
a(52) = a(64) + a(244) - a(256): j = 52: GoSub 3000: If fl1 = 1 Then GoTo 640
a(51) = -a(64) - a(244) + a(255) + 2 * a(256): j = 51: GoSub 3000: If fl1 = 1 Then GoTo 640
a(50) = a(64) - a(244) + a(254): j = 50: GoSub 3000: If fl1 = 1 Then GoTo 640
a(49) = 514 - a(64) + a(244) - a(254) - a(255) - a(256): j = 49: GoSub 3000: If fl1 = 1 Then GoTo 640
a(48) = -a(64) + a(240) + a(256): j = 48: GoSub 3000: If fl1 = 1 Then GoTo 640
a(47) = 514 + a(64) - a(240) - a(255) - 2 * a(256): j = 47: GoSub 3000: If fl1 = 1 Then GoTo 640
a(46) = -a(64) + a(240) - a(254) + 2 * a(256): j = 46: GoSub 3000: If fl1 = 1 Then GoTo 640
a(45) = a(64) - a(240) + a(254) + a(255) - a(256): j = 45: GoSub 3000: If fl1 = 1 Then GoTo 640
a(44) = -a(64) + a(240) - a(252) + 2 * a(256): j = 44: GoSub 3000: If fl1 = 1 Then GoTo 640
a(43) = 514 + a(64) - a(240) + a(252) - a(255) - 3 * a(256): j = 43: GoSub 3000: If fl1 = 1 Then GoTo 640
a(42) = -a(64) + a(240) + a(252) - a(254) + a(256): j = 42: GoSub 3000: If fl1 = 1 Then GoTo 640
a(41) = a(64) - a(240) - a(252) + a(254) + a(255): j = 41: GoSub 3000: If fl1 = 1 Then GoTo 640
a(40) = -a(64) + a(240) - a(248) + 2 * a(256): j = 40: GoSub 3000: If fl1 = 1 Then GoTo 640
a(39) = 514 + a(64) - a(240) + a(248) - a(255) - 3 * a(256): j = 39: GoSub 3000: If fl1 = 1 Then GoTo 640
a(38) = -a(64) + a(240) + a(248) - a(254) + a(256): j = 38: GoSub 3000: If fl1 = 1 Then GoTo 640
a(37) = a(64) - a(240) - a(248) + a(254) + a(255): j = 37: GoSub 3000: If fl1 = 1 Then GoTo 640
a(36) = -a(64) + a(240) - a(244) + 2 * a(256): j = 36: GoSub 3000: If fl1 = 1 Then GoTo 640
a(35) = 514 + a(64) - a(240) + a(244) - a(255) - 3 * a(256): j = 35: GoSub 3000: If fl1 = 1 Then GoTo 640
a(34) = -a(64) + a(240) + a(244) - a(254) + a(256): j = 34: GoSub 3000: If fl1 = 1 Then GoTo 640
a(33) = a(64) - a(240) - a(244) + a(254) + a(255): j = 33: GoSub 3000: If fl1 = 1 Then GoTo 640
a(32) = 257 - a(64) - a(254) + a(256): j = 32: GoSub 3000: If fl1 = 1 Then GoTo 640
a(31) = -257 + a(64) + a(254) + a(255): j = 31: GoSub 3000: If fl1 = 1 Then GoTo 640
a(30) = 257 - a(64): j = 30: GoSub 3000: If fl1 = 1 Then GoTo 640
a(29) = 257 + a(64) - a(255) - a(256): j = 29: GoSub 3000: If fl1 = 1 Then GoTo 640
a(28) = 257 - a(64) + a(252) - a(254): j = 28: GoSub 3000: If fl1 = 1 Then GoTo 640
a(27) = -257 + a(64) - a(252) + a(254) + a(255) + a(256): j = 27: GoSub 3000: If fl1 = 1 Then GoTo 640
a(26) = 257 - a(64) - a(252) + a(256): j = 26: GoSub 3000: If fl1 = 1 Then GoTo 640
a(25) = 257 + a(64) + a(252) - a(255) - 2 * a(256): j = 25: GoSub 3000: If fl1 = 1 Then GoTo 640
a(24) = 257 - a(64) + a(248) - a(254): j = 24: GoSub 3000: If fl1 = 1 Then GoTo 640
a(23) = -257 + a(64) - a(248) + a(254) + a(255) + a(256): j = 23: GoSub 3000: If fl1 = 1 Then GoTo 640
a(22) = 257 - a(64) - a(248) + a(256): j = 22: GoSub 3000: If fl1 = 1 Then GoTo 640
a(21) = 257 + a(64) + a(248) - a(255) - 2 * a(256): j = 21: GoSub 3000: If fl1 = 1 Then GoTo 640
a(20) = 257 - a(64) + a(244) - a(254): j = 20: GoSub 3000: If fl1 = 1 Then GoTo 640
a(19) = -257 + a(64) - a(244) + a(254) + a(255) + a(256): j = 19: GoSub 3000: If fl1 = 1 Then GoTo 640
a(18) = 257 - a(64) - a(244) + a(256): j = 18: GoSub 3000: If fl1 = 1 Then GoTo 640
a(17) = 257 + a(64) + a(244) - a(255) - 2 * a(256): j = 17: GoSub 3000: If fl1 = 1 Then GoTo 640
a(16) = 257 + a(64) - a(240) + a(254) - 2 * a(256): j = 16: GoSub 3000: If fl1 = 1 Then GoTo 640
a(15) = 257 - a(64) + a(240) - a(254) - a(255) + a(256): j = 15: GoSub 3000: If fl1 = 1 Then GoTo 640
a(14) = 257 + a(64) - a(240) - a(256): j = 14: GoSub 3000: If fl1 = 1 Then GoTo 640
a(13) = -257 - a(64) + a(240) + a(255) + 2 * a(256): j = 13: GoSub 3000: If fl1 = 1 Then GoTo 640
a(12) = 257 + a(64) - a(240) - a(252) + a(254) - a(256): j = 12: GoSub 3000: If fl1 = 1 Then GoTo 640
a(11) = 257 - a(64) + a(240) + a(252) - a(254) - a(255): j = 11: GoSub 3000: If fl1 = 1 Then GoTo 640
a(10) = 257 + a(64) - a(240) + a(252) - 2 * a(256): j = 10: GoSub 3000: If fl1 = 1 Then GoTo 640
a(9) = -257 - a(64) + a(240) - a(252) + a(255) + 3 * a(256): j = 9: GoSub 3000: If fl1 = 1 Then GoTo 640
a(8) = 257 + a(64) - a(240) - a(248) + a(254) - a(256): j = 8: GoSub 3000: If fl1 = 1 Then GoTo 640
a(7) = 257 - a(64) + a(240) + a(248) - a(254) - a(255): j = 7: GoSub 3000: If fl1 = 1 Then GoTo 640
a(6) = 257 + a(64) - a(240) + a(248) - 2 * a(256): j = 6: GoSub 3000: If fl1 = 1 Then GoTo 640
a(5) = -257 - a(64) + a(240) - a(248) + a(255) + 3 * a(256): j = 5: GoSub 3000: If fl1 = 1 Then GoTo 640
a(4) = 257 + a(64) - a(240) - a(244) + a(254) - a(256): j = 4: GoSub 3000: If fl1 = 1 Then GoTo 640
a(3) = 257 - a(64) + a(240) + a(244) - a(254) - a(255): j = 3: GoSub 3000: If fl1 = 1 Then GoTo 640
a(2) = 257 + a(64) - a(240) + a(244) - 2 * a(256): j = 2: GoSub 3000: If fl1 = 1 Then GoTo 640
a(1) = -257 - a(64) + a(240) - a(244) + a(255) + 3 * a(256): j = 1: GoSub 3000: If fl1 = 1 Then GoTo 640

                                    n9 = n9 + 1
                                    GoSub 2650 'Print results (squares)
'                                   GoSub 2645 'Print results (selected numbers
    
    jj = 64: GoSub 3050            'Reset b() and c()
640 Next j64

     jj = 128: GoSub 3050          'Reset b() and c()
1280 Next j128
     
     jj = 192: GoSub 3050          'Reset b() and c()
1920 Next j192

     jj = 240: GoSub 3050          'Reset b() and c()
2400 Next j240

     jj = 244: GoSub 3050          'Reset b() and c()
2440 Next j244
     
     jj = 248: GoSub 3050          'Reset b() and c()
2480 Next j248

     jj = 252: GoSub 3050          'Reset b() and c()
2520 Next j252

     jj = 254: GoSub 3050          'Reset b() and c()
2540 Next j254
     b(c(255)) = 0: c(255) = 0
2550 Next j255
     b(c(256)) = 0: c(256) = 0
2560 Next j256


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

End

'   Print results (selected numbers)

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

'   Print results (squares)

2650 n2 = n2 + 1
     If n2 = 3 Then
         n2 = 1: k1 = k1 + 17: k2 = 0
     Else
         If n9 > 1 Then k2 = k2 + 17
     End If
     Cells(k1 + 1, k2 + 1).Select
    
     i3 = 0
     For i1 = 1 To 16
         For i2 = 1 To 16
             i3 = i3 + 1
             Cells(k1 + i1, k2 + i2).Value = a(i3)
         Next i2
     Next i1
    
     Return
     
'    Exclude identical solutions and solutions out of range
     
3000 fl1 = 0
     If a(j) <= 0 Or a(j) > 256 Then fl1 = 1: GoTo 3010
     If b(a(j)) = 0 Then b(a(j)) = a(j): c(j) = a(j) Else fl1 = 1
3010 If fl1 = 1 Then                                               'Reset b() and c()
        For i = j + 1 To jj
             b(c(i)) = 0: c(i) = 0
        Next i
     End If
     Return

'    Reset b() and c() after completion loop

3050 For i = j To jj
         b(c(i)) = 0: c(i) = 0
     Next i
     Return

End Sub

Vorige Pagina About the Author