Created
February 24, 2017 20:09
-
-
Save hikilaka/fe294453bf690ca9097883729bd180c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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