private static IEnumerable<int[]> GetVerticalPaths(Grid2d grid) { for (int x = 0; x < grid.Width; x++) { for (int y = 0; y < grid.Height - PathLength + 1; y++) { yield return new int[PathLength] { grid[x,y], grid[x,y+1], grid[x,y+2], grid[x,y+3] }; } } }
private static IEnumerable<int[]> GetDiagonalNWSEPaths(Grid2d grid) { for (int x = 0; x < grid.Width - PathLength + 1; x++) { for (int y = 0; y < grid.Height - PathLength + 1; y++) { yield return new int[PathLength] { grid[x,y], grid[x+1,y+1], grid[x+2,y+2], grid[x+3,y+3] }; } } }
private static IEnumerable<int[]> GetHorizontalPaths(Grid2d grid) { for (int x = 0; x < grid.Width - PathLength + 1; x++) { for (int y = 0; y < grid.Height; y++) { yield return new int[PathLength] { grid[x,y], grid[x+1,y], grid[x+2,y], grid[x+3,y] }; } } }
public static Grid2d Parse(string content) { Contract.Requires <ArgumentNullException>(content != null); var lines = content.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var values = lines.Select(l => l.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)).ToList(); var result = new Grid2d(); result.m_Values = new int[values.Count(), values.First().Count()]; for (int i = 0; i < values.Count(); i++) { for (int j = 0; j < values.First().Count(); j++) { result.m_Values[i, j] = int.Parse(values[i][j]); } } return(result); }
public static Grid2d Parse(string content) { Contract.Requires<ArgumentNullException>(content != null); var lines = content.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var values = lines.Select(l=>l.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)).ToList(); var result = new Grid2d(); result.m_Values = new int[values.Count(), values.First().Count()]; for (int i = 0; i < values.Count(); i++) { for (int j = 0; j < values.First().Count(); j++) { result.m_Values[i, j] = int.Parse(values[i][j]); } } return result; }