Skip to content

Instantly share code, notes, and snippets.

@HappyCerberus
Created December 1, 2021 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HappyCerberus/de537637a744214e072159becb2d8d33 to your computer and use it in GitHub Desktop.
Save HappyCerberus/de537637a744214e072159becb2d8d33 to your computer and use it in GitHub Desktop.
uint32_t count_increasing_windows(std::istream &input) {
auto sliding_window_view = std::ranges::istream_view<uint32_t>(input)
| std::ranges::views::transform([e1 = 0, e2 = 0, e3 = 0](uint32_t curr) mutable {
e1 = std::exchange(e2, std::exchange(e3, curr));
return e1 + e2 + e3;
});
return std::ranges::count_if(sliding_window_view,
[prev = std::numeric_limits<uint32_t>::max(), drop = 2]
(uint32_t curr) mutable {
if (drop > 0) {
drop--;
return false;
}
return std::exchange(prev, curr) < curr; });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment