'This program make 7x7 bent diagonal 4 pan-way magic squares 'Programmer : Miguel Angel Amela 'October 2012 DEFINT A-Z CLS Nc& = 1: d4 = 25 PRINT INPUT " Input the a1 entry and press enter to execute: ", a1 PRINT Ti! = TIMER FOR a7 = a1 + 1 TO 49 SELECT CASE a7 CASE 25: GOTO 1 END SELECT a4 = 75 - a1 - a7 SELECT CASE a4 CASE IS < 1, a1, a7, 25, IS > 49: GOTO 1 END SELECT g4 = a1 + a7 - d4 SELECT CASE g4 CASE IS < 1, a4, a1, a7, 25, IS > 49: GOTO 1 END SELECT FOR g1 = a7 + 1 TO 49 SELECT CASE g1 CASE g4, a4, a1, a7, 25: GOTO 2 END SELECT g7 = 100 - a1 - a7 - g1 SELECT CASE g7 CASE IS < 1, g1, g4, a4, IS <= a1, a7, 25, IS > 49: GOTO 2 END SELECT d1 = a7 + g7 - d4 SELECT CASE d1 CASE IS < 1, g7, g1, g4, a4, a1, a7, 25, IS > 49: GOTO 2 END SELECT d7 = a1 + g1 - d4 SELECT CASE d7 CASE IS < 1, d1, g7, g1, g4, a4, a1, a7, 25, IS > 49: GOTO 2 END SELECT b2c3 = 75 - a1 IF b2c3 < 50 THEN xb2 = 1: yb2 = b2c3 - 1 IF b2c3 = 50 THEN xb2 = 1: yb2 = 49 IF b2c3 > 50 THEN xb2 = b2c3 - 49: yb2 = 49 FOR b2 = xb2 TO yb2 SELECT CASE b2 CASE d7, d1, g7, g1, g4, a4, a1, a7, 25: GOTO 3 END SELECT c3 = b2c3 - b2 SELECT CASE c3 CASE IS < 1, b2, d7, d1, g7, g1, g4, a4, a1, a7, 25, IS > 49: GOTO 3 END SELECT b6c5 = 75 - a7 IF b6c5 < 50 THEN xb6 = 1: yb6 = b6c5 - 1 IF b6c5 = 50 THEN xb6 = 1: yb6 = 49 IF b6c5 > 50 THEN xb6 = b6c5 - 49: yb6 = 49 FOR b6 = xb6 TO yb6 SELECT CASE b6 CASE c3, b2, d7, d1, g7, g1, g4, a4, a1, a7, 25: GOTO 4 END SELECT c5 = b6c5 - b6 SELECT CASE c5 CASE IS < 1, b6, c3, b2, d7, d1, g7, g1, g4, a4, a1, a7, 25, IS > 49: GOTO 4 END SELECT f2e3 = 75 - g1 IF f2e3 < 50 THEN xf2 = 1: yf2 = f2e3 - 1 IF f2e3 = 50 THEN xf2 = 1: yf2 = 49 IF f2e3 > 50 THEN xf2 = f2e3 - 49: yf2 = 49 FOR f2 = xf2 TO yf2 SELECT CASE f2 CASE c5, b6, c3, b2, d7, d1, g7, g1, g4, a4, a1, a7, 25: GOTO 5 END SELECT e3 = f2e3 - f2 SELECT CASE e3 CASE IS < 1, b6, c3, b2, d7, d1, g7, g1, g4, a4, a1, a7, 25, IS > 49: GOTO 5 CASE c5, f2: GOTO 5 END SELECT f6 = 100 - b2 - b6 - f2 SELECT CASE f6 CASE IS < 1, b6, c3, b2, d7, d1, g7, g1, g4, a4, a1, a7, 25, IS > 49: GOTO 5 CASE e3, c5, f2: GOTO 5 END SELECT e5 = 75 - f6 - g7 SELECT CASE e5 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 5 CASE f6, e3, f2, c5: GOTO 5 END SELECT b3b5 = 100 - b2 - b6 IF b3b5 < 50 THEN xb3 = 1: yb3 = b3b5 - 1 IF b3b5 = 50 THEN xb3 = 1: yb3 = 49 IF b3b5 > 50 THEN xb3 = b3b5 - 49: yb3 = 49 FOR b3 = xb3 TO yb3 SELECT CASE b3 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 6 CASE e5: GOTO 6 END SELECT b5 = b3b5 - b3 SELECT CASE b5 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 6 CASE b3, e5, f6, e3, f2, c5: GOTO 6 END SELECT f3 = 100 - b3 - c3 - e3 SELECT CASE f3 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 6 CASE b5, b3, e5, f6, e3, f2, c5: GOTO 6 END SELECT f5 = 100 - b5 - c5 - e5 SELECT CASE f5 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 6 CASE f3, b5, b3, e5, f6, e3, f2, c5: GOTO 6 END SELECT c2c6 = 100 - c3 - c5 IF c2c6 < 50 THEN xc2 = 1: yc2 = c2c6 - 1 IF c2c6 = 50 THEN xc2 = 1: yc2 = 49 IF c2c6 > 50 THEN xc2 = c2c6 - 49: yc2 = 49 FOR c2 = xc2 TO yc2 SELECT CASE c2 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 7 CASE f5, f3, b5, b3, e5: GOTO 7 END SELECT c6 = c2c6 - c2 SELECT CASE c6 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 7 CASE c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 7 END SELECT e2 = 100 - b2 - c2 - f2 SELECT CASE e2 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 7 CASE c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 7 END SELECT e6 = 100 - b6 - c6 - f6 SELECT CASE e6 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 7 CASE e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 7 END SELECT FOR a2 = 1 TO 49 SELECT CASE a2 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 8 CASE e6, e2, c6, c2, f5, f3, b5, b3, e5: GOTO 8 END SELECT g2d2 = 75 - a2 IF g2d2 < 50 THEN xg2 = 1: yg2 = g2d2 - 1 IF g2d2 = 50 THEN xg2 = 1: yg2 = 49 IF g2d2 > 50 THEN xg2 = g2d2 - 49: yg2 = 49 FOR g2 = xg2 TO yg2 SELECT CASE g2 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 9 CASE a2, e6, e2, c6, c2, f5, f3, b5, b3, e5: GOTO 9 END SELECT d2 = g2d2 - g2 SELECT CASE d2 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 9 CASE g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 9 END SELECT d3 = 125 - c2 - d1 - d2 - e2 SELECT CASE d3 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 9 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 9 END SELECT FOR a6 = 1 TO 49 SELECT CASE a6 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 10 CASE d3, d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5: GOTO 10 END SELECT b4 = a2 + a6 - 25 SELECT CASE b4 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 10 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 10 CASE a6, d3: GOTO 10 END SELECT c4 = 175 - g1 - g7 - a2 - a6 - b3 - b5 SELECT CASE c4 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 10 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 10 CASE b4, a6, d3: GOTO 10 END SELECT g6d6 = 75 - a6 IF g6d6 < 50 THEN xg6 = 1: yg6 = g6d6 - 1 IF g6d6 = 50 THEN xg6 = 1: yg6 = 49 IF g6d6 > 50 THEN xg6 = g6d6 - 49: yg6 = 49 FOR g6 = xg6 TO yg6 SELECT CASE g6 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 11 CASE c4, b4, a6, d3, d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5: GOTO 11 END SELECT d6 = g6d6 - g6 SELECT CASE d6 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 11 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 11 CASE g6, c4, b4, a6, d3: GOTO 11 END SELECT d5 = 125 - c6 - d6 - d7 - e6 SELECT CASE d5 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 11 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 11 CASE d6, g6, c4, b4, a6, d3: GOTO 11 END SELECT f4 = g2 + g6 - 25 SELECT CASE f4 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 11 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 11 CASE d5, d6, g6, c4, b4, a6, d3: GOTO 11 END SELECT e4 = 175 - a1 - a7 - g2 - g6 - f3 - f5 SELECT CASE e4 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 11 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 11 CASE f4, d5, d6, g6, c4, b4, a6, d3: GOTO 11 END SELECT b1b7 = 100 - a2 - a6 IF b1b7 < 50 THEN xb1 = 1: yb1 = b1b7 - 1 IF b1b7 = 50 THEN xb1 = 1: yb1 = 49 IF b1b7 > 50 THEN xb1 = b1b7 - 49: yb1 = 49 FOR b1 = xb1 TO yb1 SELECT CASE b1 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 12 CASE c4, b4, a6, d3, d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5: GOTO 12 CASE e4, f4, d5, d6, g6: GOTO 12 END SELECT b7 = b1b7 - b1 SELECT CASE b7 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 12 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 12 CASE b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 12 END SELECT f1 = a6 + b7 - g2 SELECT CASE f1 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 12 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 12 CASE b7, b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 12 END SELECT f7 = a2 + b1 - g6 SELECT CASE f7 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 12 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 12 CASE f1, b7, b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 12 END SELECT a3a5 = 75 - b4 IF a3a5 < 50 THEN xa3 = 1: ya3 = a3a5 - 1 IF a3a5 = 50 THEN xa3 = 1: ya3 = 49 IF a3a5 > 50 THEN xa3 = a3a5 - 49: ya3 = 49 FOR a3 = xa3 TO ya3 SELECT CASE a3 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 13 CASE c4, b4, a6, d3, d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5: GOTO 13 CASE f7, f1, b7, b1, e4, f4, d5, d6, g6: GOTO 13 END SELECT a5 = a3a5 - a3 SELECT CASE a5 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 13 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 13 CASE a3, f7, f1, b7, b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 13 END SELECT g3 = 175 - a3 - b4 - c5 - d6 - e5 - f4 SELECT CASE g3 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 13 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 13 CASE a5, a3, f7, f1, b7, b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 13 END SELECT g5 = 175 - a5 - b4 - c3 - d2 - e3 - f4 SELECT CASE g5 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 13 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 13 CASE g3, a5, a3, f7, f1, b7, b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 13 END SELECT c1e1 = 75 - d2 IF c1e1 < 50 THEN xc1 = 1: yc1 = c1e1 - 1 IF c1e1 = 50 THEN xc1 = 1: yc1 = 49 IF c1e1 > 50 THEN xc1 = c1e1 - 49: yc1 = 49 FOR c1 = xc1 TO yc1 SELECT CASE c1 CASE f6, e3, f2, c5, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25: GOTO 14 CASE c4, b4, a6, d3, d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5: GOTO 14 CASE g5, g3, a5, a3, f7, f1, b7, b1, e4, f4, d5, d6, g6: GOTO 14 END SELECT e1 = c1e1 - c1 SELECT CASE e1 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 14 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 14 CASE g3, a5, a3, f7, f1, b7, b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 14 CASE c1, g5: GOTO 14 END SELECT c7 = 75 - c1 - c4 SELECT CASE c7 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 14 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 14 CASE g3, a5, a3, f7, f1, b7, b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 14 CASE e1, c1, g5: GOTO 14 END SELECT e7 = 100 - b7 - c7 - f7 SELECT CASE e7 CASE IS < 1, b6, c3, b2, g4, d7, d1, a4, g7, g1, a7, a1, 25, IS > 49: GOTO 14 CASE d2, g2, a2, e6, e2, c6, c2, f5, f3, b5, b3, e5, f6, e3, f2, c5: GOTO 14 CASE g3, a5, a3, f7, f1, b7, b1, e4, f4, d5, d6, g6, c4, b4, a6, d3: GOTO 14 CASE c7, e1, c1, g5: GOTO 14 END SELECT PRINT PRINT USING "####"; a1; a2; a3; a4; a5; a6; a7 PRINT USING "####"; b1; b2; b3; b4; b5; b6; b7 PRINT USING "####"; c1; c2; c3; c4; c5; c6; c7 PRINT USING "####"; d1; d2; d3; d4; d5; d6; d7 PRINT USING "####"; e1; e2; e3; e4; e5; e6; e7 PRINT USING "####"; f1; f2; f3; f4; f5; f6; f7 PRINT USING "####"; g1; g2; g3; g4; g5; g6; g7 PRINT PRINT Nc& Nc& = Nc& + 1 14 NEXT 13 NEXT 12 NEXT 11 NEXT 10 NEXT 9 NEXT 8 NEXT 7 NEXT 6 NEXT 5 NEXT 4 NEXT 3 NEXT 2 NEXT 1 NEXT PRINT Tf! = TIMER PRINT INT(Tf! - Ti!); "seconds" END