魔六角陣

 投稿者:しばっち  投稿日:2011年11月13日(日)20時09分46秒
  魔六角陣? (魔方陣の六角形版)

FOR A = 1 TO 19
   FOR B = 1 TO 19
      IF A = B THEN GOTO 20
      LET  C = 38 - A - B
      IF C > 19 THEN GOTO 20
      IF C < 1 THEN EXIT FOR
      IF C = A OR C = B THEN GOTO 20
      FOR D = 1 TO 19
         IF A = D OR B = D OR C = D THEN GOTO 40
         LET  H = 38 - A - D
         IF H > 19 THEN GOTO 40
         IF H < 1 THEN EXIT FOR
         IF H = A OR H = B OR H = C OR H = D THEN GOTO 40
         FOR E = 1 TO 19
            IF A = E OR B = E OR C = E OR D = E OR H = E THEN GOTO 50
            FOR F = 1 TO 19
               IF A = F OR B = F OR C = F OR D = F OR H = F OR E = F THEN GOTO 60
               LET  G = 38 - D - E - F
               IF G < 1 THEN EXIT FOR
               IF G > 19 THEN GOTO 60
               IF A = G OR B = G OR C = G OR D = G OR H = G OR E = G OR F = G THEN GOTO 60
               LET  L = 38 - C - G
               IF L < 1 OR L > 19 THEN GOTO 60
               IF A = L OR B = L OR C = L OR D = L OR H = L OR E = L OR F = L OR G = L THEN GOTO 60
               FOR I = 1 TO 19
                  IF A = I OR B = I OR C = I OR D = I OR H = I OR E = I OR F = I OR G = I OR L = I THEN GOTO 70
                  LET  M = 38 - B - E - I
                  IF M < 1 THEN EXIT FOR
                  IF M > 19 THEN GOTO 70
                  IF A = M OR B = M OR C = M OR D = M OR H = M OR E = M OR F = M OR G = M OR L = M OR I = M THEN GOTO 70
                  FOR J = 1 TO 19
                     IF A = J OR B = J OR C = J OR D = J OR H = J OR E = J OR F = J OR G = J OR L = J OR I = J OR M = J THEN GOTO 80
                     FOR K = 1 TO 19
                        IF A = K OR B = K OR C = K OR D = K OR H = K OR E = K OR F = K OR G = K OR L = K OR I = K OR M = K OR J = K THEN GOTO 90
                        !'IF H + I + J + K + L > 38 THEN EXIT FOR
                        IF H + I + J + K + L <> 38 THEN GOTO 90
                        LET  P = 38 - B - F - K
                        IF P < 1 THEN EXIT FOR
                        IF P > 19 THEN GOTO 90
                        IF A = P OR B = P OR C = P OR D = P OR H = P OR E = P OR F = P OR G = P OR L = P OR I = P OR M = P OR K = P OR J = P THEN GOTO 90
                        FOR N = 1 TO 19
                           IF A = N OR B = N OR C = N OR D = N OR H = N OR E = N OR F = N OR G = N OR L = N OR I = N OR M = N OR K = N OR P = N OR J = N THEN GOTO 100
                           LET  R = 38 - D - I - N
                           IF R < 1 THEN EXIT FOR
                           IF R > 19 THEN GOTO 100
                           IF A = R OR B = R OR C = R OR D = R OR H = R OR E = R OR F = R OR G = R OR L = R OR I = R OR M = R OR K = R OR P = R OR N = R OR J = R THEN GOTO 100
                           LET  Q = 38 - C - F - J - N
                           IF Q < 1 THEN EXIT FOR
                           IF Q > 19 THEN GOTO 100
                           IF H + M + Q <> 38 THEN GOTO 100
                           IF A = Q OR B = Q OR C = Q OR D = Q OR H = Q OR E = Q OR F = Q OR G = Q OR L = Q OR I = Q OR M = Q OR K = Q OR P = Q OR N = Q OR R = Q OR J = Q THEN GOTO 100
                           LET  O = 38 - G - K - R
                           IF O < 1 OR O > 19 THEN GOTO 100
                           IF M + N + O + P <> 38 THEN GOTO 100
                           IF A = O OR B = O OR C = O OR D = O OR H = O OR E = O OR F = O OR G = O OR L = O OR I = O OR M = O OR K = O OR P = O OR N = O OR R = O OR Q = O OR J = O THEN GOTO 100
                           LET  S = 38 - Q - R
                           IF S < 1 OR S > 19 THEN GOTO 100
                           IF L + P + S <> 38 THEN GOTO 100
                           IF A + E + J + O + S <> 38 THEN GOTO 100
                           IF A = S OR B = S OR C = S OR D = S OR H = S OR E = S OR F = S OR G = S OR L = S OR I = S OR M = S OR K = S OR P = S OR N = S OR R = S OR Q = S OR O = S OR J = S THEN GOTO 100
                           LET  NO = NO + 1
                           PRINT "No."; NO
                           PRINT USING "    ##  ##  ##    ": A, B, C
                           PRINT USING "  ##  ##  ##  ##  ": D, E, F, G
                           PRINT USING "##  ##  ##  ##  ##": H, I, J, K, L
                           PRINT USING "  ##  ##  ##  ##  ": M, N, O, P
                           PRINT USING "    ##  ##  ##    ": Q, R, S
100                         NEXT N
90                      NEXT K
80                   NEXT J
70                NEXT I
60             NEXT F
50          NEXT E
40       NEXT D
20    NEXT B
10 NEXT A
END
 

戻る