Iterating all diagonal slices of a matrix

  • Thread starter Thread starter QuarkCharmer
  • Start date Start date
  • Tags Tags
    Matrix
Click For Summary
The discussion focuses on efficiently slicing a character array into its diagonals, regardless of the programming language used, with a specific example provided. The character array is defined as mxn with unknown dimensions, and the goal is to extract diagonals in a specific direction. The user struggles with implementing nested loops to achieve this and plans to test three cases based on the relationship between m and n (equal, greater, or less). A proposed solution involves starting from specific coordinates and iterating through the array by adjusting the indices diagonally until they go out of bounds. The challenge lies in managing the complexity of the cases and ensuring efficient iteration through the array.
QuarkCharmer
Messages
1,049
Reaction score
3
I'm writing something in Java, (but the language doesn't really matter for this problem), and I can't figure out any way to do this efficiently.

I have some character array with a bunch of stuff in it, and I need to slice it into it's diagonals, for example:

[a,b,c; d,e,f; g,h,i]

becomes: [a], [d,b], [g,e,c], [f,h], (this is just one "direction" of slicing)

But the problem is, the character array is mxn with unknown dimensions!

No matter how I nestle loops, I just can't make this happen. Tomorrow morning I am going to try 3 cases, mxn where m=n, m>n, and m<n, but then it seems I must break each of those cases into 2-3 other parts to iterate through, and it blows out of proportion from there.

Any idea how I could accomplish this task?
 
Technology news on Phys.org
You start at ##(i, j) = (i_0, 0)## or ##(i, j) = (0, j_0)## and in every iteration send ##(i, j) \mapsto (i \pm 1, j \pm 1)## (with the two ##\pm## chosen depending on the direction you want to run) until one of the variables runs out of bounds (i.e. ##i < 0##, ##i \ge m##, ##j < 0## or ##j \ge n##).
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 25 ·
Replies
25
Views
2K
  • · Replies 15 ·
Replies
15
Views
5K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 33 ·
2
Replies
33
Views
2K
Replies
2
Views
2K
Replies
31
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K