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

Magic Square program help in Java

This is homework that we got in my Computer Science class dealing with 2D Arrays. I tried understanding the code, but unfortunately, I'm having a hard time understanding some of the code. This is the code that we were provided with: public class…
Abwatts
  • 31
  • 2
  • 6
-2
votes
2 answers

Semimagic Square

I have to create function which generate random NxN magic square with all sums of columns and rows equal to S. Variables N and S have to be users input. I've already create function which draws squares and breaks the loop when meet given conditions.…
-2
votes
1 answer

Generating a magic square

This is a magic square problem, the size of the magic square n should be inputed as a command line argument. n has to be a odd number. The expected output should be like this. My problem is that when I try to execute the code, it generates a bunch…
Emilizh
  • 1
  • 1
-2
votes
1 answer

Can someone explain to me the 2nd for loop .. I already understand the first one.. thanks

I'm creating a java project called magicsquare and I've searched online on how to do it. Now, I'm trying to understand how the 2nd loop works, I know that it prints and align the magic square, but I don't know the details. I already know the first…
Carsh CaNe
  • 39
  • 7
-2
votes
2 answers

Magic Square and Backtracking C++

I have to write a program that solves a NxN Magic Square, with digits from 1 to N^2. It works properly with 3x3, partially filled 4x4, but, in two hours, it can't find a solution for partially filled 5x5. This is my code: #include…
Federico Cuozzo
  • 363
  • 1
  • 7
  • 20
-3
votes
2 answers

How to create a Magic square in python?

A magic square is a matrix in which the sum of rows, columns and diagonals are equal. I had created a matrix using nested list but unable to equal the sum of the rows, columns and diagonals.
-3
votes
3 answers

How to check if a 4x4 matrix is a magic square?

I am trying to check if a two-dimensional array is a magic square. Getting confused about the interpretation of one or more of the directions below? I learn best by example so if anyone could show me directly with code I would appreciate it. Write…
-3
votes
3 answers

Checking for a magic square

I have a program that takes in a set of 16 numbers and prints them out in a grid of 4x4. I must then check each row, column and diagonal add up to the same number, however I can't do this part, as I have no idea how that would work. Can anyone…
Thomas
  • 293
  • 1
  • 3
  • 15
-4
votes
4 answers

How do I make my code run in a loop and ask the user "Try again Yes or no?"

import java.io.*; public class Magic{ static final int maxsize = 50; public static void main (String [] args) throws IOException{ int i, j, k, l, n, key; boolean n_ok; String line; int [] [] square = new int…
-4
votes
1 answer

Write a program in python to check whether a given matrix forms magic square or not

A basket is given to you in the shape of a matrix. If the size of the matrix is N x N then the range of number of eggs you can put in each slot of the basket is 1 to N2 . You task is to arrange the eggs in the basket such that the sum of each row,…
-5
votes
3 answers

Magic Square with python, using itertools

I have some code that will determine if a N*N list of integers forms a magic square: import itertools #Function square magic def magic_square(matrix): dimension = len(matrix[0]) sum_list = [] #Horizontal code: sum_list.extend([sum…
Andreas
  • 41
  • 7
-6
votes
2 answers

magic square program help C#

I need help debugging and finishing a program that would: read a file with same number of lines and same number of integer values on each line (this will be a n x n matrix). The program should determines if the matrix is a magic square. example of…
Abner_CV
  • 25
  • 1
  • 2
  • 10
-7
votes
2 answers

Find all possible magic squares (3x3) python

I can find only one magic square how to find all please.
Duspy777
  • 1
  • 3
1 2 3
9
10