diff --git a/day3/part1/main.d b/day3/part1/main.d index df48eda..4e3dc00 100644 --- a/day3/part1/main.d +++ b/day3/part1/main.d @@ -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; } diff --git a/day3/part2/main.d b/day3/part2/main.d index 088c826..1d793d7 100644 --- a/day3/part2/main.d +++ b/day3/part2/main.d @@ -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; }