Created
September 9, 2019 19:15
-
-
Save Qqwy/d76f50fa8f6d5f95c57e79d110305e03 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
#include <iostream> | |
#include <vector> | |
auto continuation = [](auto && val){return [=](auto && cont) { return cont(val);};}; | |
auto style = [](const auto &val) { return val; }; | |
auto mod = [](auto &&modv) { return [=](auto &&truecont){ return [=](auto &&falsecont) { return [=](auto &&val) { if (val % modv) { return truecont(val); } else { return falsecont(val); }; }; }; }; }; | |
auto passing = [](auto &&val) { return [=](auto &&cont){ return [=](auto &&) {return cont(val);};};}; | |
bool isLeapYear(int year){ | |
return (continuation) | |
(year) | |
((continuation) | |
(4) | |
(mod) | |
((continuation) | |
(false) | |
(passing) | |
(style) | |
) | |
((continuation) | |
(100) | |
(mod) | |
((continuation) | |
(true) | |
(passing) | |
(style)) | |
((continuation) | |
(400) | |
(mod) | |
((continuation) | |
(true) | |
(passing) | |
(style) | |
) | |
((continuation) | |
(false) | |
(passing) | |
(style) | |
) | |
) | |
) | |
); | |
} | |
int main() { | |
std::vector<int> years{2019, 2020, 2021}; | |
for(auto year : years) { | |
std::cout << year << (isLeapYear(year) ? " is " : " is not " ) << "a leap year\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a submission to the 'is leap year' Bad Code challenge on Reddit: https://www.reddit.com/r/badcode/comments/cw5n21/bad_code_coding_challenge_18_is_leap_year/ezq904o/