day3: simplify countTrees
This commit is contained in:
parent
825cf44894
commit
396cc056ac
2 changed files with 5 additions and 13 deletions
|
@ -5,16 +5,12 @@ void main()
|
|||
File("input", "r").byLineCopy.array.countTrees(3, 1).writeln;
|
||||
}
|
||||
|
||||
ulong countTrees(const char[][] input, int angleX, int angleY)
|
||||
auto 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;
|
||||
})
|
||||
return input.stride(angleY).enumerate
|
||||
.map!(row => row.value[(row.index * angleX) % width])
|
||||
.filter!(pos => pos == '#')
|
||||
.count;
|
||||
}
|
||||
|
|
|
@ -17,12 +17,8 @@ auto 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;
|
||||
})
|
||||
return input.stride(angleY).enumerate
|
||||
.map!(row => row.value[(row.index * angleX) % width])
|
||||
.filter!(pos => pos == '#')
|
||||
.count;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue