81 points

return true

is correct around half of the time

permalink
report
reply
41 points
assert IsEven(2) == True
assert IsEven(4) == True
assert IsEven(6) == True

All checks pass. LGTM

permalink
report
parent
reply
18 points
return Math.random() > 0.5

would also be correct about half the time

permalink
report
parent
reply
1 point

Wouldn’t that only be correct about 25% of the time?

permalink
report
parent
reply
0 points

for even, 50% chance of correctness, same for odd.

permalink
report
parent
reply
52 points
*
import re

def is_even(i: int) -> bool:
    return re.match(r"-?\d*[02468]$", str(i)) is not None
permalink
report
reply
23 points

Cursed

permalink
report
parent
reply
5 points

i was gonna suggest the classic

re.match(r"^(..)\1*$", "0" * abs(i)) is not None
permalink
report
parent
reply
45 points

Just divide the number into its prime factors and then check if one of them is 2.

permalink
report
reply
20 points
*

or divide the number by two and if the remainder is greater than

-(4^34)

but less than

70 - (((23*3*4)/2)/2)

then

true
permalink
report
parent
reply
8 points

What if the remainder is greater than the first, but not less than the latter?

Like, for example, 1?

permalink
report
parent
reply
3 points

Then you should return false, unless the remainder is also greater than or equal to the twenty second root of 4194304. Note, that I’ve only checked up to 4194304 to make sure this works, so if you need bigger numbers, you’ll have to validate on your own.

permalink
report
parent
reply
14 points

I remember coding actionscript in Flash and using modulo (%) to determine if a number was even or odd. It returns the remainder of the number divided by 2 and if it equals anything other than 0 then the number is odd.

permalink
report
parent
reply
25 points

Yeah. The joke is that this is the obvious solution always used in practise, but the programmer is that bad that they don’t know it and use some ridiculous alternative solutions instead.

permalink
report
parent
reply
19 points

I believe that’s the proper way to do it.

permalink
report
parent
reply
1 point
Deleted by creator
permalink
report
parent
reply
38 points

Zero people in this post get the YanDev reference

permalink
report
reply
8 points

so nobody actually really got the joke. very sad Moment.

permalink
report
parent
reply
9 points

It’s really just us… I’ve seen the basic programming joke a bunch of times, but people really aren’t understanding the YanDev/font embellishment. Sad indeed.

permalink
report
parent
reply
3 points

I do :D

permalink
report
parent
reply
27 points

so did someone draw this by hand or was it a filter

permalink
report
reply
10 points

tbh it looks like an AI broke this down slightly & reconstructed it

permalink
report
parent
reply