2020-12-04 09:24:06 +01:00
|
|
|
import std;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
File("input", "r").byLineCopy.array.countTrees(3, 1).writeln;
|
|
|
|
}
|
|
|
|
|
2020-12-04 09:27:43 +01:00
|
|
|
ulong countTrees(const char[][] input, int angleX, int angleY)
|
2020-12-04 09:24:06 +01:00
|
|
|
in(input.length > 0)
|
|
|
|
{
|
|
|
|
immutable width = input[0].length;
|
|
|
|
size_t x = 0;
|
|
|
|
return input.stride(angleY).map!((row) {
|
2020-12-04 09:27:43 +01:00
|
|
|
immutable result = row[x];
|
2020-12-04 09:24:06 +01:00
|
|
|
x = (x + angleX) % width;
|
|
|
|
return result;
|
|
|
|
})
|
|
|
|
.filter!(pos => pos == '#')
|
|
|
|
.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
unittest
|
|
|
|
{
|
|
|
|
auto input = `..##.......
|
|
|
|
#...#...#..
|
|
|
|
.#....#..#.
|
|
|
|
..#.#...#.#
|
|
|
|
.#...##..#.
|
|
|
|
..#.##.....
|
|
|
|
.#.#.#....#
|
|
|
|
.#........#
|
|
|
|
#.##...#...
|
|
|
|
#...##....#
|
|
|
|
.#..#...#.#`.byChar.splitter("\n").map!array.array;
|
|
|
|
|
|
|
|
assert(input.countTrees(3, 1) == 7);
|
|
|
|
}
|