forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
41 lines (36 loc) · 834 Bytes
/
code.js
File metadata and controls
41 lines (36 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 );