453
WishUnderflow (lemmy.world)
you are viewing a single comment's thread
view the rest of the comments
[-] Khanzarate@lemmy.world 69 points 3 days ago* (last edited 3 days ago)

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 3 days ago

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

[-] Szyler@lemmy.world 1 points 6 hours ago* (last edited 6 hours ago)

You have 3 wishes.

First wish: I wish my last wish would count as me consuming two wishes. Second wish: I wish to have 0 wishes remaining.

First wish puts you down one wish, so ending at 2. Second wish removes one wish, so at one, then wish happens putting you at 0,

then because this second wish now becomes your last, as you have 0 remaining, the first wish then takes effect and consumes another wish, putting you to - 1 and overflowing.

[-] Mesa@programming.dev 1 points 1 day ago

Didn't even get the joke here because this is how I always imagined genie wishes working.

[-] SeductiveTortoise@piefed.social 11 points 3 days ago
[-] expatriado@lemmy.world 4 points 3 days ago

i think both solutions are valid, since sometimes you pay before and sometimes after receiving the service

[-] Khanzarate@lemmy.world 4 points 3 days ago

Genie in the OP image would've said "OK you now have 0 wishes".

Since he said 255, my interpretation is a valid solution.

Of course, if we're talking hypothetical wish gaining prevention methods, I'd just have a check before,

previous_wishes = wishes;

{Do all the wish things. wishes ends up with a 255 because of our shenanigans}

If(wishes>=previous_wishes) wishes = previous_wishes-1;

;If the current number of wishes isnt less than the old number of wishes, set it to the old number and subtract 1

If(wishes==0) {/*TODO: write function to end wish giving sequence*/}

[-] mohab@piefed.social 1 points 3 days ago

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.

[-] wheezy@lemmy.ml 4 points 3 days ago* (last edited 3 days ago)

Well, not entirely. There are cases for which a person utters the wish and it is not counted. "I wish for a million wishes!"

The standard is for the genie to explain the exceptions but not count that as a wish.

Now, it could decrement the count after this check. But just decrementing the count before verification would be sloppy.

But, then again, basic verification would also include checking that wishes_remaining <= MAX_WISHES.

Which, I think is a pretty standard check for genie's. Given that that constant has remained at 3 since their beta days and exceptions are thrown for violations of this rule.

[-] Khanzarate@lemmy.world 1 points 3 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.

[-] QuazarOmega@lemy.lol 9 points 3 days ago

This is actually genius

this post was submitted on 31 Jul 2025
453 points (100.0% liked)

Programmer Humor

25436 readers
885 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