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
0
votes
1 answer

Find the largest Magic Square

Given an m x n integer grid, return the size (i.e., the side length k) of the largest magic square that can be found within this grid. The question can be found here on leetcode I first wanted to see if a naive brute force approach would pass, so I…
Jitesh Malipeddi
  • 2,150
  • 3
  • 17
  • 37
0
votes
0 answers

Test if magic square can be created from array

I am trying to write a program that checks if a magic square can be created out of an array. The array that I have to work with contains 64 elements (which would result in a 8x8 magic square). from sympy.utilities.iterables import…
ATYslh
  • 75
  • 2
  • 7
0
votes
1 answer

Creating a magic square (Java)

I'm kinda stuck on what to do with this square matrix coding project. Whenever I try to input any values, the results always turn out as true and that the square matrix is a magic square. For example, this would turn out true: 16 03 02 13 05 10 11…
Zenzu
  • 7
  • 2
0
votes
1 answer

Magic Square with Python

I have a file called "magic.txt" which contains the following numbers: 3 8 1 6 3 5 7 4 9 2 The "3" stands for the NxN size of the square, and the rest of the numbers is the potential magic square. I wrote code that can sum up all the rows and the…
hilbert
  • 5
  • 1
0
votes
1 answer

Magic Square in Python error in Lists but not in Numpy arrays

I have this two versions of a program that generates a magic square of odd order, 1. using numpy arrays : import numpy as np N = 5 magic_square = np.zeros((N, N), dtype=int) n = 1 i, j = 0, N // 2 while n <= N ** 2: magic_square[i, j] = n …
PATHIK GHUGARE
  • 137
  • 1
  • 9
0
votes
2 answers

Magic square in a recursive form in C

I am working on a magic square problem, the size of the square will be an odd number between 3 to 99. Here is the result of a 5x5 square: 15 8 1 24 17 16 14 7 5 23 22 20 13 6 4 3 21 19 12 10 …
Bryce Chan
  • 1,639
  • 11
  • 26
0
votes
2 answers

3x3 magic square with unknown magic constant (sum)

I am trying to fill missing fields in a 3x3 matrix (square) in order to form a magic square (row, columns both diagonals sum are the same, filled with any none repeating positive integers ). an example of such square will be like : [_ _ _] [_ _…
beel
  • 15
  • 6
0
votes
1 answer

I don't understand why test[number-1] is duplicated and returns different boolean values

Here is a subcode of calculating if a given matrix is a magic square. I'm only confused with the test[element -1] that is duplicated and have two different returns. public static boolean testNormal(int[][] matrix, int dim){ int magicConstant =…
0
votes
0 answers

Magic Square Code Single Even number in C#

can you help me to create a logic for magic square metric. In given example, I have created a code for generate Magic Square for odd numbers like 3x3, 5x5, 7x7 metric and double even numbers like 4×4 , 8×8 but unable to found a proper solution for…
jan
  • 1
  • 2
0
votes
1 answer

Magic Square for Even Metric

Anyone can help me to create a logic for even magic square metric. In given example, I have created a code for generate Magic Square for odd numbers like 3x3, 5x5, 7x7 metric but unable to found a proper solution for create even value magic square…
Kundan Sharma
  • 189
  • 1
  • 8
0
votes
2 answers

Magic Square gives ArrayIndexOutOfBoundException

I have been working on Magic Square formation, after reading through the algo, I found out there are certain set of rules to be followed while forming the MagicSquare. The algo which I'm following is : The magic constant will always be equal to…
Alok
  • 8,452
  • 13
  • 55
  • 93
0
votes
1 answer

StackOverflowError in Magic Square program for checking if square is magic

I guess I'll get to the point: my teacher for computer science gave us an assignment where he wanted us to create a program that generates a 3 by 3 magic square (meaning that all rows, columns and diagonals of the square must equal 15). He wanted us…
0
votes
2 answers

Forming a magic square

We define a magic square to be an matrix of distinct positive integers from to where the sum of any row, column, or diagonal of length is always equal to the same number: the magic constant. You will be given a matrix of integers in the…
0
votes
0 answers

Testing Unique Values in Magic Square Array

I'm working on magic square testing program, which determines if the values in a two dimensional array qualify as a magic square. What this means is that every row, column, and diagonal add up to the same values, and more importantly for my case,…
0
votes
2 answers

How do I write a program that reads a square array of integers and determines whether or not it is a Magic square on not?

This is the class square and the main function. const int max_size = 9; class Square { public: void read(); //the square data is read bool is_magic(); // determin if the given square is a magic square private: int…
Richard
  • 41
  • 5