How do you iterate "vertically" over a 2-D array?

jmh530 john.michael.hall at gmail.com
Tue Oct 9 15:27:10 UTC 2018


On Tuesday, 9 October 2018 at 10:52:47 UTC, Chris Katko wrote:
> I have a 2-D array:
>
> int[5][5] data =
> 	[
> 		[1, 0, 1, 0, 0],
> 		[1, 0, 1, 0, 0],
> 		[1, 0, 1, 1, 1],
> 		[1, 0, 0, 1, 0],
> 		[1, 1, 1, 1, 0]
> 	];
>
>
> 1 - Is there a way to foreach vertically through that? (that 
> is, rotated 90 degrees from the usual iteration.)
>
> 2 - Is there a way to send that "vertical slice" to a function?
>
> [snip]

mir has a lot of functionality that can be helpful here, byDim 
[1] comes to mind. Of course it also has transposed, but you can 
combine byDim with count to achieve the same thing as what you're 
trying.

http://docs.algorithm.dlang.io/latest/mir_ndslice_topology.html#.byDim



More information about the Digitalmars-d-learn mailing list