how could this array: a b c d e f g h i j k l m n o p be rearranged into a 7 length array (lets call x) where: a = x[1,1] b = x[2,2] ... e = x[2,1] ... k=x[5,2] ... etc As below: 1,1 2,2 3,3 4,4 2,1 3,2 4,3 5,3 3,1 4,2 5,2 6,2 4,1 5,1 6,1 7,1
I am trying to do this with java
Most certainly. You could create an instance of int [] x = new int [2]. Then create a class of 'points' with an array of x as an instance variable. You might also look at ArrayList for a more versatile implementation. http://docs.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html
are you just trying to do this for the particular mentioned case, or do you need a general solution for cases other than 7? Also, x is not an array of length 7 if it has two dimensions.
don't worry, i've already solved it. Thanks anyway
So are you willing to share your solution for the benefit of other students (and then perhaps close the question)?
function transform(x,y,size) { int X = x + y - 1; int Y; if (X <= size) Y = y; else Y = y + size - X; Integer out[] = {X,Y}; return out; } So in this case transform(3,4,4) = {6,2}
Yeah, I'll close it now
Out of curiosity, what do you need this function for?
Interesting. I have already got a method of finding the minimal sum from the top to bottom of a triangle of numbers. I now need to do this with a square. So I am basically 'turning the square' into 2 triangles. Complicated, I know
Join our real-time social learning platform and learn together with your friends!