So I have a one-dimensional boolean array representing a two-dimensional shape. It's numbered from 0-8, representing a 3x3 square with this index:
012
345
678
I wrote a function to rotate the shape clockwise using the following code:
newShape[2]=oldShape[0];
newShape[5]=oldShape[1];
newShape[8]=oldShape[2];
newShape[1]=oldShape[3];
newShape[4]=oldShape[4];
newShape[7]=oldShape[5];
newShape[0]=oldShape[6];
newShape[3]=oldShape[7];
newShape[6]=oldShape[8];
Now, when the input of the function is:
false-true-false
true--true-false
false-false-false
The expected output would be:
false-true-false
false-true--true
false-false-false
However, I instead get:
false-true-false
true--true--true
false-true-false
This is not only the result of newShape, but also the result of oldShape, even though I never change oldShape. It would seem that the assignments are changing around references to variables, but not their actual values. How can I fix this?
newShapedeclared? How isoldShapedeclared? What are you passing in and out of your method? Adding some actual code to your question would make it much clearer. Ideally you could even include an MCVE.newShapeandoldShapearray references point to the same array, assigning values to array elements innewShapewill still overwriteoldShapearray elements, because, they are essentially referencing the same array.