Monday, June 3, 2013

how to make magic squares - NxN magic square solver generator c++ source

how to make magic squares - NxN magic square solver generator c++ source

hello every one, in this post I'm gonna show you how to create an odd NxN magic squares, plus you can download a simple application that generates an odd magic square and save it as .html file.

what is a magic square

A magic square is a square matrix with the property that the sum of every row and column, as well as both diagonals, is the same number.an example of a 3 x 3 normal magic square is

You can verify that each of the three rows, the three columns, and the two diagonals add to 15

1.Do magic squares manually - algorithm

       C1   C2   C3   C4   C5
                      

R1     17   24   1    8    15   


R2     23   5    7    14   16            ROWS
                                        

R3     4    6    13   20   22    


R4     10   12   19   21   3      


R5     11   18   25   2    9   

RULE DEFAULT: INCREASING NUMBERS DIAGONALLY

RULE onw: always put 1 at the middle of the upper row. see above

RULE# two: if you ran out of or rows(ie R is less than R1 ) go to Rn ( in this case R5)

RULE# three:if you ran out or columns(ie C>Cn ) go to C1.

RUlE# four:if the space is already taken, add 2 to the taken row,n subtract 1 from taken col. (ie. in our case 6 goes to r1+2=r3 n c3-1=c2)=====>(r3,c2).

RULE# five: if you ran out of both rows and cols, add 2 to the taken row,n subtract 1 from taken col. (ie. in our case 6 goes to r1+2=r3 n c3-1=c2)=====>(r3,c2). similar to rule#4

keep doing until the square is complete!

2.c++ source for magic square generator

this is not different from the above rules except the order of the rules. in logic you must always check compound sentences before simple ones. so in the source file, rule#one must come before two and three.

download magic square generator app + source here

thanks!!!!!!

No comments:

Post a Comment