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

Home > General
More or less magic square (Posted on 2004-06-22) Difficulty: 3 of 5
Fill a 3x3 square with the numbers from 1 to 9, so the four sides and the two diagonals share the same sum, which is to be as large as possible.

See The Solution Submitted by Federico Kereki    
Rating: 3.2500 (4 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re(2): Solution | Comment 5 of 11 |
(In reply to re: Solution by Bryan)

Having myself written a program to solve this, I disagree with the wrecking ball analogy.  Of course my program is bare bones and utilizes code from prior puzzles, but it assures that no solutions would be left unchecked.  I agree that many of the bells and whistles attached to the previously posted program lend credence to the wrecking ball analogy, but to my mind the bare bones version is worthwhile, though I didn't previously think it was worth posting.  But for comparison, and to dispel the wrecking ball analogy:

DECLARE SUB permute (a$)
OPEN "almmagic.txt" FOR OUTPUT AS #2
a$ = "123456789": h$ = a$
FOR i = 1 TO 362880
 n1 = VAL(MID$(a$, 1, 1))
 n2 = VAL(MID$(a$, 2, 1))
 n3 = VAL(MID$(a$, 3, 1))
 n4 = VAL(MID$(a$, 4, 1))
 n5 = VAL(MID$(a$, 5, 1))
 n6 = VAL(MID$(a$, 6, 1))
 n7 = VAL(MID$(a$, 7, 1))
 n8 = VAL(MID$(a$, 8, 1))
 n9 = VAL(MID$(a$, 9, 1))
 n10 = VAL(MID$(a$, 10, 1))
 t1 = n1 + n4 + n7
 t2 = n2 + n5 + n8
 t3 = n3 + n6 + n9
 t4 = n1 + n2 + n3
 t5 = n4 + n5 + n6
 t6 = n7 + n8 + n9
 t7 = n1 + n5 + n9
 t8 = n3 + n5 + n7
 IF t1 = t3 AND t1 = t4 AND t1 = t6 AND t1 = t7 AND t1 = t8 THEN
   PRINT #2, MID$(a$, 1, 3), t4
   PRINT #2, MID$(a$, 4, 3)
   PRINT #2, MID$(a$, 7, 3), t6
   PRINT #2, t1; t3
   PRINT #2, , , , t7, t8
   PRINT #2,
 END IF
nextPerm:
 permute a$
 IF LEFT$(a$, 2) <> pVal$ THEN pVal$ = LEFT$(a$, 2): PRINT pVal$
NEXT

CLOSE
 

The permute subroutine is the same as has been used elsewhere.


  Posted by Charlie on 2004-06-22 14:34:29
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 (2)
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