aoc2020/day3/part1/main.d

39 lines
691 B
D

import std;
void main()
{
File("input", "r").byLineCopy.array.countTrees(3, 1).writeln;
}
ulong countTrees(T)(T input, int angleX, int angleY)
in(input.length > 0)
{
immutable width = input[0].length;
size_t count = 0;
size_t x = 0;
return input.stride(angleY).map!((row) {
auto result = row[x];
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);
}