AdventOfCode2021/source/day1/part2.d

17 lines
529 B
D
Raw Permalink Normal View History

2021-12-01 07:39:14 +00:00
module day1.part2;
import std.stdio;
import util.fileutils;
void slidingSum() {
int[] values = readInts("source/day1/input.txt");
int previousSum = values[0] + values[1] + values[2];
int increaseCount = 0;
// Iterate over indices 1 to 2 minus the length of the array.
2021-12-01 07:39:14 +00:00
foreach (i; 1 .. (values.length - 2)) {
int currentSum = values[i] + values[i + 1] + values[i + 2];
2021-12-01 07:57:31 +00:00
if (currentSum > previousSum) increaseCount++;
2021-12-01 07:39:14 +00:00
previousSum = currentSum;
}
writefln("%d", increaseCount);
}