Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:05,130 --> 00:00:09,870
Let's talk about something that's often overlooked in day to day life but is super important in the
2
00:00:09,870 --> 00:00:11,240
world of video games.
3
00:00:11,280 --> 00:00:14,500
And that is finding the remainder after division.
4
00:00:14,520 --> 00:00:19,650
Here we are playing some Hearthstone where we've already won a coin toss at the start of the game and
5
00:00:19,680 --> 00:00:26,430
we're now dealing some random damage to multimillions on the board before our turn time runs out.
6
00:00:26,460 --> 00:00:32,070
The question is how can any of these decisions relate to division and remainders
7
00:00:35,050 --> 00:00:40,530
if I was to ask you to group every single integer into two equally sized groups.
8
00:00:40,540 --> 00:00:42,790
How would you go about doing that.
9
00:00:42,790 --> 00:00:50,330
Well my first thought would be to split them into even and odd numbers.
10
00:00:50,480 --> 00:00:57,050
And what this essentially means is that if we're dividing our number by two it will have either a reminder
11
00:00:57,140 --> 00:00:58,470
of zero.
12
00:00:58,670 --> 00:01:05,010
If it's even so perfectly divide by two and if it doesn't it will have a reminder of one because it'll
13
00:01:05,040 --> 00:01:07,780
always be one away from being even.
14
00:01:08,090 --> 00:01:15,820
So no matter which number we pick it will fall into one of these two categories so why is that important
15
00:01:15,820 --> 00:01:17,200
why do we care.
16
00:01:17,200 --> 00:01:20,250
Well imagine we're going to simulate a coin toss.
17
00:01:20,380 --> 00:01:23,820
And here's a terribly drawn coin for you.
18
00:01:23,950 --> 00:01:28,820
So we could say that if it's heads then play a one will go first.
19
00:01:29,140 --> 00:01:32,940
And if it's tails then player two would go fast.
20
00:01:32,950 --> 00:01:39,550
So we have a binary choice here the same as we have these binary categories up here although just note
21
00:01:39,580 --> 00:01:45,700
that this isn't the binary logic case of one being true and zero being false.
22
00:01:45,700 --> 00:01:52,060
So we could take pretty much any random number that we like say seven hundred and sixty three for example
23
00:01:52,630 --> 00:02:00,110
and we could say that if that number turns out to be even then play a one will go fast.
24
00:02:00,130 --> 00:02:07,170
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
25
00:02:07,170 --> 00:02:10,090
go first and will display tails.
26
00:02:10,260 --> 00:02:17,130
So hopefully you can see how we can link these concepts together and use remainders from division to
27
00:02:17,160 --> 00:02:19,400
make some sort of choice.
28
00:02:19,440 --> 00:02:25,770
Now we could also extend this and imagine we have say a number divided by four.
29
00:02:26,040 --> 00:02:27,210
What would this do.
30
00:02:27,270 --> 00:02:32,040
Well if we divide our number by four then Eliezer have a remainder of zero.
31
00:02:32,070 --> 00:02:41,710
If it's perfectly divisible or have a remainder of 1 2 or 3 and so if we quickly just draw our little
32
00:02:41,710 --> 00:02:46,280
table in here and let's try that line again.
33
00:02:46,410 --> 00:02:46,760
Okay.
34
00:02:46,770 --> 00:02:53,100
And then we can start filling in our numbers so we know that one will have a remainder of one two three
35
00:02:53,370 --> 00:03:00,510
four will be perfectly divisible and then we just keep going up and can see this kind of cyclical repeating
36
00:03:00,510 --> 00:03:03,390
pattern happening as we add our numbers.
37
00:03:03,450 --> 00:03:07,700
So it resets every four numbers which can be really handy.
38
00:03:07,710 --> 00:03:13,500
Imagine that we have say a counter that's counting up from the start of our game does say how long the
39
00:03:13,590 --> 00:03:16,680
level has been active or something like that.
40
00:03:16,830 --> 00:03:20,580
We can then use that information to make some decisions.
41
00:03:20,580 --> 00:03:27,150
So for example say this was something that was happening every four seconds in our game and our game
42
00:03:27,240 --> 00:03:29,990
level had been running for nine seconds at this point.
43
00:03:30,300 --> 00:03:37,670
Well we can say that that would be one second into turn three or cycle three.
44
00:03:37,680 --> 00:03:44,340
So you got the first second and third cycle here and that might be useful say if you're looking for
45
00:03:44,670 --> 00:03:51,870
the term counter that repeats every 30 seconds and knowing which turn it currently is so maybe your
46
00:03:51,870 --> 00:03:56,290
game lasts for 10 rounds and this would be round three.
47
00:03:56,330 --> 00:04:01,880
You could also use this information to then link it back to this binary choice here and say well we
48
00:04:01,880 --> 00:04:03,330
know who went first.
49
00:04:03,470 --> 00:04:06,270
And we know that we're on the third turn.
50
00:04:06,320 --> 00:04:14,930
So if Player 2 went first it would currently be player to turn again now that we have an idea of how
51
00:04:14,930 --> 00:04:16,130
to use remainders.
52
00:04:16,160 --> 00:04:20,090
Let's look at how we actually work these out using our calculators.
53
00:04:20,090 --> 00:04:24,390
As with most things there is a handy button that will just do the work for us.
54
00:04:24,500 --> 00:04:29,330
But the calculation is quite simple so let's start by picking two numbers.
55
00:04:29,330 --> 00:04:40,040
So let's do twenty three divided by four and that will give us five point seven five once we've got
56
00:04:40,040 --> 00:04:40,330
that.
57
00:04:40,340 --> 00:04:44,320
We then need to remove the whole numbers just to leave the decimals.
58
00:04:44,480 --> 00:04:53,970
So we remove our five and that will give us zero point seven five next.
59
00:04:53,990 --> 00:04:57,230
We have to multiply by our original divide.
60
00:04:57,260 --> 00:05:04,170
So this case for that will leave us with three which is our remainder.
61
00:05:04,690 --> 00:05:10,300
So we can comfortably say that 23 divided by four will give us a remainder of three.
62
00:05:10,360 --> 00:05:19,520
And if we want to check that we can say four times five plus three and that would equal four times five
63
00:05:19,580 --> 00:05:23,500
is 20 plus our three is twenty three.
64
00:05:23,540 --> 00:05:26,320
So we know that the answer is definitely correct.
65
00:05:26,600 --> 00:05:31,670
When it comes to programming we actually have a much easier time because we can use something called
66
00:05:31,670 --> 00:05:37,490
the remainder operator and that essentially looks like the percentage sign that we're all familiar with.
67
00:05:37,490 --> 00:05:41,570
And when we use it we use it very similarly to the other arithmetic operators.
68
00:05:41,570 --> 00:05:53,880
So plus minus multiply and divide so with all 23 divided by for example we could say 23 remained a full
69
00:05:55,770 --> 00:05:57,980
will give us three.
70
00:05:58,230 --> 00:06:07,440
All we could do something like 15 remainder five and that would give us zero because five goes into
71
00:06:07,520 --> 00:06:08,090
15.
72
00:06:08,100 --> 00:06:13,590
Exactly three times with no remainder for a small code example of this.
73
00:06:13,590 --> 00:06:17,790
We could say if some random number
74
00:06:20,310 --> 00:06:26,860
remained the two equals zero then run our code.
75
00:06:27,020 --> 00:06:32,390
And this is akin to our coin flipping example and this if statement would essentially try and find an
76
00:06:32,480 --> 00:06:35,920
even number.
77
00:06:35,940 --> 00:06:38,280
So now it's time for your challenge.
78
00:06:38,310 --> 00:06:46,290
Let's imagine a four play a game and we're going to give each player a remainder of 0 1 2 or 3.
79
00:06:46,480 --> 00:06:54,330
Then let's take some random number say 63 and find the remainder after dividing by four.
80
00:06:54,420 --> 00:06:57,110
We want to know who will go first.
81
00:06:57,210 --> 00:07:01,560
And that will be the player whose remainder matches.
82
00:07:01,590 --> 00:07:09,240
So if the remainder is zero then the person with the zero remainder will go first.
83
00:07:09,270 --> 00:07:14,520
I'd like to try doing this calculation with both your calculator and in code
84
00:07:18,130 --> 00:07:24,410
and for a bit of extra fun try setting a new number for the next person in the chain.
85
00:07:24,410 --> 00:07:29,480
Once you've got your answers pop them in the community forum and I'll see you in the next lecture.
9000
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.