this post was submitted on 15 Jul 2025
439 points (94.7% liked)

Programmer Humor

38823 readers
361 users here now

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

Rules:

founded 6 years ago
MODERATORS
(page 2) 50 comments
sorted by: hot top controversial new old
[–] Kuma@lemmy.world 6 points 3 months ago

I am more amazed that he didn't stop at 10 and think "damn this is tiresome isn't there a one liner i could do?". I want to know how far he went. His stubbornness is amazing but also scary. I haven't seen this kind of code since back in school lol lol lol

[–] thann@lemmy.dbzer0.com 6 points 3 months ago (6 children)

You could use a loop to subtract 2 from the number until it equals one or zero

load more comments (6 replies)
[–] Treczoks@lemmy.world 6 points 3 months ago

Good if you are rated by an AI that pays for LOCs.

[–] Midnitte@beehaw.org 5 points 3 months ago

When did Thor become the dev for Yandere Simulator?

[–] FireIced@lemmy.super.ynh.fr 5 points 3 months ago

that's some good code right there

[–] ICastFist@programming.dev 5 points 3 months ago (1 children)

Oh shit, gotta check the negative numbers as well!

load more comments (1 replies)
[–] last_philosopher@lemmy.world 4 points 3 months ago (1 children)

To be fair, the question is "Write a function that simultaneously determines if the number is even and works as a timer"

[–] JackbyDev@programming.dev 4 points 3 months ago

sleepSort meets sleepIsEven

[–] ferric_carcinization@lemmy.ml 4 points 3 months ago (1 children)

I hope that the language's ints 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.

[–] Patches@ttrpg.network 6 points 3 months ago* (last edited 3 months ago)

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.

[–] Randomgal@lemmy.ca 3 points 3 months ago

Yeah but did you know he worked for Blizzard tho

[–] dsilverz@calckey.world 2 points 3 months ago (1 children)

@sirico@feddit.uk

private bool isEven(int number){
    	bool result = true;
    	while (number > 0){
    		number = number - 1;
    		if (result == true)
    			result = false;
    		else
    			result = true;
    	}
    	return result;
    }

(P.S.: Only works for positive numbers)

[–] jaupsinluggies@feddit.uk 3 points 3 months ago

This works for both positive and negative numbers:

private static bool isEven(int number)
{
	bool result = true;

	while (number < 0)
	{
		number = number - 1;
		if (result == true)
			result = false;
		else
			result = true;
	}
	while (number > 0)
	{
		number = number - 1;
		if (result == true)
			result = false;
		else
			result = true;
	}
	return result;
}

Output:

isEven(4) = True
isEven(5) = False
isEven(-4) = True
isEven(-5) = False
load more comments
view more: ‹ prev next ›