import std; void main() { File("input", "r").byLineCopy.array.countTrees(3, 1).writeln; } auto countTrees(const char[][] input, int angleX, int angleY) in(input.length > 0) { immutable width = input[0].length; return input.stride(angleY).enumerate .map!(row => row.value[(row.index * angleX) % width]) .filter!(pos => pos == '#') .count; } unittest { auto input = `..##....... #...#...#.. .#....#..#. ..#.#...#.# .#...##..#. ..#.##..... .#.#.#....# .#........# #.##...#... #...##....# .#..#...#.#`.byChar.splitter("\n").map!array.array; assert(input.countTrees(3, 1) == 7); }