Skip to content

Implementation of Magic Square #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions algorithm/category.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@
"etc": {
"list": {
"flood_fill": "Flood Fill",
"cellular_automata": "Cellular Automata",
"create_maze": "Create Maze"
"cellular_automata": "Cellular Automata",
"create_maze": "Create Maze",
"magic_square": "Magic Square"
},
"name": "Uncategorized"
}
Expand Down
41 changes: 41 additions & 0 deletions algorithm/etc/magic_square/basic/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var i = Math.floor (n/2);
var j = n-1;

for ( var num = 1; num <= n*n; ) {
logTracer._print ( 'i = ' + i );
logTracer._print ( 'j = ' + j );

if( i == -1 && j == n ) {
j = n - 2;
i = 0;

logTracer._print ( 'Changing : ' );
logTracer._print ( 'i = ' + i );
logTracer._print ( 'j = ' + j );
} else {
if ( j == n ) {
j = 0;
logTracer._print ( 'Changing : ' + 'j = ' + j);
}
if ( i < 0 ) {
i = n-1;
logTracer._print ( 'Changing : ' + 'i = ' + i );
}
}

if ( A[i][j] > 0 ) {
logTracer._print ( ' Cell already filled : Changing ' + ' i = ' + i + ' j = ' + j );
j -= 2;
i++;
continue;
} else {
A[i][j] = num++;
tracer._notify( i, j, A[i][j] )._wait ();
tracer._denotify ( i, j );
tracer._select ( i, j )._wait ();
}
j++;
i--;
}

logTracer._print ( 'Magic Constant is ' + n*(n*n+1)/2 );
14 changes: 14 additions & 0 deletions algorithm/etc/magic_square/basic/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var n = 7;
var A = new Array (n);
for (var i = n - 1; i >= 0; i--) {
A[i] = new Array (n);
}

for ( var i = n -1; i >= 0; i-- ) {
for ( var j = n - 1; j >= 0; j-- ) {
A[i][j] = 0;
}
}

var tracer = new Array2DTracer ('Magic Square')._setData(A);
var logTracer = new LogTracer ( 'Console' );
13 changes: 13 additions & 0 deletions algorithm/etc/magic_square/desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Magic Square": "In recreational mathematics, a magic square is an arrangement of distinct numbers (i.e., each number is used once), usually integers, in a square grid, where the numbers in each row, and in each column, and the numbers in the main and secondary diagonals, all add up to the same number, called the magic constant. 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.)",
"Complexity": {
"time": " O(N<sup>2</sup>)",
"space": "O(N<sup>2</sup>)"
},
"References": [
"<a href='https://en.wikipedia.org/wiki/Magic_square'>Wikipedia</a>"
],
"files": {
"basic": "Magic Square"
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy