i'm trying to create a one tough puzzle solver thing, can anyone help me on why this is only showing 4 numbers in console instead of 8.
s1 = [1,-4,-1,2];
s2 = [2,-4,-3,4];
s3 = [4,-1,-3,3];
s4 = [3,-3,-4,4];
s5 = [2,-4,-3,2];
s6 = [4,-2,-4,3];
s7 = [1,-2,-4,2];
s8 = [1,-1,-4,4];
s9 = [1,-3,-3,4];
pieces = [s1,s2,s3,s4,s5,s6,s7,s8,s9];
correct =[];
pog = 0;
function setup() {
createCanvas(400, 400);
for(i=0;i<8;i++){
for (h=1;h<8;h++){
if(h==i){
i++;
}
for(j=0;j<4;j++){
if(pieces.at(i).at(1) == -pieces.at(h).at(3)){
console.log(h);
break
i=h;
} else {
shiftL(pieces.at(h));
}
}
}
}
}
//BTW the piece above another piece is 3 pieces away!!!!
function draw() {
background(220);
frameRate(1);
}
function shiftL(array) {
let sV = array.at(0);
array.splice(0,1);
array.splice(array.length-1,0,sV);
}
i'm trying to output more but it only shows 1,3,7,2. i'm adding more text so that this is able to be published.
It is pretty hard to tell what you are trying to do and your for loop logic is very convoluted, here it is with comments and log statements:
for (i = 0; i < 8; i++) {
console.log(`begin i = ${i}`);
for (h = 1; h < 8; h++) {
console.log(`begin h = ${h}`);
// When i == 0 this will be false
if (h == i) {
// when i == 1 and h == 1, this increments i to 2
// on the next pass through the for loop that increments h,
// i == 2 and h == 2, this increments i to 3
// so on, for each iteration of the inner loop, i gets incremented
i++;
console.log(`incremented i to ${i}`);
}
// this loop should happen just 14 times, 7 times for i = 0 and then 7
// times starting with i = 1
for (j = 0; j < 4; j++) {
if (pieces.at(i).at(1) == -pieces.at(h).at(3)) {
console.log(h);
// exits the loop for j
break;
// unreachable, never happens
console.log("never happens");
i = h;
} else {
console.log(`shiftL(piecese.at(${h}))`);
shiftL(pieces.at(h));
}
}
}
}
Hopefully this helps you figure out why this code is not working properly.