Skip to content

Instantly share code, notes, and snippets.

@hikilaka
Created February 24, 2017 20:09
Show Gist options
  • Save hikilaka/fe294453bf690ca9097883729bd180c5 to your computer and use it in GitHub Desktop.
Save hikilaka/fe294453bf690ca9097883729bd180c5 to your computer and use it in GitHub Desktop.
bool isLucky(int n) {
auto sum = [](auto c) {
return std::accumulate(std::begin(c), std::end(c), 0);
};
auto str = std::to_string(n);
auto left = str.substr(0, str.size() / 2);
auto right = str.substr(str.size() / 2);
return sum(left) == sum(right);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment