Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

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

OpenStudy (anonymous):

I am trying to do this with java

OpenStudy (espex):

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

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

don't worry, i've already solved it. Thanks anyway

OpenStudy (anonymous):

So are you willing to share your solution for the benefit of other students (and then perhaps close the question)?

OpenStudy (anonymous):

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}

OpenStudy (anonymous):

Yeah, I'll close it now

OpenStudy (anonymous):

Out of curiosity, what do you need this function for?

OpenStudy (anonymous):

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!