Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
It does actually matter, because every language has its own tests. It is hard to validate and fix a problem if one doesn't know where to start looking.
What language ( of the twelve ) ?
You are correct. Thanks for replying with the clarification. :)
Here is how I am interpretting your question
You are curious how the CellsInBox gets the cells using only the CellsInRow method. In other words, you want to know why it doesn't also need to use the CellsInCol method. If that is what your question intends -- the reason CellsInCol is not uses is because the collection of cells in a row span the columns and CellsInBox exploits this with a combination of Skip & Take.
It might make more sense if I describe the logic for CellsInBox.
The CellsInBox method takes an integer 0..8 for the 9 three-by-three boxes.
The 3x3 boxes are laid-out like this:
To get the cells in the box, the method takes the box number and gets the cells in 3 rows that correspond to the location of the box, pulling out just the 3 for that box.
So take the center box 4 for example -- to get the cells for box 4:
How do we get the middle three cells from a row? Skip(3).Take(3)
The math for the Skip is
3 * (box % 3)
-- so in box 4's case:3 * (4 % 3) == 3
, then the Take(3) portion gives us the values for the 3 columns in that row.Suppose we had box 3 instead -- in that case we still take the rows 3, 4 & 5, but we want the first three cells of each of those rows instead. The math in that case causes the algorithm to: Skip(0).Take(3). In this box = 3 case, the rowStart math =
3 - (3 % 3) = 3
, and the skip math works out:3 * (3 % 3) == 0
-- skipping 0 is valid, so I didn't need a special case.The algorithm could have just as easily taken the cells from the cellsInCol method, but because of how the board-array is laid-out, the CellsInRow is more efficient. I take that into consideration when using it for CodeWars kata that could have a performance requirement.