Parser.cs 839 B

12345678910111213141516171819202122232425262728293031323334
  1. using System.Text.RegularExpressions;
  2. namespace Day10;
  3. public partial class Parser
  4. {
  5. [GeneratedRegex(@".*")]
  6. private partial Regex LineMatch();
  7. public Grid Parse(string inputFile)
  8. {
  9. using var reader = File.OpenText(inputFile);
  10. var line = reader.ReadLine()!;
  11. var width = line.Length;
  12. var row = 0;
  13. var tiles = new Tile[width, width];
  14. while (!reader.EndOfStream)
  15. {
  16. if (row != 0)
  17. {
  18. line = reader.ReadLine()!;
  19. }
  20. for (var col = 0; col < line.Length; col++)
  21. {
  22. tiles[col, row] = new Tile(line[col], new GridPoint(col, row));
  23. }
  24. row++;
  25. }
  26. return new Grid(tiles, width, width);
  27. }
  28. }