Repository navigation
Replies: 4 comments
|
In this case, it would be |
0 replies
|
Actually, |
0 replies
|
Oh! Then yes, I believe your code would be the simplest way that does a one-time pass through the enumerable. You could use |
0 replies
|
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(); |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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 % 3or something similar. I'm not sure how frequent of a use case this is, but it might be worth considering adding aColumnizemethod to MoreLINQ, or maybe just a GroupBy method which exposes the index of each elemenet.All reactions