Just print True all the time. Half the time it will be correct and the client will be happy, and the other half the time, they will open a ticket that will be marked as duplicate and closed.
Reminds me of the fake thermometers being sold during the peak of COVID that weren’t actually thermometers but just displayed numbers to make people think they were.
I definitely have one of these.
The number of comments posting a better solution is funny and somewhat concerning.
Yeah, “just use modulo” - no shit, you must be some kind of master programmer
while (true){ if (number == 0) return true; if (number == 1) return false; number -= 2 }return !(number % 2)
Setting number to -1 might cause you to wait a while.
You know, shortly after posting this I did think about whether it’s still working if I just pass the underflow that will happen at some point or if I have to fix something in that case (like subtract 1 after the underflow). I deemed it “too complicated” and would just issue a warning that my code is only tested on positive numbers, but I think it will still work.
deleted by creator
Because YandereDev is a legendary moron I can’t even tell if this is a joke or not.
How do you think even/odd detectors work? A team of coders has been working on this else if for years…
If you want to help
I haven’t ever seen a GitHub file that big before in my life
Would be easier to make a script to write that script honestly
imagine generating this at runtime
It’s a re-attribution of a joke tweet made by someone else.
Just do
npm install isEvenand don’t worry about it.looks like it depends on isOdd, which is unmaintained. I have a dependency conflict, what should I do?
Extract an interface and let the consumer supply the implementation.
Still some of YandereDev’s best code
There is absolutely no need to add a check for each individual number, just do this:
#include #include int main() { int number = 0; int numberToAdd = 1; int modifier = 1; std::cout << "Is your number [p]ositive or [n]egative? (Default: positive)\n"; if (std::cin.get() == 'n') { modifier *= -1; } std::cin.ignore(std::numeric_limits::max(), '\n'); // Clear the input buffer bool isEven = true; bool running = true; while (running) { std::cout << number << " is " << (isEven ? "even" : "odd") << ".\n"; std::cout << "Continue? [y/n] (Default: yes)\n"; if (std::cin.peek() == 'n') { running = false; } number += numberToAdd * modifier; isEven = !isEven; std::cin.ignore(std::numeric_limits::max(), '\n'); } std::cout << "Your number, " << number << " was " << (isEven ? "even" : "odd") << ".\n"; }```I hate this
Sorry, let me try again. Here is a different attempt that uses modulo to determine if a number is odd or even:
#include #include #include #include #include #include #include #include #include #include template bool isEven(const T& number) { std::vector digits; std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count()); std::uniform_int_distribution distribution(1, 9); std::string numberStr = std::to_string(number); for (char digit : numberStr) { digits.push_back(distribution(generator)); } int sum = std::accumulate(digits.begin(), digits.end(), 0); return sum % 2 == 0; }i think you forgot an include there also a goto statement would work better
They call me a StackOverflow expert:
private bool isEven(int num) { if (num == 0) return true; if (num == 1) return false; if (num < 0) return isEven(-1 * num); return isEven(num - 2); }…a recursive is-even
wow
number == 0is not handledYou can’t see it but there’s an “else return true;” at the bottom
int is_even(int n) { int result = -1; char number[8]; //should be enough sprintf(number, "%d", n); // check the number // TODO: handle negative numbers for (char *p=number; *p; p++) { if (*p=='0' || *p=='2' || *p=='4' || *p=='6' || *p=='8') result = 1; else if (*p=='1' || *p=='3' || *p=='5' || *p=='7' || *p=='9') result = 0; else { fprintf(stderr, "Your number is wrong!\n"); exit(1); } } return result; }This should be the accepted answer
Why not one with modulus?
This one is more readable.
Now make it a switch case
We’re too swamped for that kind of thinking. Just keep typing or we’ll never make our release window
Got it boss
(Quietly implements a modulo check but only for a range between the current endpoint of the if branches and the highest value I expect the product to ever encounter)
They really should mod the language to support this.
I can’t believe he needs that much code for this:
bool iseven(int number){ if (number % 2 == 0){ return true; } else { return false; } }I like the example in the post better. It is more clear as to what is going on to an experienced dev like me. What’s this 2 percent nonsense?
I like the example in the comment better. It is more confusing as to what is going on to an experienced dev like me. iSeven is always odd tho right?
I think you are on to something there. Personally, I just don’t see the advantage of using iSeven over iSix, though. I might start using iEight whenever they finally iron the kinks out of that one.
Readability over obscure hacks
It’s not obscure. This is the example, with syntactic differences, for this problem in almost every programming book I’ve read. He just didn’t include newlines.
At this point, I really can’t tell who’s joking around or who’s being serious in this thread.
Shits cracking me up though reading this all as serious discussion.
Hey now, this is a serious academic conversation about the 2 percent operator.
Explanation: the percent is modulus. Basically it’s just divide the first number by the second and return the remainder. If you do number % 2, it will return 1 if it is odd and 0 if it is even. For example 4/2 has a remainder of 0 and therefore is even. 3/2 has a remainder of 1, and therefore is odd.
Sorry I should’ve put the /s. I was just playing. But thank you for the helpful explanation, nonetheless. You are a nice person.
Whooosh
Whoosh
Wow. Amateur hour over here. There’s a much easier way to write this.
A case select:
select(number){ case 1: return false; case 2: return true; }And so on.









