this post was submitted on 31 Jul 2025
430 points (97.4% liked)

Programmer Humor

25425 readers
986 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] expatriado@lemmy.world 46 points 2 days ago (10 children)

wouldn't 0 be 0 and -1 underflow to 255 if 8 bit container? intentional error to enhance engagement?

[–] Khanzarate@lemmy.world 68 points 2 days ago* (last edited 2 days ago) (8 children)

You're correct but you have an off by 1 error.

First, the genie grants the wish.

NumWishes=0;

Then, having completed the wish, the genie deducts that wish from the remaining wishes.

NumWishes--;

And to complete the thought,

Lastly, the genie checks if the lampholder is out of wishes

If(NumWishes==0) {...}

(255==0) evaluates to False, so we fall past that check.

[–] Dumhuvud@programming.dev 31 points 2 days ago (6 children)

Yeah, but what if the counter gets decremented before the wish gets granted, huh?

[–] mohab@piefed.social 0 points 2 days ago (1 children)

I would assume this to be the case since you cannot un-utter a wish—once you say it, it is counted as a wish before it's fulfilled.

If the counter is decremented only after the wish is fulfilled, then this means you can go back on wishes because they don't count until they're fulfilled, which goes against the lore.

[–] Khanzarate@lemmy.world 1 points 2 days ago

Nah theres just no process for undoing your submission.

It doesn't matter when it's decremented if you can't interrupt the process, anyway.

In a code sense we pause for input, feed it to the wishmaker function, and pause until the thread returns, then decrement.

We could decrement first, also, but neither violates the rules.

load more comments (4 replies)
load more comments (5 replies)
load more comments (6 replies)