Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Let's talk about something that's often overlooked in day to day life but is super important in the
world of video games.
And that is finding the remainder after division.
Here we are playing some Hearthstone where we've already won a coin toss at the start of the game and
we're now dealing some random damage to multimillions on the board before our turn time runs out.
The question is how can any of these decisions relate to division and remainders
if I was to ask you to group every single integer into two equally sized groups.
How would you go about doing that.
Well my first thought would be to split them into even and odd numbers.
And what this essentially means is that if we're dividing our number by two it will have either a reminder
of zero.
If it's even so perfectly divide by two and if it doesn't it will have a reminder of one because it'll
always be one away from being even.
So no matter which number we pick it will fall into one of these two categories so why is that important
why do we care.
Well imagine we're going to simulate a coin toss.
And here's a terribly drawn coin for you.
So we could say that if it's heads then play a one will go first.
And if it's tails then player two would go fast.
So we have a binary choice here the same as we have these binary categories up here although just note
that this isn't the binary logic case of one being true and zero being false.
So we could take pretty much any random number that we like say seven hundred and sixty three for example
and we could say that if that number turns out to be even then play a one will go fast.
So we will show them heads on the screen and if it's odd which in this case it is then play it to will
go first and will display tails.
So hopefully you can see how we can link these concepts together and use remainders from division to
make some sort of choice.
Now we could also extend this and imagine we have say a number divided by four.
What would this do.
Well if we divide our number by four then Eliezer have a remainder of zero.
If it's perfectly divisible or have a remainder of 1 2 or 3 and so if we quickly just draw our little
table in here and let's try that line again.
Okay.
And then we can start filling in our numbers so we know that one will have a remainder of one two three
four will be perfectly divisible and then we just keep going up and can see this kind of cyclical repeating
pattern happening as we add our numbers.
So it resets every four numbers which can be really handy.
Imagine that we have say a counter that's counting up from the start of our game does say how long the
level has been active or something like that.
We can then use that information to make some decisions.
So for example say this was something that was happening every four seconds in our game and our game
level had been running for nine seconds at this point.
Well we can say that that would be one second into turn three or cycle three.
So you got the first second and third cycle here and that might be useful say if you're looking for
the term counter that repeats every 30 seconds and knowing which turn it currently is so maybe your
game lasts for 10 rounds and this would be round three.
You could also use this information to then link it back to this binary choice here and say well we
know who went first.
And we know that we're on the third turn.
So if Player 2 went first it would currently be player to turn again now that we have an idea of how
to use remainders.
Let's look at how we actually work these out using our calculators.
As with most things there is a handy button that will just do the work for us.
But the calculation is quite simple so let's start by picking two numbers.
So let's do twenty three divided by four and that will give us five point seven five once we've got
that.
We then need to remove the whole numbers just to leave the decimals.
So we remove our five and that will give us zero point seven five next.
We have to multiply by our original divide.
So this case for that will leave us with three which is our remainder.
So we can comfortably say that 23 divided by four will give us a remainder of three.
And if we want to check that we can say four times five plus three and that would equal four times five
is 20 plus our three is twenty three.
So we know that the answer is definitely correct.
When it comes to programming we actually have a much easier time because we can use something called
the remainder operator and that essentially looks like the percentage sign that we're all familiar with.
And when we use it we use it very similarly to the other arithmetic operators.
So plus minus multiply and divide so with all 23 divided by for example we could say 23 remained a full
will give us three.
All we could do something like 15 remainder five and that would give us zero because five goes into
15.
Exactly three times with no remainder for a small code example of this.
We could say if some random number
remained the two equals zero then run our code.
And this is akin to our coin flipping example and this if statement would essentially try and find an
even number.
So now it's time for your challenge.
Let's imagine a four play a game and we're going to give each player a remainder of 0 1 2 or 3.
Then let's take some random number say 63 and find the remainder after dividing by four.
We want to know who will go first.
And that will be the player whose remainder matches.
So if the remainder is zero then the person with the zero remainder will go first.
I'd like to try doing this calculation with both your calculator and in code
and for a bit of extra fun try setting a new number for the next person in the chain.
Once you've got your answers pop them in the community forum and I'll see you in the next lecture.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.