Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r4nd0lph-c/magic_square_generator
This class is an implementation of a normal magic square.
https://github.com/r4nd0lph-c/magic_square_generator
mathematics
Last synced: 2 days ago
JSON representation
This class is an implementation of a normal magic square.
- Host: GitHub
- URL: https://github.com/r4nd0lph-c/magic_square_generator
- Owner: r4nd0lph-c
- Created: 2022-09-27T19:29:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-21T14:31:15.000Z (8 months ago)
- Last Synced: 2024-12-09T05:07:03.680Z (about 2 months ago)
- Topics: mathematics
- Language: Java
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Magic Square generator ✨
### Theory
A Magic square is a square array n×n filled with n² different numbers in such a way that the sum of the numbers in each row, each column and on both diagonals is the same.If the array includes just the positive integers 1, 2, ..., n² the magic square is said to be normal.
* Order is the number of integers along one side n;
* Magic constant is the sum of the numbers in each row, column and on the diagonals, depends only on n and is determined by the formula n×(n²+1)/2.
Normal magic squares exist for all orders of n>=1, with the exception of n=2, although the case of n=1 is trivial - the square consists of a single number.
This class is an implementation of a normal magic square.------------
### Examples
```java
// Creating a class object (size n)
MagicSquare square = new MagicSquare(n);
// Get the order value
square.getOrder();
// Get the magic constant value
square.getMagicConstant();
// Displaying the elements of the magic square on the screen
for (int i = 0; i < square.getOrder(); i++) {
for (int j = 0; j < square.getOrder(); j++) {
System.out.print(square.getBody()[i][j] + " ");
}
System.out.println("");
}
```------------
### Results
![result image](result.png)
------------### References to the sources used
- [Definition](https://en.wikipedia.org/wiki/Magic_square "Definition")
- [Odd Magic Squares | Algorithm](https://www.1728.org/magicsq1.htm "Odd Magic Squares | Algorithm")
- [Doubly Even Magic Squares | Algorithm](https://www.1728.org/magicsq2.htm "Doubly Even Magic Squares | Algorithm")
- [Singly Even Magic Squares | Algorithm](https://www.1728.org/magicsq3.htm "Singly Even Magic Squares | Algorithm")------------