public override ulong Part2(string input) { var traversals = new List <(int x, int y)> { (1, 1), (3, 1), (5, 1), (7, 1), (1, 2) }; var map = new LoopingMap(input); var result = traversals .Select((slopes, y) => { var treesCutDown = TraverseMap(map, slopes.x, slopes.y); return(treesCutDown); }) .Aggregate(1Lu, (acc, current) => { var cast = (ulong)current; return(acc * (cast)); }); return(result); }
public void GetPosition_ReturnsCorrectInformation(int x, int y, PositionInformation expected) { var input = @"..##....... #...#...#.. .#....#..#. ..#.#...#.# .#...##..#. ..#.##..... .#.#.#....# .#........# #.##...#... #...##....# .#..#...#.#"; var map = new LoopingMap(input); var actual = map.GetPosition(x, y); Assert.Equal(expected, actual); }
public int TraverseMap(LoopingMap map, int xSlope, int ySlope) { var x = 0; var y = 0; var cutdownTrees = 0; do { y += ySlope; x += xSlope; var currentTile = map.GetPosition(x, y); if (currentTile == PositionInformation.Tree) { cutdownTrees++; } }while (y < map.Height - 1); return(cutdownTrees); }
public override ulong Part1(string input) { var map = new LoopingMap(input); return((ulong)TraverseMap(map, 3, 1)); }