-
-
Save HappyCerberus/d3eb7b713193e6e12c7f918f620e2afc 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
struct Order { | |
uint32_t count; | |
size_t from; | |
size_t to; | |
}; | |
void crateMover9001(std::vector<std::vector<char>>& state, | |
const std::vector<Order>& orders) { | |
for (auto &order : orders) { | |
// view of the last order.count elements in order | |
auto src = state[order.from] | | |
std::views::reverse | std::views::take(order.count) | | |
std::views::reverse; | |
std::ranges::copy(src, std::back_inserter(state[order.to])); | |
// remove the last order.count elements | |
state[order.from].resize(state[order.from].size()-order.count); | |
} | |
} | |
std::string top_crates(const std::vector<std::vector<char>>& state) { | |
std::string result; | |
for (auto &stack : state) { | |
if (stack.size() == 0) continue; | |
result += stack.back(); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment