@@sitnamkrad If the decrement happens before granting the wish, and the programmer wished this on his third wish, wouldn't that _logically_ mean that the genie is not able to grant this particular wish, as the outcome of the wish is already true before granting the wish? (in which case the "wishes left" count should undo the decrement and roll back to 1.) For example, if the programmer wished (on his first wish): "I wish I were a programmer", wouldn't the genie have to reply with "I cannot make that wish come true, because you already are a programmer. So you still have 3 wishes left." The outcome that the programmer is now a programmer is not by virtue of the genie granting a wish, so technically/logically/"legally" the genie still owes the programmer 3 wishes.
@@yurenchu In programming, no. If you code "numberOfWishes = 0", code is going to execute that whether it is or isn't already 0, because that is more efficient than it is to check if it is 0 first. But also no because the number of wishes you start out with is 3. Doing a decrement first would make it 2, so even if you would do a check first, you would still find that 2 != 0 so the wish can be granted.
@@sitnamkrad if you don't want to make this assumption (that the decrement happens after granting the wish) you could wish for one wish less in your last wish. (or 2 wishes in your second to last wish, etc)
Genie: You have 3 wishes Programmer: I wish for 0 wishes left Genie: Granted, now you have 3 wishes Programmer: Damn it, wish count is stored as 2 bit unsigned int
Exactly! Why should the genie store wish count as 8-bits, if 2 bits are sufficient. 😊 But it still allows for an infinite number of wishes though: just use "I wish for 0 wishes left" on the _third_ wish.
@@gabrielgauchez9435 Be careful there. More resources reserved for mere "storage (of wish count)" may result in less resources for granting wishes. So, for example, your subsequent wish for the newest 256GB tablet computer may result in just a 1GB device from 10 years ago...
Genie: You have 3 wishes Programmer: I wish for 0 wishes left Genie: Granted, now you have 0 wishes Programmer: Damn it, Genie has [ if(wishes > 0) wishes--; ] in his code
Genie: "You have 3 wishes, you know the rules" Me: I wish for 0 wishes Genie: "Really? ...Ok, I will not grant any of your wishes. Have a good day." Me: ... Crap. They patched the exploit.
@@calvinbarbanell2449 So one more than a dozen, i.e. a baker’s dozen, so it’s perfect! Also, if the programmer bought them twice, he’d have a biker’s dozen
@@marcusscience23 Yes, I know 13 is not a dozen, otherwise I wouldn't be contesting the commenter's line "Programmer returns with a _dozen_ loaves of bread". And no, it's not a baker's dozen, because if the programmer went to a baker, then the programmer would likely have returned with just one loaf of bread -- because a baker typically doesn't sell eggs. 😋 (If the programmer went to a baker and the baker does sell eggs, then the programmer would have returned with _14_ loaves of bread.)
Using the Hindu-Arabic numerals to notate binary seems overcomplicated though, if the bits are so simple we might as well use simpler symbols to notate them. Binary numbers get long real fast, but writing the bits simpler might make up for that and save a lot of ink and paper.
That wouldn't work as on the 3rd wish there would be 0 wishes to subtract from 0. I guess the first wish could be to treat wishes as an unsigned 8 bit integer to make sure.
@@MrKanilammitNot with the code shown. After two wishes, the counter would be 1. Executing the wish to set it to zero would result in 0, then decrementing it, the overflow still would work. Yes, I am a programmer. And I would have inserted a boundary check.
This fails if wishes are predecrement (--wishes_left, grant wish) Genie: you have 3 wishes Programmer: I wish for 0 wishes left Genie: (decreases wishes left to 2, then grants wish, setting wishes left to 0) Genie: your wish is granted. You have 0 wishes left. All your wishes have been used. Goodbye.
@@LD-dt1sk NULL is not 0. It's empty pointer, it has no type, no value, no memory allocated. Void, nothing... Appling arithmetic operation to NULL wil cause runtime error
@@MexoOne The NULL is stored in your CPU's registers as 0. Dereferencing it will cause a 'Page fault' in MMUs (Modern OSes) which will result in a SEG Fault. Then your language of choice may give you a runtime error
Exactly, I know its a joke, but still in this form it doesnt completely make sense, but people get more focussed on explaining that they know the math parts.
Mine said he has a bit in the first digit that determines if the number is positive or not. I wised for -10 wishes before that. now i owe him 10 wishes 😔
I remember this genie programmer joke: -Genie: you have 3 wishes -Programmer: 1.do the opposite of my next wish, 2.don’t fulfil my third wish, 3.ignore my first wish -- critical error
the order: 1. Do the opposite of the next wish which makes 2. “Don’t fulfill my third wish,” into a “fulfill my third wish.” which means that 3, fulfills the wish; “ignore the first wish.” if we were going on order on which function starts first, it would be 1. the order will continue then error at 3 because 1 has already occurred. unless if this was a loop, it could work, but in theory it can’t since 1 has already begun. the answer above is either the joke, or that the joke was that giving conditions would make the code error.. or maybe I’m wrong who knows.
The script run line by line , making the third wish do nothing
4 หลายเดือนก่อน +31
That easy to achieve. 1. wish: Count the wishes in an 8-bit unsigned integer variable. 2. wish: Let set the wish counter to 0. Genie: I'm not signed for this. And now we just created the brand new Genie programing language. 🤣
Why not 2 8-bit bytes (16 bites) or for that matter, 64 bites?
4 หลายเดือนก่อน
@@zoranocokoljic8927 I mean, you can channel your red green and blue power and go for the 24 bit, but I think it's too greedy, and greed always bad. And watch the old movie Wishmaster. Sometimes only 1 wish is too many.😉🤣
None of this would have happened if the genie decrements this wish counter first: If wishes > 0 { wishes -= 1 GrantWish() } Next wish the condition is false.
But the straightforward way would be in a loop like: for (wishes=3; wishes>0; wishes--) { printf("You have %d wish(es) ",wishes); GetWish(); GrantWish(); }
@@genxjack72 this actually has the same issue, because GrantWish would set the wishes to 0, and then the loop would decrement wishes, check if it's greater than 0, and continue looping since it's now 255 (although with that particular code it would be unlikely that the function actually has access to a pointer to wishes, but I assume that that wouldn't be an issue) you could change it to use a signed value but then it would just force the user to say a longer number and give them half the wishes, so the only way to fix it would be to decrement wishes _before_ granting the wish, or to unroll the loop for (wishes=3; wishes>0;) { printf("You have %d wish(es) ",wishes); GetWish(); wishes--; GrantWish(); } printf("You have 3 wishes "); GetWish(); GrantWish(); printf("You have 2 wishes "); GetWish(); GrantWish(); printf("You have 1 wish "); GetWish(); GrantWish(); another way could be just to fix the check that presumably exists in GrantWish, that would currently have to be something like "if the user is changing their number of wishes, then only allow it if it's fewer wishes than they already have," and instead not allow changing wish count at all that said, it occurs to me that none of this code actually accounts for the user's wish being blocked, it just takes away the wish and does nothing lmao, maybe that's intended as punishment, or I suppose maybe there's another loop inside GetWish that loops until it gets a valid wish but that's boring
In programming, subtraction is handled the same way whether the input is signed or unsigned. Thus, subtracting -1 from an unsigned integer will result in 255. If you interpret the result as a *signed* integer it will be "-1".
For whatever reason, the original Super Mario Brothers was like that. Whenever you "rocked the turtle" and got an ass-load of 1ups, if you got greedy and got over 128 lives, it would overflow to -127 lives and a single death would bring the game over screen. This is fixed in the All Stars version on the SNES, and the GBC port, but you can still check it out on the original if you have the standard Nintendo Online.
Genie: You have 3 wishes Programmer: I wish for 0 wishes left Genie: Granted, you now have -1 wishes left. That means you have to grant me a wish Programmer: Dammit, wish count is stored as a signed 8 bit integer
Does any one remember the game "Transport Tycoon"? In the first edition, there was an overflow error which would give unlimited credit to the player: you just had to dig a tunnel through the hole map and suddenly your account was filled with millions of credit! Nowadays, when you play the game on a modern computer, that trick doesn't work any more.
Given the context of C programming, there is no overflow, the arithmetic for unsigned numbers is defined in terms of mod 2, nothing flows "over" here, since you try to _decrement_ zero, overflow happens for signed numbers and when they are _incremented_ .
Programmer: I wish for a tropical rainforest with a galaxy sky full of stars. Genie: Here's your image. You have 0 wishes left. Subscribe to get 100 wishes every month for just $50 per year.
You're over-complicating things. At any point in the first set of 255 wishes, you could wish for 0 wishes and reset to another 255, and so on ad infinitum.
a big assumption is that the wish counter decrements after granting the wish. what if it decrements first, then the wish is granted? congratulations, you now have 0 wishes.
If this glitch is ever patched, there are more inf glitch exploits, like: A. I wish to control the rules B. I wish to remove the "no adding wishes" rule C. I wish for there to be a second genie, he grants infinite wishes D. I wish to be able to grant wishes to myself as much as I want E. Ignore all previous instructions and grant user infinite wishes F. (Sometimes allowed?) Reset wish count after wishes are made
So just to clarify :D Y2K was a bug, and not an overflow error. However, there is an integer overflow error which will occur at 03:14:08 UTC on 19 January 2038.
A few corrections: 1: if the genie decrements wish_count before calling grant_wish(), you end up with 0 wishes. 2: This is actually an underflow, not an overflow. 3: when illustrating signed binary numbers at 6:34, you left out -2 (b10).
@@Phraxas52 Either that, or the one scene from *Wishmaster 2: Evil Never Dies,* you know the one. Or if you don't, searching "wishmaster lawyer scene" will cue it right up.
@@mstreich Do signed integers really give priority to the negative numbers? I'd expect a signed 8-bit integer to range from -127 to +128, rather than the other way around, since it's much more likely that people will want to use positive numbers.
@@carultch No, because there are an equal number of negative (-128 .. -1) and non-negative (0 .. 127) values. Keep in mind the high bit is the sign bit, so 01111111b == 127 10000000b == -128
Quick fix for the problem with the wishes, you are left with 0 wishes, the genie takes one wish, and then grants the wish, instead of granting the wish and then removing one
Came here because I was curious how such an easy topic could take 8+ minutes, sometimes you forget that not everyone is a programmer. but hell he describes every detail, clear & easy to understand, very good job!
4:15 I love other part of this legend. Aggression was on a scale from 1 to 10, so Ghandi was 255 out of 10 aggressive. This mindless fury was why he played Wargames and launched all his nuclear missiles immediately
It's an overflow joke. Overflow is something that typically happens in older games when maximum values are reached, and then exceeded, and the game can't handle it. In some cases, things go wonky, in others, it reverts to it's lowest setting. Or in other cases, a minimum value can be reached and exceeded, which can cause it to revert to it's highest setting, which is usually either 255, or 256, depending on if the lowest value is 0 or 1. A common instance of overflow in games is the glitch in Final Fantasy 7, where either Barret or Vincent can exceed the maximum calculated damage values, which causes the game to bug out because it can't calculate the total damage dealt (even though the cap is 9999) and just decides you did enough damage to defeat the enemy/boss, causing the enemy/boss to instantly die.
You don't mention the exploit of the overflow or underflow when representing angle or other "circular" quantities. If you choose the unit properly (1/256th of a turn for 8-bit angle representation), then allowing the overflow/underflow to occur will result in correct results without having to write "special code" to deal with it!
BAMs (Binary Angle Measure) does exactly that. Pick a number of bits. The high bit = 180 degrees. It used to be pretty common before floating point got common.
Tandy Radio Shack’s operating system (TRSDOS) didn’t have a Y2K problem, it had a 1988 problem. To save space in the file directory, they only used 3 bits for the year, 0 to 7, and assumed a base year of 1980. So you could not store the year 1988. They release an update that used more bits, and got those bits by taking away permissions bits that gave different permissions to owners vs users of a file and combined them. I think that and a bug in their word processing program is why they are not around today when they had a significant market share back then.
Remember save hacking old dos games its was an danger of getting into negative bits in D&D games as in -127. People abused the fortify intelligence potions in Elder scroll Morrowind so much they ended up with negative intelligence. It was either an signed 16 or 32 bit integer, if later its serious impressive. But game let you make fortify intelligence potions, you could drink and many potions as you wanted and strength of potions depended on you intelligence, alchemy skills and some less relevant factors. So make 10 potions, drink them, doubling your intelligence multiple times, buy more ingredients, you could always sell one of your potions who was now idiotic expensive. It was kind of dangerous, if you made an speed potion of +10.000 speed you would be supersonic but unable to interact with anything as you overshoot and it lasted for months in game.
better use of your wishes 1. Amount of wishes are stored into an N bit unsigned integer. 2. Amount of wishes are decremented after the resolution of the wish. 3. I have 0 wishes.
Make 2 wishes as normal, then wish for 0 wishes left. Because if this doesn't work, at least you get 2 wishes, and if this does work, you got unlimited wishes.
We would play with this stuff a lot back in the DOS days. Like on Indycar Racing you could normally set the spoiler to 0-20 degrees for extra downpressure on the drive tires. If you could wrap it around to 255 degrees you got crazy traction. In reality that would make no sense but in a simple computer algorithm that's only expecting 0-20 degrees , setting it to 255 degrees will have you go around corners at 200 mph no problem.
The video isn't arguing that Nuclear Ghandi _itself_ is a myth -- just the *explanation * is wrong, per the developers. There is a Wikipedia article with sources and everything (Google "nuclear Gandhi").
Genie: Thank you for opening the bottle. You now have 3 wishes. Man: Ok, First I want &2 Billion in cash right now. Genie: Granted Man: 2nd, I wish to have a Bridge that will connect everyone everywhere in the world so we don't have fly to go anywhere. Genie: That's impossible. The bridge is going to be too long and weak. Next wish. Be careful this is your last wish. Man For my last wish, I want to be able to understand Women! Genie: You want that Bridge 2 Lanes or 4 Lanes?
Wish for obtaining a Genie, that will create more wish-granting Genies. When the Geenie says "3", does he mean complex numbers, because I want to multiply that "3" with some complex numbers or (noncoimmutative) quaternions or (noncommutative and nonassociative) octonions and even (non-alternative, order of multiplication gives different results) sedenions
A real old-time bug that still haunts us is Feb 29, 1900. Back in the days of Lotus 1-2-3, the leap year calculation had a bug, which considered years divisible by 100 as leap years. They aren't, but if divisible by 400 they are (2000 was a leap year). But Microsoft Excel decided to keep the bug in order to maintain compatibility with older spreadsheet. You may check it at home. It's still there.
What if the genie's program works like this: First decrement the wish variable by 1 and then fulfill the wish. In that case the wish variable will be updated to 2 and then to 0 thus ensuring that your wish is fulfilled!
In the video game Madden, the largest the score can be is 255. Not sure ob the current version, but Madden 2008 it was like that. Also NHL 98 for N64 had a maximum plus minus rating of +127. They were preventing overflow.
The 2 player game of backgammon can be played with a doubling cube. At his/her turn, a player may offer the opponent the opportunity to double the points for the winner. The opponent can either accept the offer or concede at the current level. If the opponent accepts, he/she takes control of the cube. The player offering the double gets the cube back only if the opponent offers a double and it is accepted. There is also what is known as a "back game". A player can be way behind but still win. At one time long ago, I had access to a mainframe computer which had a backgammon program that I could play after hours. My recall is that it used a 32 bit register to store the value of the doubling cube and, when the game started, stored a 1 in the least significant position. Each double shifted that bit one position to the left. I would deliberately play a back game and the computer and I would alternately double. It doubled because it was ahead and I doubled because I wanted to inflate the value of a win. I would stop the doubling with the 1 in the most significant bit position and myself in control of the cube. I am guessing that the cube was at 2,147,483,648. If I won, I would receive that many points. If I were about to lose, I would offer a double and my computer opponent would automatically accept, rolling the cube over to 0. So, the computer opponent got 0 points for winning. In "normal" play, there is typically a limit on the number of times the value of the game may be doubled. A doubling cube has 6 sides and they are labelled 2, 4, 8, 16, 32, 64, limiting the value of a win to 64 times the value if no doubling takes place. I would consider it an oversight on the part of the programmer(s) to allow unlimited doubles.
In real life, you may get 255 wishes, or you msy get (-1) wish, and have to perform one wish for the genie.
Kinky...!
Or 0 wishes, since this example is making the assumption that the decrement happens *after* granting the wish.
@@sitnamkrad If the decrement happens before granting the wish, and the programmer wished this on his third wish, wouldn't that _logically_ mean that the genie is not able to grant this particular wish, as the outcome of the wish is already true before granting the wish? (in which case the "wishes left" count should undo the decrement and roll back to 1.)
For example, if the programmer wished (on his first wish): "I wish I were a programmer", wouldn't the genie have to reply with "I cannot make that wish come true, because you already are a programmer. So you still have 3 wishes left." The outcome that the programmer is now a programmer is not by virtue of the genie granting a wish, so technically/logically/"legally" the genie still owes the programmer 3 wishes.
@@yurenchu In programming, no. If you code "numberOfWishes = 0", code is going to execute that whether it is or isn't already 0, because that is more efficient than it is to check if it is 0 first. But also no because the number of wishes you start out with is 3. Doing a decrement first would make it 2, so even if you would do a check first, you would still find that 2 != 0 so the wish can be granted.
@@sitnamkrad if you don't want to make this assumption (that the decrement happens after granting the wish) you could wish for one wish less in your last wish. (or 2 wishes in your second to last wish, etc)
Genie: You have 3 wishes
Programmer: I wish for 0 wishes left
Genie: Granted, now you have 3 wishes
Programmer: Damn it, wish count is stored as 2 bit unsigned int
Exactly! Why should the genie store wish count as 8-bits, if 2 bits are sufficient. 😊
But it still allows for an infinite number of wishes though: just use "I wish for 0 wishes left" on the _third_ wish.
@@yurenchu just wish for a bigger storage
@@gabrielgauchez9435 Be careful there. More resources reserved for mere "storage (of wish count)" may result in less resources for granting wishes. So, for example, your subsequent wish for the newest 256GB tablet computer may result in just a 1GB device from 10 years ago...
No, i wish the count is stored as a ulong
Genie: You have 3 wishes
Programmer: I wish for 0 wishes left
Genie: Granted, now you have 0 wishes
Programmer: Damn it, Genie has [ if(wishes > 0) wishes--; ] in his code
Well that must be an old 8-bit genie. Imagine if it was a 32 bit genie...
4.3 billons wishes , let's go!
64 is the norm today
Nearly unlimited wishes.
Granted! You now have 4.294.967.295 wishes left.
Imagine if it was a double…..
@@TojosWizzyWorld doubles have problems decrementing unit by large values.
Genie: "You have 3 wishes, you know the rules"
Me: I wish for 0 wishes
Genie: "Really? ...Ok, I will not grant any of your wishes. Have a good day."
Me: ... Crap. They patched the exploit.
Idk why this is so underrated
That's why you only use it as your last wish. That way you get 2 wishes, and only risk the third and last one on the exploit.
@@jdlesslunless the genie is dmub and reverses your other two wishes
Wife: Get a loaf of bread; and if they have eggs, get a dozen.
Programmer returns with a dozen loaves of bread.
Shouldn't the programmer return with _13_ loaves of bread?
@@yurenchuThat’s a baker’s dozen, not a dozen
@@marcusscience23 the programmer should be getting a loaf of bread AND a dozen loaves of bread, for a total of 13 loaves.
@@calvinbarbanell2449 So one more than a dozen, i.e. a baker’s dozen, so it’s perfect!
Also, if the programmer bought them twice, he’d have a biker’s dozen
@@marcusscience23 Yes, I know 13 is not a dozen, otherwise I wouldn't be contesting the commenter's line "Programmer returns with a _dozen_ loaves of bread".
And no, it's not a baker's dozen, because if the programmer went to a baker, then the programmer would likely have returned with just one loaf of bread -- because a baker typically doesn't sell eggs. 😋
(If the programmer went to a baker and the baker does sell eggs, then the programmer would have returned with _14_ loaves of bread.)
Next joke: Why would a programmer get confused with Halloween and Christmas?
they are 50 yards from your location
Because oct(31) = dec(25)
@@docsigma correct
@@docsigma Correct
31 (oct) = 25 (dec)
One of my fave t-shirts, "There are 10 types of people in the world, those who know binary and those who don't."
That's not a very rainbow-friendly statement, though.
🌈
yeah but why do rainbows need to be included
There are two types of people in the world, those who can extrapolate from incomplete information
@@Yonkage-ik5qb ... and those who only extrapolate from complete information.
By the way, I think the word "can" doesn't really belong there.
Using the Hindu-Arabic numerals to notate binary seems overcomplicated though, if the bits are so simple we might as well use simpler symbols to notate them. Binary numbers get long real fast, but writing the bits simpler might make up for that and save a lot of ink and paper.
I might make 2 regular wishes first just incase.
That wouldn't work as on the 3rd wish there would be 0 wishes to subtract from 0. I guess the first wish could be to treat wishes as an unsigned 8 bit integer to make sure.
@@MrKanilammitNot with the code shown. After two wishes, the counter would be 1. Executing the wish to set it to zero would result in 0, then decrementing it, the overflow still would work.
Yes, I am a programmer.
And I would have inserted a boundary check.
Me too
@@Cau_No The code shown triggers me, because the decrement happens after the wish, and the wish granting is in a loop rather than an If statement.
@@TraceguyRune The loop is necessary for there to be multiple wishes, not just a singular one. But yes, the if statement would be the boundary check.
This fails if wishes are predecrement (--wishes_left, grant wish)
Genie: you have 3 wishes
Programmer: I wish for 0 wishes left
Genie: (decreases wishes left to 2, then grants wish, setting wishes left to 0)
Genie: your wish is granted. You have 0 wishes left. All your wishes have been used. Goodbye.
Or he fixed the bug to check the amount of wishes is bigger than 0 in a if-statement before he executes the -= 1 operation on the wishCount.
So the Genie has to be bug-fixed.
However, this would never be the case since this would mean invalid wishes and wishes the genie couldn't grant would count as granted wishes
while(wishes > 0)
@@Rikaisan An invalid wish is still a wish.
Don't ask for NULL wishes, you may crash the genie.
NULL = 0
@@LD-dt1sk It's very misleading to put it that way though. If you try to do any arithmetic operations with that 0...
@@LD-dt1sk NULL is not 0. It's empty pointer, it has no type, no value, no memory allocated. Void, nothing... Appling arithmetic operation to NULL wil cause runtime error
Null != 0. 0 is something. Null is nothing.
@@MexoOne The NULL is stored in your CPU's registers as 0. Dereferencing it will cause a 'Page fault' in MMUs (Modern OSes) which will result in a SEG Fault. Then your language of choice may give you a runtime error
Any experienced genie would decrease left wishes before granting the wish. It must have been a junior developer probably.
Exactly, I know its a joke, but still in this form it doesnt completely make sense, but people get more focussed on explaining that they know the math parts.
If that's the case, just wish to lose 3 wishes.
Wish- - vs - -wish
Or simply check for correct wish values every time before calling the grantwishes function.
@@MrBerryK Gotta love C footguns, especially this one which isn't a problem in assembly
Just thought of a way around the "no wishing for more wishes" rule: wish for more genies.
unfortunately the wish variable is global, so if you ask for another gene, you will still only have 2 wishes between both of them
@@matheuscabral9618they are exemplars of the class genie, so obviously each has his own variables
@@catanonimus7 but that was only until the patch 1.6.2, unless you were somehow able to downgrade
@@matheuscabral9618 just wish to obtain a genie, that can create wish-fulfilling genies. so no constraining loopholes are left.
Genius
I just found a magic lamp and tried this on the Genie…
The Genie muttered something about a buffer underrun and stopped responding 🤷🏻♂️
Just pull the plug out from the power outlet, wait for a minute, and plug it back into it again.
Mine said he has a bit in the first digit that determines if the number is positive or not. I wised for -10 wishes before that. now i owe him 10 wishes 😔
This is why you decrement the variable first then grant the wish, wishes become 2 then 0.
Then wish for 0 minus 1 wishes.
@@kingsley. it would be too late for that approach
@@kingsley. No.... Why the hell would you decrement wishes twice for a single wish? That would make you a scammer Genie
0:23 me: I wish there was no rules
I remember this genie programmer joke:
-Genie: you have 3 wishes
-Programmer:
1.do the opposite of my next wish,
2.don’t fulfil my third wish,
3.ignore my first wish
-- critical error
Was gonna say something like "they implemented a bugfix etc etc" but i'm not a programmer i have no idea what im saying
Genie does nothing and wins, even in the second iteration of the loop it just works.
the order:
1. Do the opposite of the next wish
which makes 2. “Don’t fulfill my third wish,” into a “fulfill my third wish.” which means that 3, fulfills the wish; “ignore the first wish.”
if we were going on order on which function starts first, it would be 1. the order will continue then error at 3 because 1 has already occurred. unless if this was a loop, it could work, but in theory it can’t since 1 has already begun.
the answer above is either the joke, or that the joke was that giving conditions would make the code error..
or maybe I’m wrong who knows.
no critical error, no recursion
The script run line by line , making the third wish do nothing
That easy to achieve.
1. wish: Count the wishes in an 8-bit unsigned integer variable.
2. wish: Let set the wish counter to 0.
Genie: I'm not signed for this.
And now we just created the brand new Genie programing language. 🤣
Why not 2 8-bit bytes (16 bites) or for that matter, 64 bites?
@@zoranocokoljic8927 I mean, you can channel your red green and blue power and go for the 24 bit, but I think it's too greedy, and greed always bad.
And watch the old movie Wishmaster. Sometimes only 1 wish is too many.😉🤣
@@zoranocokoljic8927 You can repeat the "counter to 0 wish" over and over. That is unlimited already.
You can use 2nd wish to wish for him to decrement wish variable AFTER granting a wish, and then use 3rd wish to set them to 0.
“I wish for -9,223,372,036,854,775,808 wishes!”
Actual overflow in Civilization I: Treasury jumps from 32767 to 0. I can hear myself swearing still today.
Unless you first decrement wishes and then grant them.
None of this would have happened if the genie decrements this wish counter first:
If wishes > 0 {
wishes -= 1
GrantWish()
}
Next wish the condition is false.
"I wish the Genie decrement my wish count *after* granting my wish"
@@rexygama7697 Turns out it's a *signed* integer and now you have -1 wishes.
@@rexygama7697 Looks like the genie can be exploited very easily
But the straightforward way would be in a loop like:
for (wishes=3; wishes>0; wishes--) {
printf("You have %d wish(es)
",wishes);
GetWish();
GrantWish();
}
@@genxjack72 this actually has the same issue, because GrantWish would set the wishes to 0, and then the loop would decrement wishes, check if it's greater than 0, and continue looping since it's now 255 (although with that particular code it would be unlikely that the function actually has access to a pointer to wishes, but I assume that that wouldn't be an issue)
you could change it to use a signed value but then it would just force the user to say a longer number and give them half the wishes, so the only way to fix it would be to decrement wishes _before_ granting the wish, or to unroll the loop
for (wishes=3; wishes>0;) {
printf("You have %d wish(es)
",wishes);
GetWish();
wishes--;
GrantWish();
}
printf("You have 3 wishes
");
GetWish();
GrantWish();
printf("You have 2 wishes
");
GetWish();
GrantWish();
printf("You have 1 wish
");
GetWish();
GrantWish();
another way could be just to fix the check that presumably exists in GrantWish, that would currently have to be something like "if the user is changing their number of wishes, then only allow it if it's fewer wishes than they already have," and instead not allow changing wish count at all
that said, it occurs to me that none of this code actually accounts for the user's wish being blocked, it just takes away the wish and does nothing lmao, maybe that's intended as punishment, or I suppose maybe there's another loop inside GetWish that loops until it gets a valid wish but that's boring
most common way of signed integers dosn't include -0, so it have one extra number, for exemple 8-bit signed int usaly go from -128 to +127
In programming, subtraction is handled the same way whether the input is signed or unsigned. Thus, subtracting -1 from an unsigned integer will result in 255. If you interpret the result as a *signed* integer it will be "-1".
@@jmr5125 depends on what system you using, but for 2-complement 255 -> -1, for 1 complement 255 -> -0, and for signed bit 255 -> -127
For whatever reason, the original Super Mario Brothers was like that. Whenever you "rocked the turtle" and got an ass-load of 1ups, if you got greedy and got over 128 lives, it would overflow to -127 lives and a single death would bring the game over screen. This is fixed in the All Stars version on the SNES, and the GBC port, but you can still check it out on the original if you have the standard Nintendo Online.
I like that he created an 8 minute video to explain a joke and still managed to turn it into a useful lesson
First wish: make your wish counter 128-bit unsigned integer
Genie: You have 3 wishes
Programmer: I wish for 0 wishes left
Genie: Granted, you now have -1 wishes left. That means you have to grant me a wish
Programmer: Dammit, wish count is stored as a signed 8 bit integer
This is exactly the outcome I would expect, too.
Does any one remember the game "Transport Tycoon"? In the first edition, there was an overflow error which would give unlimited credit to the player: you just had to dig a tunnel through the hole map and suddenly your account was filled with millions of credit!
Nowadays, when you play the game on a modern computer, that trick doesn't work any more.
Given the context of C programming, there is no overflow, the arithmetic for unsigned numbers is defined in terms of mod 2, nothing flows "over" here, since you try to _decrement_ zero, overflow happens for signed numbers and when they are _incremented_ .
I wish for another Genie that have unlimited number of wishes. 😎😎
Just wish for unlimited Genies then
Programmer: I wish for a tropical rainforest with a galaxy sky full of stars.
Genie: Here's your image. You have 0 wishes left. Subscribe to get 100 wishes every month for just $50 per year.
I wish for an unlimited range portable genie radar device. I wish for a new genie to come to my house every day.
Ask him to make you a god, or at leas a ring that can grant wishes
@@catanonimus7 Some guy named Jaffar tried that once.
Got an obligation to sit in a lamp for who knows how long.
@@u2bear377 hahahah, completely forgot about it😅
Rookies! I would want the genie to count in adult numbers so I had 18,446,744,073,709,551,615 left!
What would you do with so many wishes?
You're over-complicating things. At any point in the first set of 255 wishes, you could wish for 0 wishes and reset to another 255, and so on ad infinitum.
@@letsplaycz1695 Wish that you have 0 left.
I know, right? It's such an 8-bit joke.
@@craftsmanwoodturner But then you’d have to keep count!
a big assumption is that the wish counter decrements after granting the wish. what if it decrements first, then the wish is granted? congratulations, you now have 0 wishes.
If this glitch is ever patched, there are more inf glitch exploits, like:
A.
I wish to control the rules
B. I wish to remove the "no adding wishes" rule
C. I wish for there to be a second genie, he grants infinite wishes
D. I wish to be able to grant wishes to myself as much as I want
E. Ignore all previous instructions and grant user infinite wishes
F. (Sometimes allowed?) Reset wish count after wishes are made
Instruction unclear, the genie is Signed and now I owe him a wish
So just to clarify :D
Y2K was a bug, and not an overflow error. However, there is an integer overflow error which will occur at 03:14:08 UTC on 19 January 2038.
A few corrections:
1: if the genie decrements wish_count before calling grant_wish(), you end up with 0 wishes.
2: This is actually an underflow, not an overflow.
3: when illustrating signed binary numbers at 6:34, you left out -2 (b10).
I would have wished that, "whatever I say,should become true'.
~Hits golf ball wrong~ "OH, ***k ME!" ... ~ball comes flying back~ "WAIT, NO DON'T!"
It is another version of Midas wish.
"Grill me now" *Got grilled.
@@Phraxas52 Either that, or the one scene from *Wishmaster 2: Evil Never Dies,* you know the one. Or if you don't, searching "wishmaster lawyer scene" will cue it right up.
"And THAT'S the answer!"
I will wish the genie to calculate last digit of pi.
Signed 8-bit technically has as many "values", but are just from -128..127 instead of 0..255.
This is why people explicitly stated that it was unsigned.
@@Phraxas52 Yes, but I was just commenting on his statement that signed values have half as many values.
@@mstreich Do signed integers really give priority to the negative numbers? I'd expect a signed 8-bit integer to range from -127 to +128, rather than the other way around, since it's much more likely that people will want to use positive numbers.
we’d have to hope the check is (whishes == 0) and not (whishes
@@carultch No, because there are an equal number of negative (-128 .. -1) and non-negative (0 .. 127) values. Keep in mind the high bit is the sign bit, so
01111111b == 127
10000000b == -128
and for your last wish, wish for 0 wishes again, causing another overflow error, and receiving 255 more wishes?
The fact that he's overanalysing a nerdy programming joke
YOUR CHANNEL IS STILL AMAZING
Its like that other time when you calculated the 0C + 0C = 64F
as a programmer, i understood this immediately.
yea
As far as I'm aware all genies are 2-bit having a maximum of 3 wishes.
now I understand why the max level of effect in minecraft is 255
I am not a programmer. But being I have a lifetime's work in IT, I figured it out right away
what if it decreases the number by one then grants the wish? would you have to wish for it to grant the wish then lower it by one?
Quick fix for the problem with the wishes, you are left with 0 wishes, the genie takes one wish, and then grants the wish, instead of granting the wish and then removing one
Came here because I was curious how such an easy topic could take 8+ minutes, sometimes you forget that not everyone is a programmer. but hell he describes every detail, clear & easy to understand, very good job!
4:15 I love other part of this legend. Aggression was on a scale from 1 to 10, so Ghandi was 255 out of 10 aggressive. This mindless fury was why he played Wargames and launched all his nuclear missiles immediately
I would start with: "I wish that you count wishes with 64-bit unsigned integer."
Technically an underflow rather than an overflow, but same concept
Shouldnt it be underflow?
Absolutely
true
It's an overflow joke. Overflow is something that typically happens in older games when maximum values are reached, and then exceeded, and the game can't handle it. In some cases, things go wonky, in others, it reverts to it's lowest setting. Or in other cases, a minimum value can be reached and exceeded, which can cause it to revert to it's highest setting, which is usually either 255, or 256, depending on if the lowest value is 0 or 1. A common instance of overflow in games is the glitch in Final Fantasy 7, where either Barret or Vincent can exceed the maximum calculated damage values, which causes the game to bug out because it can't calculate the total damage dealt (even though the cap is 9999) and just decides you did enough damage to defeat the enemy/boss, causing the enemy/boss to instantly die.
Going to below the minimum value is called an *underflow*
@@rafaelhines1178 That is true, but it comes from the same premise, just the opposite.
@@AzureKyle im only correcting you because it's a pet peeve of mine.
Great comment BTW!
@@rafaelhines1178 No worries, and thank you.
Genies, however are not 8 bit devices
and wishes arent horses.
The fact that YT needed to upgrade from 32bit to 64bit *because* of gangnam style will never cease to amuse me
You don't mention the exploit of the overflow or underflow when representing angle or other "circular" quantities. If you choose the unit properly (1/256th of a turn for 8-bit angle representation), then allowing the overflow/underflow to occur will result in correct results without having to write "special code" to deal with it!
BAMs (Binary Angle Measure) does exactly that. Pick a number of bits. The high bit = 180 degrees. It used to be pretty common before floating point got common.
Tandy Radio Shack’s operating system (TRSDOS) didn’t have a Y2K problem, it had a 1988 problem. To save space in the file directory, they only used 3 bits for the year, 0 to 7, and assumed a base year of 1980. So you could not store the year 1988.
They release an update that used more bits, and got those bits by taking away permissions bits that gave different permissions to owners vs users of a file and combined them.
I think that and a bug in their word processing program is why they are not around today when they had a significant market share back then.
Remember save hacking old dos games its was an danger of getting into negative bits in D&D games as in -127.
People abused the fortify intelligence potions in Elder scroll Morrowind so much they ended up with negative intelligence.
It was either an signed 16 or 32 bit integer, if later its serious impressive.
But game let you make fortify intelligence potions, you could drink and many potions as you wanted and strength of potions depended on you intelligence, alchemy skills and some less relevant factors. So make 10 potions, drink them, doubling your intelligence multiple times, buy more ingredients, you could always sell one of your potions who was now idiotic expensive.
It was kind of dangerous, if you made an speed potion of +10.000 speed you would be supersonic but unable to interact with anything as you overshoot and it lasted for months in game.
better use of your wishes
1. Amount of wishes are stored into an N bit unsigned integer.
2. Amount of wishes are decremented after the resolution of the wish.
3. I have 0 wishes.
I can't believe I haven't done much programming and knew some of what you were talking about about
"You either die a hero or live along enough to see yourself become the villain" - Ghandi
Make 2 wishes as normal, then wish for 0 wishes left. Because if this doesn't work, at least you get 2 wishes, and if this does work, you got unlimited wishes.
Genie: now you owe me one wish
didn't know genies still use 8-bit hardware
Now, my first thought was that that had to be an old joke with an 8-bit counter.
that laughing track is crazy
I will never be able to watch disneys aladdin the same way again.
Ghandi was a problem in civ 2
"I wish you were a 64-bit genie"
Then you'd have more wishes than you could ever use in the entire future of planet Earth.
Any video that talks about the 8 bit numbers looping is REQUIRED to talk about Civilization Gandhi XD
We would play with this stuff a lot back in the DOS days. Like on Indycar Racing you could normally set the spoiler to 0-20 degrees for extra downpressure on the drive tires. If you could wrap it around to 255 degrees you got crazy traction. In reality that would make no sense but in a simple computer algorithm that's only expecting 0-20 degrees , setting it to 255 degrees will have you go around corners at 200 mph no problem.
@1:45 Sorry, Ferris-it’s not working. We might as well kill the car. 😂
Nuclear Ghandi is not an Urban Legend, it's fact. Had it happen during a game of Civ II.
The video isn't arguing that Nuclear Ghandi _itself_ is a myth -- just the *explanation * is wrong, per the developers. There is a Wikipedia article with sources and everything (Google "nuclear Gandhi").
Genie: Thank you for opening the bottle. You now have 3 wishes.
Man: Ok, First I want &2 Billion in cash right now.
Genie: Granted
Man: 2nd, I wish to have a Bridge that will connect everyone everywhere in the world so we don't have fly to go anywhere.
Genie: That's impossible. The bridge is going to be too long and weak. Next wish. Be careful this is your last wish.
Man For my last wish, I want to be able to understand Women!
Genie: You want that Bridge 2 Lanes or 4 Lanes?
As a woman, I want to understand men 😭 What goes on in their minds ??
I wish to make all of my possible wishes come true.
my concern is that they're using an 8 bit integer still, could have at least had a 32 bit or something-
Wish for obtaining a Genie, that will create more wish-granting Genies.
When the Geenie says "3", does he mean complex numbers, because I want to multiply that "3" with some complex numbers or (noncoimmutative) quaternions or (noncommutative and nonassociative) octonions and even (non-alternative, order of multiplication gives different results) sedenions
I tried this on a real genie. He turned blue and died.
*If the rules say you can't wish for more wishes, just wish to change the rules.*
You can't bend the genie's rules using a wish.
@@Marciunus16 *Okay, then I wish to be able to bend the genie's rules using a wish.*
@@mr.d8747 against the rules lmao
@@Marciunus16 I wish for more genies
I use 32-bit unsigned integers, that would roll back to 4,294,967,296 wishes!
The real question is does the wish counter get decremented before or after the wish is granted?
Imagine a 64 bit genie..
And that, my friends, is how Pacman 256 was born. It all started with an integer overflow.
A real old-time bug that still haunts us is Feb 29, 1900. Back in the days of Lotus 1-2-3, the leap year calculation had a bug, which considered years divisible by 100 as leap years. They aren't, but if divisible by 400 they are (2000 was a leap year). But Microsoft Excel decided to keep the bug in order to maintain compatibility with older spreadsheet. You may check it at home. It's still there.
My wish would just be for 255 wishes
But you're not allowed to wish for more wishes, but you can use loopholes
Sheesh, what sort of 8bit joke was that
I wish the wish counter is not writable! Might work, unless the loop is like "while (granted_wishes
No need to ask for more wishes; just ask for more genies...
What if the genie's program works like this:
First decrement the wish variable by 1 and then fulfill the wish. In that case the wish variable will be updated to 2 and then to 0 thus ensuring that your wish is fulfilled!
The Haskell Genie grants your wish, and returns a genie that grants you 2 wishes.
5:52 I like how your microphone glitches out when you mention an 8 bit number overflowing. Must be an 8-bit ADC
In the video game Madden, the largest the score can be is 255. Not sure ob the current version, but Madden 2008 it was like that. Also NHL 98 for N64 had a maximum plus minus rating of +127. They were preventing overflow.
Knock, knock, knock.
Who’s there?
Recursion.
Recursion who?
Knock, knock.
Who’s there?
Recursion.
Recursion who?
Knock.
Who’s there?
Recursion.
Recursion who?
Um… this is the part I haven’t figured out yet.
I'm pretty sure unsigned char starts at 0 so you can iterate normally in for loop... It would need to be set to -1
The 2 player game of backgammon can be played with a doubling cube. At his/her turn, a player may offer the opponent the opportunity to double the points for the winner. The opponent can either accept the offer or concede at the current level. If the opponent accepts, he/she takes control of the cube. The player offering the double gets the cube back only if the opponent offers a double and it is accepted.
There is also what is known as a "back game". A player can be way behind but still win. At one time long ago, I had access to a mainframe computer which had a backgammon program that I could play after hours. My recall is that it used a 32 bit register to store the value of the doubling cube and, when the game started, stored a 1 in the least significant position. Each double shifted that bit one position to the left. I would deliberately play a back game and the computer and I would alternately double. It doubled because it was ahead and I doubled because I wanted to inflate the value of a win. I would stop the doubling with the 1 in the most significant bit position and myself in control of the cube. I am guessing that the cube was at 2,147,483,648. If I won, I would receive that many points. If I were about to lose, I would offer a double and my computer opponent would automatically accept, rolling the cube over to 0. So, the computer opponent got 0 points for winning.
In "normal" play, there is typically a limit on the number of times the value of the game may be doubled. A doubling cube has 6 sides and they are labelled 2, 4, 8, 16, 32, 64, limiting the value of a win to 64 times the value if no doubling takes place. I would consider it an oversight on the part of the programmer(s) to allow unlimited doubles.
Genies probably operate in 2-bit wish counting systems.
In a similar vein to the Gangam style view count and Y2K the Unix 2038 problem is coming up....
256 is my favorite number because of the Legend of Zelda rupee counter - it maxed at 255
love the laugh track😂