this post was submitted on 31 Jul 2025
479 points (97.6% liked)

Programmer Humor

26603 readers
2487 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 50 points 1 month ago (12 children)

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

[–] Khanzarate@lemmy.world 77 points 1 month ago* (last edited 1 month ago) (10 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 33 points 1 month ago (8 children)

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

[–] Szyler@lemmy.world 1 points 1 month ago* (last edited 1 month 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.

load more comments (7 replies)
load more comments (8 replies)
load more comments (9 replies)