magic-square

Brute force magic squares

非 Y 不嫁゛ 提交于 2019-12-10 20:38:46
问题 Basically I have a 3 x 3 grid that is filled with two digit numbers 00 - 99. Some of the numbers are given as input the rest are unknown. What are some suggestions on how to solve such a problem with brute force in C? EDIT: Sorry I forgot part of the problem. Every row and column and diagonal must add up to the same number. I don't want any code just some ideas to get started with algorithm 回答1: There is a simple recursive solution to your problem, which is an example of a type of brute force

How to create a symmetric matrix of 1's and 0's with constant row and column sum

◇◆丶佛笑我妖孽 提交于 2019-12-09 13:13:46
问题 I'm trying to find an elegant algorithm for creating an N x N matrix of 1's and 0's, under the restrictions: each row and each column must sum to Q (to be picked freely) the diagonal must be 0's the matrix must be symmetrical. It is not strictly necessary for the matrix to be random (both random and non-random solutions are interesting, however), so for Q even, simply making each row a circular shift of the vector [0 1 1 0 ... 0 0 0 ... 0 1 1] (for Q=4) is a valid solution. However, how to do

Writing a function that returns boolean true if matrix forms a magic square without importing numpy

梦想的初衷 提交于 2019-12-02 16:19:26
问题 I already wrote one part of the program which is below: def matrix_is_square(matrix): for i in range(len(matrix)): if len(matrix[i]) != len(matrix): return False return True This function returns True if matrix is a square matrix, otherwise, it returns False. HOWEVER, HERE'S WHEN THE PROBLEM BEGINS. I Have to write a second function that determines if the function is Magic square. A square matrix forms a magic square if the following conditions are met: The elements of the matrix are numbers

How to create a magic square in PHP?

◇◆丶佛笑我妖孽 提交于 2019-12-01 22:00:55
问题 I'd like to try my hand at creating a Magic Square in PHP (i.e. a grid of numbers that all add up to the same value), but I really don't know where to start. I know of the many methods that create magic square, such as starting "1" at a fixed position, then moving in a specific direction with each iteration. But that doesn't create a truly randomized Magic Square, which is what I'm aiming for. I want to be able to generate an N-by-N Magic Square of N² numbers where each row and column adds up

How to create a magic square in PHP?

本秂侑毒 提交于 2019-12-01 21:11:06
I'd like to try my hand at creating a Magic Square in PHP (i.e. a grid of numbers that all add up to the same value), but I really don't know where to start. I know of the many methods that create magic square, such as starting "1" at a fixed position, then moving in a specific direction with each iteration. But that doesn't create a truly randomized Magic Square, which is what I'm aiming for. I want to be able to generate an N-by-N Magic Square of N² numbers where each row and column adds up to N(N²+1)/2 (e.g. a 5x5 square where all rows/columns add up to 65 — the diagonals don't matter). Can

Testing a .txt file for a Magic Square Java

此生再无相见时 提交于 2019-11-29 16:07:06
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 square. n is equal to the square root of the array list's length. If it isn't a perfect square it immediately fails the magic square test. Anyway I have it almost completed; I just don't seem to understand what my professor is telling/asking us to do in the final step of the magic square test. All the testing before these final four steps works

Testing a .txt file for a Magic Square Java

て烟熏妆下的殇ゞ 提交于 2019-11-28 09:36:49
问题 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 square. n is equal to the square root of the array list's length. If it isn't a perfect square it immediately fails the magic square test. Anyway I have it almost completed; I just don't seem to understand what my professor is telling/asking us to