Questions tagged [magic-square]

A "magic square" is an arrangement of numbers (usually integers) in a square grid, where the numbers in each row, and in each column, and the numbers in the forward and backward main diagonals, all add up to the same number.

In recreational mathematics, a magic square is an arrangement of numbers (usually integers) in the form of a square grid, where the numbers in each row, and in each column, and the numbers in the forward and backward main diagonals, all add up to the same number.

A magic square has the same number of rows as it has columns, and in conventional math notation, "n" stands for the number of rows (and columns) it has.

Thus, a magic square always contains n2 numbers, and its size (the number of rows [and columns] it has) is described as being "of order n". A magic square that contains the integers from 1 to n2 is called a normal magic square. (The term "magic square" is also sometimes used to refer to any of various types of word squares.)

Wikipedia:
http://en.wikipedia.org/wiki/Magic_square

148 questions
1
vote
3 answers

Prolog sum of a list of numbers

I am new to Prolog and I want to write poppler(Nums, Plate, Tastiness) that takes a list of exactly 9 numbers as input, and, if possible, returns a permutation of those numbers that forms a delicious poppler plate when Plate is read in row-major…
MicM
  • 123
  • 1
  • 2
  • 13
1
vote
2 answers

Magic Square of n order in wolfram mathematica

please can you help me with creation of function in Wolfram Mathematica for magic square. I must create function MagicSquare[n_], which output is sqare matrix of first n^2 integers, and sum of these integers in every column, every row, and on…
Alex
  • 11
  • 1
1
vote
2 answers

Magic square brute force algorithm

Basically for an assignment I need to create a C# program that will take a number as input (n) then create a 2D array size n*n with the numbers 1 to (n*n). It needs to use a brute force method. I have done this but at the moment the program will…
1
vote
1 answer

Construct a Magic Square by a given number of rows

I'm trying to build an application in simple PHP but could be done in any language. I want the user to enter number of rows and the output will be the magic square of it. For example, for $rows=3: 8-1-6 3-5-7 4-9-2 Notice that in every…
Gal
  • 23,122
  • 32
  • 97
  • 118
1
vote
1 answer

Need help for optimization - generating magic squares in java

I have to implement an algorithm which creates all possible magic squares for a given edge length(n=3,4). For n=3 the algorithm works fine. But for n=4 the algorithm don't get any results, because it's not optimal(too slow). I tried to optimize the…
mate1229
  • 95
  • 1
  • 7
0
votes
2 answers

Permuting Magic Squares

I'm having a little bit of trouble writing a recursive permutation function for solving Magic Squares. For this function, I'm not allowed to use two-dimensional arrays, only lists. Below is what I have currently: def permute(size): magicSquare =…
tuffbunnies9
  • 9
  • 1
  • 2
0
votes
2 answers

Magic Square Function Matlab

For a project i am supposed to write my own function that will do the same thing as the magic function in matlab. I am obviously not asking anyone to write out my problem but if somebody could give me any ideas of how i could start it or example…
user1068253
  • 51
  • 1
  • 2
  • 3
0
votes
2 answers

Does not take input if more than 3

def magic_square(n): n = int(n) magicSquare=[] for i in range(n): l=[] for j in range(n): l.append(0) magicSquare.append(l) print("Before processing the program..") for i in range(n): …
0
votes
1 answer

Sum in magic square isnt working properly for size> 37

I'm first year csd student I have an assignment where I need to check whether a square is a magic square and print "Yes" or "No" for each row (including diagonals) and column that meets the sum of the requirement magic square , if each number on…
0
votes
0 answers

There is something wrong with my magic square validation check

how do i check that in my magic square there is a duplicate of numbers #include #include int main(void) { int size, c, r, ctr = 0; printf("Input Size: "); scanf("%d", &size); int magic[size][size]; int…
Gami
  • 1
  • 1
0
votes
4 answers

Magic Square Java program

//Kevin Clement //Week3A Magic Squares Hey all, doing an introductory assignment to 2dimensional arrays. Below is the code I have done which is pretty much done. My problem I get is I'm not entirely sure how to print out the array, as well as…
Kevin Clement
  • 21
  • 1
  • 5
0
votes
0 answers

Trying to program Magic Square solver with Python

I am trying to create a program that opens a text file containing a magic square, which is laid out like this: (I have updated the code now. There is no longer a debug error however the program doesn't actually function) 1 2 3 4 5 6 7 8 9 I have…
jotachin
  • 15
  • 5
0
votes
1 answer

Find number of ways to fill the magic square

We have a simplified 3x3 magic square that can be filled with numbers from 0 to 9 with repetitions. The sum of the elements in each row must be equal the sum of the elements in each column, diagonals don't matter. We need to count the number of ways…
0
votes
1 answer

Is there something wrong with my Magic Square Code?

A brief explanation: With the code below it will make a randomly generated Square and some code below would make sure that it was a Magic Square, in which the sum of the elements in each row, column, and the two diagonals are the same value. My…
PG915
  • 1
  • 1
0
votes
1 answer

Equation Creation for Magic Square style logic

I am trying to bring logic and programming to a currently manually driven process. We take the weights of 16 different crushing hammers, organize them into sets of 4 based on how close each set's weight is to the others. We are looking to have less…