
#1
Dec2812, 04:26 AM

P: 31

Is there any algorithm to form a magic square of any size with a desired magic sum ?
Also can we make a magic square not only with the numbers from 1 to n^{2} but using any random numbers ? 



#2
Dec2812, 10:58 AM

P: 96

For a quick overview look at: http://en.wikipedia.org/wiki/Magic_square




#3
Dec2912, 02:50 AM

P: 31

Can you give me a better one ? 



#4
Dec2912, 04:16 AM

P: 96

General algorithm for a magic square
There is not one algorithm for all n (a natural number); I think, there are at least 3:
for odd numbers, for double even ( ie for numbers with 4 as factor) and for even numbers. Below you find my little algorithm (written in ARIBAS) to generate an odd magic square; example for n = 11; for simplicity of the algorithm, a 'vector' is used to store the 'square' . ==> MagicSquareOdd(11). : (68, 81, 94, 107, 120, 1, 14, 27, 40, 53, 66, 80, 93, 106, 119, 11, 13, 26, 39, 52, 65, 67, 92, 105, 118, 10, 12, 25, 38, 51, 64, 77, 79, 104, 117, 9, 22, 24, 37, 50, 63, 76, 78, 91, 116, 8, 21, 23, 36, 49, 62, 75, 88, 90, 103, 7, 20, 33, 35, 48, 61, 74, 87, 89, 102, 115, 19, 32, 34, 47, 60, 73, 86, 99, 101, 114, 6, 31, 44, 46, 59, 72, 85, 98, 100, 113, 5, 18, 43, 45, 58, 71, 84, 97, 110, 112, 4, 17, 30, 55, 57, 70, 83, 96, 109, 111, 3, 16, 29, 42, 56, 69, 82, 95, 108, 121, 2, 15, 28, 41, 54)




#5
Dec2912, 08:11 AM

P: 891





#6
Dec2912, 10:27 AM

P: 96

Below you find my little algorithm (written in ARIBAS) to generate an doubleeven magic square of side length n (ie 4 divides n);
example for n = 4; for simplicity of the algorithm, a 'vector' is used to store the 'square' MagicSquareDoubleEven(4). : (16, 2, 3, 13, 5, 11, 10, 8, 9, 7, 6, 12, 4, 14, 15, 1)




#7
Dec3012, 08:09 AM

P: 96

Below you find my little algorithm (written in ARIBAS) to generate an simpleeven magic square of side length n (ie n div 2 must be odd);
example for n = 6; the algorithm uses my 'MagicSquareOdd' (see above) to form a matrix a and an auxiliary matrix 'aux' for the needed inter change of some elements of matix a MagicSquareSimpleEven(6) ((35, 1, 6, 26, 19, 24), (3, 32, 7, 21, 23, 25), (31, 9, 2, 22, 27, 20), (8, 28, 33, 17, 10, 15), (30, 5, 34, 12, 14, 16), (4, 36, 29, 13, 18, 11)) A good companion for this algorithm was: http://www.hpgramatke.de/magic_sq/index.htm



Register to reply 
Related Discussions  
Magic Square Java  Engineering, Comp Sci, & Technology Homework  1  
Help With Pseudo Coded Algorithm for The DiamondSquare Algorithm  Engineering, Comp Sci, & Technology Homework  0  
Apocalyptic Magic Square  General Math  1  
Magic Square question  General Math  9  
Magic square  Brain Teasers  5 