this post was submitted on 22 Feb 2024
111 points (95.9% liked)

Programmer Humor

32481 readers
239 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 8 months ago (17 children)

Is this the same person who coded the odd/even function?

[–] [email protected] 3 points 8 months ago* (last edited 8 months ago) (16 children)

I have a better odd/even function:

bool isEven( long long x ) {

if ( x < 0 ) x = -x;

if ( x == 1 )

return false;

if ( x == 2 )

return true;

return isEven( x - 2 );

}

This will work for both negative numbers and arbitrarily large integers. I've tested it up to 26 but I'm pretty sure it will work up to infinity.

Though serious question: Why are these forums coded in such a way that they ignore single newlines? How hard is it to replace a newline with a br tag?

[–] [email protected] 5 points 8 months ago (1 children)

Can you put this in a npm package so I can use it in my project, please?

[–] [email protected] 2 points 8 months ago

Just copy paste it into each source file, I give you permission to reuse the code.

load more comments (14 replies)
load more comments (14 replies)