Last active
June 23, 2021 02:40
-
-
Save Kiandisor/411f7b8eb507d1c1563beb51f0966e64 to your computer and use it in GitHub Desktop.
[2021-06-21] Challenge #395 [Easy] Nonogram row - C++ 20 Solution
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
[[nodiscard]] std::vector<std::size_t> solve_nonogram(std::ranges::contiguous_range auto&& problem) { | |
namespace ranges = std::ranges; | |
std::vector<std::size_t> streaks {}; | |
streaks.reserve(problem.size()); | |
ranges::split_view splits {problem,0}; | |
auto add_size {[&streaks](auto&& range) { | |
if (const auto size {ranges::distance(range)}; size!=0) { | |
streaks.push_back(size); | |
} | |
}}; | |
ranges::for_each(splits,add_size); | |
streaks.shrink_to_fit(); | |
return streaks; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment