0:00:04.799,0:00:11.040
in this exercise we are asked to
0:00:07.200,0:00:15.040
use the modulo operator integer division
0:00:11.040,0:00:17.600
or both to take a four digit number
0:00:15.040,0:00:18.400
and find the digit in the thousands
0:00:17.600,0:00:22.240
hundreds
0:00:18.400,0:00:25.359
tens and ones place so let's begin with
0:00:22.240,0:00:25.359
the thousands place
0:00:27.359,0:00:31.119
i'll initialize a local variable
0:00:29.519,0:00:34.079
thousands
0:00:31.119,0:00:35.040
and we need a four digit number for this
0:00:34.079,0:00:39.280
exercise
0:00:35.040,0:00:42.079
let's use the number 4936
0:00:39.280,0:00:43.600
finding the digit in the thousands place
0:00:42.079,0:00:47.600
for a four digit number
0:00:43.600,0:00:50.480
is pretty simple using integer division
0:00:47.600,0:00:52.239
we'll simply divide by a thousand and
0:00:50.480,0:00:54.879
the return value of that integer
0:00:52.239,0:00:59.680
division will be four
0:00:54.879,0:01:02.800
to see that
0:00:59.680,0:01:05.519
let's use string interpolation
0:01:02.800,0:01:07.840
and output that result i'll hop over to
0:01:05.519,0:01:10.960
the command line
0:01:07.840,0:01:13.439
and run our file
0:01:10.960,0:01:15.280
as expected the return value of that
0:01:13.439,0:01:17.520
operation was four
0:01:15.280,0:01:19.200
now that we've successfully found the
0:01:17.520,0:01:23.040
digit in the thousands place
0:01:19.200,0:01:23.040
let's move on to the hundreds place
0:01:24.000,0:01:29.040
for the rest of this exercise the modulo
0:01:26.880,0:01:31.600
operator is going to come in handy
0:01:29.040,0:01:35.200
let's move back over to our command line
0:01:31.600,0:01:38.840
and hop into irb to see how this works
0:01:35.200,0:01:41.320
we saw that using integer division to
0:01:38.840,0:01:45.200
divide
0:01:41.320,0:01:48.560
4936 by 1000
0:01:45.200,0:01:52.079
returned 4. the modulo operator
0:01:48.560,0:01:52.079
returns the remainder
0:01:53.439,0:01:59.600
in this case that's 936.
0:01:57.360,0:02:01.759
once we have this three-digit number
0:01:59.600,0:02:04.560
it's easy to isolate the digit in the
0:02:01.759,0:02:04.560
hundreds place
0:02:04.880,0:02:11.840
with integer division again we'll divide
0:02:08.520,0:02:14.239
936 by 100 and return
0:02:11.840,0:02:14.239
9.
0:02:16.959,0:02:23.840
so let's go back to our text editor
0:02:24.640,0:02:27.920
we'll use the modulo operator to get the
0:02:26.800,0:02:33.840
remainder of
0:02:27.920,0:02:33.840
dividing 4936 by 1000
0:02:34.959,0:02:38.560
and divide that by one hundred
0:02:42.000,0:02:46.720
and we expect that the integer
0:02:44.400,0:02:47.280
referenced by the variable hundreds will
0:02:46.720,0:02:53.440
be
0:02:47.280,0:02:53.440
nine let's hop over to the command line
0:02:56.160,0:03:00.319
and we see nine as we were expecting
0:03:02.400,0:03:08.159
now let's move on to isolating the digit
0:03:05.120,0:03:08.159
in the tens place
0:03:08.480,0:03:11.760
we'll follow a similar process here as
0:03:10.959,0:03:14.480
we did
0:03:11.760,0:03:15.120
for finding the digit in the hundreds
0:03:14.480,0:03:17.760
place
0:03:15.120,0:03:18.879
however this time we need the remainder
0:03:17.760,0:03:23.200
of dividing
0:03:18.879,0:03:23.200
the original number by 100
0:03:25.040,0:03:29.519
and we expect that the return of this
0:03:27.120,0:03:32.000
operation will be 36
0:03:29.519,0:03:34.720
so we'll use integer division to divide
0:03:32.000,0:03:34.720
that by 10
0:03:36.400,0:03:40.400
and now we expect that the local
0:03:38.560,0:03:43.519
variable tens
0:03:40.400,0:03:43.519
references three
0:03:45.680,0:03:48.319
and it does
0:03:50.879,0:03:56.080
so we're almost finished our last step
0:03:53.599,0:03:58.000
is to isolate the digit in the ones
0:03:56.080,0:04:00.560
place
0:03:58.000,0:04:02.799
and again this will be very similar to
0:04:00.560,0:04:05.360
what we just did to isolate the three
0:04:02.799,0:04:07.680
from the tens place
0:04:05.360,0:04:10.640
this time we need the remainder of
0:04:07.680,0:04:13.840
dividing our original four digit number
0:04:10.640,0:04:16.720
by ten we expect that this
0:04:13.840,0:04:18.160
operation alone will return the last
0:04:16.720,0:04:20.959
digit in the number
0:04:18.160,0:04:21.600
six and therefore we don't need to
0:04:20.959,0:04:23.919
perform
0:04:21.600,0:04:29.840
any additional integer division like we
0:04:23.919,0:04:29.840
did for the previous steps
0:04:37.680,0:04:40.880
we run our file and we see that we've
0:04:40.000,0:04:43.440
successfully
0:04:40.880,0:04:45.759
isolated 6 as the digit in the ones
0:04:43.440,0:04:45.759
place
0:04:47.600,0:04:54.840
integer division and the modulo operator
0:04:50.800,0:04:57.840
are important tools for working with
0:04:54.840,0:04:57.840
integers
0:04:59.040,0:05:01.120
you