bnagle
08-30-2007, 05:32 PM
Hello,
I'm trying to take a 2D array of user input display it, rearrange it, and display it again according to Mathew's Algorithm.
The matrices would like this:
ORIGINAL-
[0][0], [0][1], [0][2], [0][3],
[1][0], [1][1], [1][2], [1][3],
[2][0], [2][1], [2][2], [2][3],
[3][0], [3][1], [3][2], [3][3]
REARRANGED
[0][0], [1][1], [2][2], [3][3],
[3][0], [0][1], [1][2], [2][3],
[2][0], [3][1], [0][2], [1][3],
[1][0], [2][1], [3][2], [0][3]
As it is now entering the input and displaying the first table is no problem. After that, though, something goes wrong. The second table does not display, I don't know if the problem is the algorithmRot() function or the tableMaker()
Here are both of those funtions (I would be happy to provide the whole code if necessary, just trying to be concise)
/****A 2d of information is passed to tableMaker() which displays the
matrix, and than passes it up to algorithmRot() which rearranges its pieces
and passes it back.*****/
function algorithmRot(x){
var xRef = [];
for(i=0; i<x.length; i++){
for(j=0; j<x.length; j++){
xRef[i][j]=j;
}}
for(i=0; i<x.length; i++){
var a=xRef[i].splice(-i);
a.reverse()
for(j=0; j<a.length; j++){
xRef[i].splice(0,0,a[j]);// OR TRY unshift(a[j]);
}}
for(i=0; i<x.length; i++){
for(j=0; j<x.length; j++){
x[i][j]=x[xRef[i][j]][j];
}}
}
function tableMaker(x){
var table = [];
var row = [];
var col = [];
var div = document.getElementById("cont");
for(i=0; i<x.length; i++){
table[i] = document.createElement("table");
row[i] = document.createElement("tr");
for(j=0; j<x.length; j++){
col[j] = document.createElement("td");
table[i].appendChild(row[i]);
div.appendChild(table[i]);
}
algorithmRot(x);
/*****2ND TABLE*******/
for(i=0; i<x.length; i++){
table[i] = document.createElement("table");
row[i] = document.createElement("tr");
for(j=0; j<x.length; j++){
col[j] = document.createElement("td");
table[i].appendChild(row[i]);
div.appendChild(table[i]);
}
}
any help will be greatly appreciated as I've knocking my skull against a wall on this one for a while.
-Brad
I'm trying to take a 2D array of user input display it, rearrange it, and display it again according to Mathew's Algorithm.
The matrices would like this:
ORIGINAL-
[0][0], [0][1], [0][2], [0][3],
[1][0], [1][1], [1][2], [1][3],
[2][0], [2][1], [2][2], [2][3],
[3][0], [3][1], [3][2], [3][3]
REARRANGED
[0][0], [1][1], [2][2], [3][3],
[3][0], [0][1], [1][2], [2][3],
[2][0], [3][1], [0][2], [1][3],
[1][0], [2][1], [3][2], [0][3]
As it is now entering the input and displaying the first table is no problem. After that, though, something goes wrong. The second table does not display, I don't know if the problem is the algorithmRot() function or the tableMaker()
Here are both of those funtions (I would be happy to provide the whole code if necessary, just trying to be concise)
/****A 2d of information is passed to tableMaker() which displays the
matrix, and than passes it up to algorithmRot() which rearranges its pieces
and passes it back.*****/
function algorithmRot(x){
var xRef = [];
for(i=0; i<x.length; i++){
for(j=0; j<x.length; j++){
xRef[i][j]=j;
}}
for(i=0; i<x.length; i++){
var a=xRef[i].splice(-i);
a.reverse()
for(j=0; j<a.length; j++){
xRef[i].splice(0,0,a[j]);// OR TRY unshift(a[j]);
}}
for(i=0; i<x.length; i++){
for(j=0; j<x.length; j++){
x[i][j]=x[xRef[i][j]][j];
}}
}
function tableMaker(x){
var table = [];
var row = [];
var col = [];
var div = document.getElementById("cont");
for(i=0; i<x.length; i++){
table[i] = document.createElement("table");
row[i] = document.createElement("tr");
for(j=0; j<x.length; j++){
col[j] = document.createElement("td");
table[i].appendChild(row[i]);
div.appendChild(table[i]);
}
algorithmRot(x);
/*****2ND TABLE*******/
for(i=0; i<x.length; i++){
table[i] = document.createElement("table");
row[i] = document.createElement("tr");
for(j=0; j<x.length; j++){
col[j] = document.createElement("td");
table[i].appendChild(row[i]);
div.appendChild(table[i]);
}
}
any help will be greatly appreciated as I've knocking my skull against a wall on this one for a while.
-Brad