java - How do I generate random address of a multi-dimension array? -


i'm stuck please help!

the size of matrix n , m.

for eg-
n=4, m=3
1, 2, 3, 4
5, 6, 7, 8
9, 10, 11, 12

how generate random address?

for eg- (0,0), (1,1), (1,2), (2,2), (3,3);
-> last address should represents end element of matrix.
-> next address should address of element either right or down.

    random random = new random();     list<integer> list = new arraylist<>();     int random_int_1 = 0, random_int_2 = 0;     int = 0;     list.add(2);     list.add(1);     while (list.get(i) < list.get(i + 1)) {         list.add(random_int_1 = random.nextint(5));         list.add(random_int_2 = random.nextint(5));         i++;     }     (int j = 0; j < list.size() - 1; j++) {         if (list.get(j) < list.get(j + 1)) system.out.print(list.get(j));     } 

and i'm improving skills solving such examples
please tell me how should solve such problems.
give to-do tasks

oke, i'll try along. per example have current point, there code should move point randomly right , down. i'm still bit fuzzy on move either or move both question, that's not important, around step 2 , 3 can define logic either, or either or both. (right it's possible point not move! think this!)

what algorithm should following:

  1. determine if currentpoint on edges of matrix (location m=3, n=4 cannot move)
  2. if it's possible move right, create random 0 or 1. if 0 nothing, if 1 move right.
  3. if it's possible move down, create random 0 or 1. if 0 nothing, if 1 move down.
  4. append location list , update current position, go step 1.

you can either achieve loops or recursive algorithm. can solve problem these todo's :)


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -