Would this be a case of modulo saving the day?
Like: If Number modulo 2 = 0, true
This has to be taken out of context
Post funny things about programming here! (Or just rant about your favourite programming language.)
Would this be a case of modulo saving the day?
Like: If Number modulo 2 = 0, true
This has to be taken out of context
Thanks to goodness, finally. A (giggle & snort) solid algorithm. There ya’s go set yer clocks & go get a haircut.
Ffs just use a switch. It's much faster!
This joke was not written by the dude pictured. The author wrote a book of funny code jokes.
this is like the making chess one
This is what Test Driven Development looks like
TDD has cycles of red, green, refactor. This has neither been refactored nor tested. You can tell by the duplication and the fact that it can't pass all test cases.
If this looks like TDD to you, I'm sorry that is your experience. Good results with TDD are not guaranteed, you still have to be a strong developer and think through the solution.
bool isEven(int value) {
return (int)(((double)value / 2.0) % 1.0) * 100) != 50;
}
To be fair, the question is "Write a function that simultaneously determines if the number is even and works as a timer"
assert IsEven(-2);
I hope that the language's int
s are at most 32 bits. For 8 bits it could even be written by hand & the source code for a 32 bit version would only take up avg_line_len * 4GiB
space for the source code of the function. But it might take a bit of time to compile a version that supports the full range of 64 or 128 bit ints.
My mate, Paul, says all numbers after 700 repeat so we can stop there.
We just give them different names so you think they're going up.
that's some good code right there
You could use a loop to subtract 2 from the number until it equals one or zero
Or literally just look at its binary representation. If the least significant digit is a "1", it's odd, if "0", it's even. Or you can divide by 2 and check for a remainder.
Your method is just spending time grinding away CPU cycles for no reason.
What should all the non binary people do then you bigot
Wasn’t the fun the CPU cycles we wasted along the way?
private?