461
WishUnderflow (lemmy.world)
you are viewing a single comment's thread
view the rest of the comments
[-] expatriado@lemmy.world 49 points 3 days ago

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

[-] Khanzarate@lemmy.world 71 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?

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

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

load more comments (5 replies)
load more comments (6 replies)
load more comments (7 replies)
this post was submitted on 31 Jul 2025
461 points (97.5% liked)

Programmer Humor

25426 readers
1053 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