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
2
votes
6 answers

Magic square python

I'm coding a program that reads a line in a file and determines whether or not the line makes a Lo Shu Magic square. In this magic square, the sum of the rows, sum of the columns, and sum of the diagonals have to equal 15, and each number 1-9 can…
TheBudderBomb
  • 73
  • 1
  • 3
  • 14
2
votes
1 answer

How to turn a line in a file into a 2d array

I'm fairly new to python and I've been struggling with coding a program that will take a line in a file as input to verify a Lo Shu Magic Square. What i need to do is read one line in the file at a time and with each line 1 2 3 4 5 6 7 8 9 for…
TheBudderBomb
  • 73
  • 1
  • 3
  • 14
2
votes
2 answers

Creating a Magic Square in java

I have to write a program that takes in an odd number from the user and creates a magic square. A magic square is one where the sum of each row, column, and diagonal is the same. These are the characteristics for writing the code: Ask the user for…
ch1maera
  • 1,369
  • 5
  • 20
  • 42
2
votes
2 answers

Testing a .txt file for a Magic Square Java

I didn't want to have to ask, but I can not figure out this assignment, and neither could the TA when I asked for help. I have to take input from a text file, feed the integers in the file into an array list, and test to see if it is a n x n magic…
sbowde4
  • 767
  • 1
  • 4
  • 23
2
votes
1 answer

How do I generate a magic square using only a 1 dimensional array?

I am assigned to prompt a user to give the order of a magic square (a magic square of order 3 would be a 3x3 matrix) and then generate a magic square of that order without using a 2 dimensional array. Here's what I know and understand: The Array…
TrevDev
  • 63
  • 3
2
votes
1 answer

Magic Square in Python Debugging

Problem originally is in this link. I wrote a Python code but I got 64 points (total points is 100) and this indicates that my code has some missing points. I passed 11 of 16 test cases but 5 test cases have problematic for me. Could you say where…
mathema
  • 939
  • 11
  • 22
2
votes
4 answers

Magic Square in C++

Yet another magic square problem. I'm creating an odd magic square program in C++, and for some reason the program keeps giving a segmentation fault error and quitting. Here is the code: #include using std::cin; using…
T145
  • 1,415
  • 1
  • 13
  • 33
2
votes
2 answers

How to get a list of the Value of a number as the sum of 4 numbers in Prolog

I'm having trouble making this predicate work. The idea is to use diabolic([A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P]) to obtain all the possible magic squares in that list. At first I thought about using permutation/2 but it's hella slow for a list of 16…
2
votes
3 answers

prolog I have to make a program that calculates the magic matrix permutate

I have to make a program that calculates the magic matrix, I have made ​​my code and it works but my permute is very slow. I need one that is faster someone can help me Please This is the code: diabolico([A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P]) :- …
D4IVT3
  • 101
  • 1
  • 17
2
votes
2 answers

How to create a magic square which already has some numbers filled?

I would like to do this: I've got a matrix N x N. It can contain number from 1 to n^2. This matrix has a few cells filled with positive numbers. I have to decide, that this already filled matrix can be a magic matrix (magic square). For example: 0 0…
Alex
  • 258
  • 2
  • 20
2
votes
1 answer

C - 2D Array - Magic Square order 4

114 void fillDoubly(int square[20][20], int n){ 115 116 int i, j, k=0, l=0, counter=0, test[400]={0}, diff=n/4-1; 117 118 for(i=0;i
hqjb
  • 85
  • 4
1
vote
2 answers

Make a magic square, with min change

So I'm trying to make a magic square with min changes, but with this i only get the last option, I mean is a magic square but not with the min, I was thinking that somehow we can use the min value of x as an indicator to change into that specific…
1
vote
1 answer

OpenMp and #pragma omp for in c how it works and how to check if its doing his objective

I and doing a magic square program with OpenMP in C to try it to get faster. However, my times are higher than the sequencial implementation. I don't know if I am doing the omp for in a good way and I can't understand if that loop for is spreading…
1
vote
1 answer

Why the result changes after i change the size of array?

I ve done a program that take an number n as input and then return a square matrix n*n with the property that all row, columns, and diagonals have the same sum. The project works without problem, and I tried to optimize it as much as i can, from the…
will
  • 143
  • 1
  • 2
  • 11
1
vote
1 answer

Solving a magic square using recursion in C

Hi I want to make a 3 x 3 magic square in C using backtracking (as in the 4 queens exercise) with recursivity. In addition, I must enter the maximum value that this magic square will have inside, for example if I enter m = 26, my table should look…
1
2
3
9 10