Replies: 4 comments
-
In this case, it would be |
Beta Was this translation helpful? Give feedback.
-
Actually, |
Beta Was this translation helpful? Give feedback.
-
Oh! Then yes, I believe your code would be the simplest way that does a one-time pass through the enumerable. You could use |
Beta Was this translation helpful? Give feedback.
-
I believe you're looking for const string gameStateString = @"
0 | 1 | 2
3 | 4 | 5
6 | 7 | 8 ";
var gameState =
from m in Regex.Matches(gameStateString, @"[0-9]+")
select int.Parse(m.Value);
var rows = gameState.Batch(3);
var columns = rows.Transpose(); |
Beta Was this translation helpful? Give feedback.
-
For example, if I were writing a Tic Tac Toe implementation which takes an input IEnumerable where the indices are mapped like:
0 | 1 | 2
3 | 4 | 5
6 | 7 | 8
Rows are easy to check, but I don't know of a single-method way to get the columns. I have settled on the following:
I wonder if there is a cleaner way to do this. LINQ's GroupBy does not have access to the index of each element, so I can't do
index % 3
or something similar. I'm not sure how frequent of a use case this is, but it might be worth considering adding aColumnize
method to MoreLINQ, or maybe just a GroupBy method which exposes the index of each elemenet.Beta Was this translation helpful? Give feedback.
All reactions