All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Border Magic (Posted on 2012-12-11) Difficulty: 3 of 5

No Solution Yet Submitted by brianjn    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer findings | Comment 1 of 2

DECLARE SUB permute (a$)
DATA 3111,9191,2114,1919
DATA 3648,4221,1512,5172
FOR i = 1 TO 4: READ row$(i): NEXT
FOR i = 1 TO 4: READ col$(i): NEXT

OPEN "bordmagc.txt" FOR OUTPUT AS #2

CLS
roword$ = "1234": hrow$ = roword$
DO
  FOR r = 1 TO 4
    FOR c = 1 TO 4
       rgrid(r, c) = VAL(MID$(row$(VAL(MID$(roword$, r, 1))), c, 1))
    NEXT c
  NEXT r
  FOR c = 1 TO 4: rgrid(5, c) = rgrid(1, c): NEXT
 
  colord$ = "1234": hcol$ = colord$
  DO
    FOR c = 1 TO 4
      FOR r = 1 TO 4
        cgrid(r, c) = VAL(MID$(col$(VAL(MID$(colord$, c, 1))), r, 1))
      NEXT r
    NEXT c
    FOR r = 1 TO 4: cgrid(r, 5) = cgrid(r, 1): NEXT
   
    good = 1
    FOR sqrow = 1 TO 4
     FOR sqcol = 1 TO 4
       sqgrid(sqrow, sqcol) = rgrid(sqrow, sqcol) + rgrid(sqrow + 1, sqcol) + cgrid(sqrow, sqcol) + cgrid(sqrow, sqcol + 1)
       IF sqgrid(sqrow, sqcol) > 25 THEN good = 0
     NEXT
    NEXT
    t0 = 0
    FOR c = 1 TO 4: t0 = t0 + sqgrid(1, c): NEXT
    FOR r = 2 TO 4
      t = 0
      FOR c = 1 TO 4: t = t + sqgrid(r, c): NEXT
      IF t <> t0 THEN good = 0: EXIT FOR
    NEXT
    FOR c = 1 TO 4
      t = 0
      FOR r = 1 TO 4: t = t + sqgrid(r, c): NEXT
      IF t <> t0 THEN good = 0: EXIT FOR
    NEXT
    IF good THEN
        FOR r0 = 1 TO 4
          PRINT " ";
          PRINT #2, " ";
          FOR c0 = 1 TO 4
            PRINT STR$(rgrid(r0, c0));
            PRINT #2, STR$(rgrid(r0, c0));
          NEXT
          PRINT
          PRINT #2,
          FOR c0 = 1 TO 5
            PRINT STR$(cgrid(r0, c0));
            PRINT #2, STR$(cgrid(r0, c0));
          NEXT
          PRINT
          PRINT #2,
        NEXT
        PRINT " ";
        PRINT #2, " ";
          FOR c0 = 1 TO 4
            PRINT STR$(rgrid(5, c0));
            PRINT #2, STR$(rgrid(5, c0));
          NEXT
        PRINT : PRINT
        PRINT #2, : PRINT #2,
        FOR r = 1 TO 4
         FOR c = 1 TO 4
          PRINT USING "###"; sqgrid(r, c);
          PRINT #2, USING "###"; sqgrid(r, c);
         NEXT
         PRINT
         PRINT #2,
        NEXT
        PRINT
        PRINT #2,
    END IF

    permute colord$
  LOOP UNTIL colord$ = hcol$
 permute roword$
LOOP UNTIL roword$ = hrow$
CLOSE

finds some with consecutive values in the magic square, and others with repeated and skipped values:

  2 1 1 4
 5 4 3 1 5
  9 1 9 1
 1 2 6 5 1
  3 1 1 1
 7 2 4 1 7
  1 9 1 9
 2 1 8 2 2
  2 1 1 4
 20  9 14 11
 15 10 21  8
 13 16  7 18
  6 19 12 17
  2 1 1 4
 5 1 3 4 5
  9 1 9 1
 1 5 6 2 1
  3 1 1 1
 7 1 4 2 7
  1 9 1 9
 2 2 8 1 2
  2 1 1 4
 17  6 17 14
 18 13 18  5
 12 15  8 19
  7 20 11 16    has repeats
  2 1 1 4
 5 4 3 1 5
  1 9 1 9
 1 2 6 5 1
  3 1 1 1
 7 2 4 1 7
  9 1 9 1
 2 1 8 2 2
  2 1 1 4
 12 17  6 19
  7 18 13 16
 21  8 15 10
 14 11 20  9
  2 1 1 4
 5 1 3 4 5
  1 9 1 9
 1 5 6 2 1
  3 1 1 1
 7 1 4 2 7
  9 1 9 1
 2 2 8 1 2
  2 1 1 4
  9 14  9 22
 10 21 10 13
 20  7 16 11
 15 12 19  8   has repeats

 


  Posted by Charlie on 2012-12-11 17:26:05
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (10)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information