aoc2020/day3/part1/main.d
2020-12-04 09:27:43 +01:00

37 lines
683 B
D

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