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.
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.
Yeah, but what if the counter gets decremented before the wish gets granted, huh?
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.
Didn’t even get the joke here because this is how I always imagined genie wishes working.
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*/}