1
0
Fork 0
mirror of https://github.com/HenkKalkwater/aoc-2020 synced 2024-11-22 19:15:18 +00:00
aoc-2020/source/day3.d

32 lines
1.2 KiB
D
Raw Normal View History

2020-12-03 09:50:55 +00:00
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);
}