mirror of
https://github.com/HenkKalkwater/aoc-2020
synced 2024-11-22 19:15:18 +00:00
32 lines
1.2 KiB
D
32 lines
1.2 KiB
D
|
import std.algorithm;
|
||
|
import std.format;
|
||
|
import std.range;
|
||
|
import std.stdio;
|
||
|
import std.uni;
|
||
|
|
||
|
void run(string[] args) {
|
||
|
ulong count = stdin.byLine.countTrees;
|
||
|
writeln(count);
|
||
|
}
|
||
|
|
||
|
ulong countTrees(Range)(Range lines) if (isInputRange!Range) {
|
||
|
return lines.enumerate.filter!(x => (x.value[x.index * 3 % x.value.length] == '#')).count;
|
||
|
}
|
||
|
|
||
|
unittest {
|
||
|
string[] field = [
|
||
|
"..##.........##.........##.........##.........##.........##.......",
|
||
|
"#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..",
|
||
|
".#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.",
|
||
|
"..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#",
|
||
|
".#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.",
|
||
|
"..#.##.......#.##.......#.##.......#.##.......#.##.......#.##.....",
|
||
|
".#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#",
|
||
|
".#........#.#........#.#........#.#........#.#........#.#........#",
|
||
|
"#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...",
|
||
|
"#...##....##...##....##...##....##...##....##...##....##...##....#",
|
||
|
".#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#"
|
||
|
];
|
||
|
assert(field.countTrees == 7);
|
||
|
}
|