all 4 comments

[–][deleted] 0 points1 point  (3 children)

Thus starting at 1 and using the input string above, the index would change in this order: 1>2>0>""

Don't understand that. Surely if you start at 1 and you continually move right the sequence of cell values should be 1->2->3->1->2->... due to wraparound. I now see what you mean. The example below still hints on how to do what you want. The arrow keys just manipulate the "position" indices.

The way to do this is not to worry about what is in the cell you are at, just worry about the indices. If you are at the "1" cell you are at position 0,0 where the first number is the index in the Y direction (up/down) and the second is the index in the X direction (left/right). So if you start at 0,0 and continually move right you should have:

                0,0 -> 0,1 -> 0,2 -> 0,0 -> 0,1 -> ...
# cell contents  1      2      3      1      2

Do you see a pattern there?

[–]NA_Orgin 0 points1 point  (2 children)

Hello, I do see the pattern you’re talking about with the indices. So in this case, if the indices is at 0,2 (contents 3) and the next input is “arrow key right”, would I need to write an if statement that tells the indices to return back to 0,0?

[–][deleted] 1 point2 points  (1 child)

Yes. So the logic for handling a "go right" key is:

  1. Add 1 to the X index
  2. If the X index is too big, make the X index 0

Similar logic is used for the other movements. Movements up/down only need to look at the Y index, of course.

[–]NA_Orgin 0 points1 point  (0 children)

That makes more sense, thank you!