day3: cleanup
This commit is contained in:
parent
3dd39bac7a
commit
825cf44894
2 changed files with 3 additions and 5 deletions
|
@ -5,14 +5,13 @@ void main()
|
||||||
File("input", "r").byLineCopy.array.countTrees(3, 1).writeln;
|
File("input", "r").byLineCopy.array.countTrees(3, 1).writeln;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong countTrees(T)(T input, int angleX, int angleY)
|
ulong countTrees(const char[][] input, int angleX, int angleY)
|
||||||
in(input.length > 0)
|
in(input.length > 0)
|
||||||
{
|
{
|
||||||
immutable width = input[0].length;
|
immutable width = input[0].length;
|
||||||
size_t count = 0;
|
|
||||||
size_t x = 0;
|
size_t x = 0;
|
||||||
return input.stride(angleY).map!((row) {
|
return input.stride(angleY).map!((row) {
|
||||||
auto result = row[x];
|
immutable result = row[x];
|
||||||
x = (x + angleX) % width;
|
x = (x + angleX) % width;
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
|
@ -35,5 +34,4 @@ unittest
|
||||||
.#..#...#.#`.byChar.splitter("\n").map!array.array;
|
.#..#...#.#`.byChar.splitter("\n").map!array.array;
|
||||||
|
|
||||||
assert(input.countTrees(3, 1) == 7);
|
assert(input.countTrees(3, 1) == 7);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ in(input.length > 0)
|
||||||
immutable width = input[0].length;
|
immutable width = input[0].length;
|
||||||
size_t x = 0;
|
size_t x = 0;
|
||||||
return input.stride(angleY).map!((row) {
|
return input.stride(angleY).map!((row) {
|
||||||
auto result = row[x];
|
immutable result = row[x];
|
||||||
x = (x + angleX) % width;
|
x = (x + angleX) % width;
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue