Skip to content

Instantly share code, notes, and snippets.

@Qqwy
Created September 9, 2019 19:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qqwy/d76f50fa8f6d5f95c57e79d110305e03 to your computer and use it in GitHub Desktop.
Save Qqwy/d76f50fa8f6d5f95c57e79d110305e03 to your computer and use it in GitHub Desktop.
#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";
}
}
@Qqwy
Copy link
Author

Qqwy commented Sep 9, 2019

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment