Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HappyCerberus/8b4b810b770be7f364e284b34c6fd543 to your computer and use it in GitHub Desktop.
Save HappyCerberus/8b4b810b770be7f364e284b34c6fd543 to your computer and use it in GitHub Desktop.
uint32_t count_increasing_windows(std::istream &input) {
uint32_t e1 = 0, e2 = 0, e3 = 0, prev_sum = std::numeric_limits<uint32_t>::max(), drop = 2, cnt = 0;
for (uint32_t v : std::ranges::istream_view<uint32_t>(input)) {
e1 = std::exchange(e2, std::exchange(e3, v));
if (drop > 0) {
drop--;
continue;
}
if (std::exchange(prev_sum, e1 + e2 + e3) < e1 + e2 + e3)
cnt++;
}
return cnt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment