Created
December 1, 2021 12:49
-
-
Save HappyCerberus/8b4b810b770be7f364e284b34c6fd543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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