Last active
December 4, 2024 07:12
-
-
Save jbevain/46c84a3a2e0930865b299e5595291630 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var lines = new List<string>(); | |
| using var reader = new StreamReader(args[0]); | |
| while (reader.ReadLine() is string line) | |
| { | |
| lines.Add(line); | |
| } | |
| var grid = new char[lines.Count, lines[0].Length]; | |
| for (var i = 0; i < lines.Count; i++) | |
| { | |
| for (var j = 0; j < lines[i].Length; j++) | |
| { | |
| grid[i, j] = lines[i][j]; | |
| } | |
| } | |
| lines.Clear(); | |
| int xmas = 0; | |
| for (int i = 0; i < grid.GetLength(0); i++) | |
| { | |
| for (int j = 0; j < grid.GetLength(1); j++) | |
| { | |
| if (i < grid.GetLength(0) - 2 && j < grid.GetLength(1) - 2) | |
| { | |
| xmas += ((grid[i + 0, j], grid[i + 0, j + 1], grid[i + 0, j + 2]), | |
| (grid[i + 1, j], grid[i + 1, j + 1], grid[i + 1, j + 2]), | |
| (grid[i + 2, j], grid[i + 2, j + 1], grid[i + 2, j + 2])) switch | |
| { | |
| (('M', _, 'S'), | |
| (_, 'A', _), | |
| ('M', _, 'S')) => 1, | |
| (('S', _, 'M'), | |
| (_, 'A', _), | |
| ('S', _, 'M')) => 1, | |
| (('M', _, 'M'), | |
| (_, 'A', _), | |
| ('S', _, 'S')) => 1, | |
| (('S', _, 'S'), | |
| (_, 'A', _), | |
| ('M', _, 'M')) => 1, | |
| _ => 0 | |
| }; | |
| } | |
| } | |
| } | |
| Console.WriteLine(xmas); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment