WEBVTT 00:00:00.000 --> 00:00:03.486 align:middle line:90% [MUSIC PLAYING] 00:00:03.486 --> 00:01:23.527 align:middle line:90% 00:01:23.527 --> 00:01:24.610 align:middle line:90% DAVID J. MALAN: All right. 00:01:24.610 --> 00:01:27.540 align:middle line:84% This is CS50, Yale University's introduction 00:01:27.540 --> 00:01:29.860 align:middle line:84% to the intellectual enterprises of computer science 00:01:29.860 --> 00:01:31.180 align:middle line:90% and the arts of programming. 00:01:31.180 --> 00:01:34.420 align:middle line:84% All of that and so much more will make great sense before long. 00:01:34.420 --> 00:01:37.720 align:middle line:84% And I thought I'd mention that Benedict and I actually go way back. 00:01:37.720 --> 00:01:40.257 align:middle line:84% He and I were classmates at Harvard some 20-plus years ago. 00:01:40.257 --> 00:01:42.340 align:middle line:84% And we went through our archives, even though this 00:01:42.340 --> 00:01:45.400 align:middle line:84% was well before digital cameras, and found this one. 00:01:45.400 --> 00:01:47.050 align:middle line:90% I used to go over to Benedict's room. 00:01:47.050 --> 00:01:49.468 align:middle line:84% And I was friendly with some of his roommates as well. 00:01:49.468 --> 00:01:52.760 align:middle line:84% And if you can see here, this is a stack of some very cheap pizza in Cambridge, 00:01:52.760 --> 00:01:54.610 align:middle line:90% Massachusetts, from Pizza Ring. 00:01:54.610 --> 00:01:57.850 align:middle line:84% It was so amazing that they would give you two pies at once 00:01:57.850 --> 00:02:00.220 align:middle line:90% in the same box for like $8. 00:02:00.220 --> 00:02:03.910 align:middle line:84% And if we enhance here, this is our own Professor Brown. 00:02:03.910 --> 00:02:05.440 align:middle line:90% So he and I go way back. 00:02:05.440 --> 00:02:09.460 align:middle line:84% And it's only fortuitous that we've now come full circle and are together now, 00:02:09.460 --> 00:02:11.620 align:middle line:90% teaching this course here at Yale. 00:02:11.620 --> 00:02:14.587 align:middle line:84% So if you are leaning toward computer science, 00:02:14.587 --> 00:02:17.920 align:middle line:84% you might already have some comfort with the idea of being in a class like this. 00:02:17.920 --> 00:02:19.670 align:middle line:90% But odds are, you don't. 00:02:19.670 --> 00:02:22.180 align:middle line:84% And in fact, if you're anything like me back in the day, 00:02:22.180 --> 00:02:24.910 align:middle line:84% I had no interest in or really appreciation 00:02:24.910 --> 00:02:28.090 align:middle line:84% of what computer science was back in my first year of college. 00:02:28.090 --> 00:02:29.980 align:middle line:84% And in fact, when I got to college, I really 00:02:29.980 --> 00:02:32.260 align:middle line:84% gravitated toward things I was more familiar with. 00:02:32.260 --> 00:02:34.510 align:middle line:84% At the time, I'd come off the heels of high school. 00:02:34.510 --> 00:02:37.360 align:middle line:84% And I really liked a constitutional law class in high school. 00:02:37.360 --> 00:02:39.960 align:middle line:84% And I liked history and that sort of domain. 00:02:39.960 --> 00:02:41.710 align:middle line:84% And so I just kind of naturally gravitated 00:02:41.710 --> 00:02:43.900 align:middle line:84% when I got to Cambridge toward government, 00:02:43.900 --> 00:02:47.260 align:middle line:84% which was the closest concentration or major there in Cambridge. 00:02:47.260 --> 00:02:49.780 align:middle line:84% And I was still, nonetheless, kind of a geek as a kid. 00:02:49.780 --> 00:02:52.060 align:middle line:84% I certainly played with computers or computer games. 00:02:52.060 --> 00:02:54.760 align:middle line:84% But I never really took a genuine interest in it. 00:02:54.760 --> 00:02:57.130 align:middle line:84% And even my friends, ironically in retrospect, 00:02:57.130 --> 00:02:59.140 align:middle line:84% who did take computer science in high school, 00:02:59.140 --> 00:03:01.690 align:middle line:84% I thought they were actually the geeks and didn't really see 00:03:01.690 --> 00:03:04.720 align:middle line:84% the appeal of heads down at a computer monitor, typing away, 00:03:04.720 --> 00:03:06.370 align:middle line:90% door closed, fluorescent lights. 00:03:06.370 --> 00:03:09.128 align:middle line:84% It just didn't really make any sense to me or resonate. 00:03:09.128 --> 00:03:11.170 align:middle line:84% But I finally, sophomore year, I got up the nerve 00:03:11.170 --> 00:03:14.637 align:middle line:84% to shop a course that was and still is now called CS50. 00:03:14.637 --> 00:03:16.720 align:middle line:84% It was being offered only at Harvard at that time. 00:03:16.720 --> 00:03:19.270 align:middle line:84% And even then, I only got up the nerve to go into that lecture hall 00:03:19.270 --> 00:03:21.940 align:middle line:84% because the professor at the time let me sign up pass-fail, 00:03:21.940 --> 00:03:25.660 align:middle line:84% since I really rather feared failure of some sort 00:03:25.660 --> 00:03:27.767 align:middle line:84% because it was just so new and unfamiliar to me. 00:03:27.767 --> 00:03:30.100 align:middle line:84% But long story short, I ended up falling in love with it 00:03:30.100 --> 00:03:32.680 align:middle line:84% once I actually came to realize what it was. 00:03:32.680 --> 00:03:35.500 align:middle line:84% And no joke, on Friday evenings, when back then the homework 00:03:35.500 --> 00:03:37.580 align:middle line:84% assignments or problem sets would be released, 00:03:37.580 --> 00:03:40.288 align:middle line:84% I would legitimately look forward to going back to my dorm room-- 00:03:40.288 --> 00:03:42.580 align:middle line:84% 7:00 PM, the p set would be released-- and diving 00:03:42.580 --> 00:03:44.950 align:middle line:90% into that week's programming challenge. 00:03:44.950 --> 00:03:45.640 align:middle line:90% But why? 00:03:45.640 --> 00:03:50.140 align:middle line:84% So at the end of the day, computer science really isn't about programming. 00:03:50.140 --> 00:03:53.290 align:middle line:84% It's probably not about what you perceived your own friends as doing 00:03:53.290 --> 00:03:55.300 align:middle line:90% in high school versions thereof. 00:03:55.300 --> 00:03:57.460 align:middle line:84% It really is about problem solving more generally. 00:03:57.460 --> 00:04:00.550 align:middle line:84% So if you're feeling at all uncomfortable with the idea of shopping 00:04:00.550 --> 00:04:04.150 align:middle line:84% or taking a class like this, realize that most of the people around you 00:04:04.150 --> 00:04:05.080 align:middle line:90% feel that same way. 00:04:05.080 --> 00:04:09.533 align:middle line:84% 2/3 of CS50 students each year have no prior CS experience. 00:04:09.533 --> 00:04:11.950 align:middle line:84% So even though on occasion it might sound like it, perhaps 00:04:11.950 --> 00:04:14.950 align:middle line:84% based on answers that others seem to be giving or facial expressions 00:04:14.950 --> 00:04:17.380 align:middle line:84% they might be having, it's really not actually the case. 00:04:17.380 --> 00:04:21.250 align:middle line:84% 2/3 of you are feeling as uncomfortable or less comfortable 00:04:21.250 --> 00:04:22.642 align:middle line:90% as I was back in the day. 00:04:22.642 --> 00:04:24.850 align:middle line:84% But the course itself, as you'll see in the syllabus, 00:04:24.850 --> 00:04:27.050 align:middle line:90% really focuses on students individually. 00:04:27.050 --> 00:04:29.170 align:middle line:84% There is no course-wide curve per se, but rather 00:04:29.170 --> 00:04:31.262 align:middle line:84% what's going to matter ultimately is not so much 00:04:31.262 --> 00:04:34.220 align:middle line:84% where you end up relative to your classmates at the end of this course, 00:04:34.220 --> 00:04:37.720 align:middle line:84% but where you end up relative to yourself as of today, 00:04:37.720 --> 00:04:42.440 align:middle line:84% and focusing on that delta and that sense of progression yourselves. 00:04:42.440 --> 00:04:44.200 align:middle line:90% So what then is computer science? 00:04:44.200 --> 00:04:46.220 align:middle line:90% I daresay we can simplify it as this. 00:04:46.220 --> 00:04:47.188 align:middle line:90% So problem solving. 00:04:47.188 --> 00:04:48.730 align:middle line:90% What does it mean to solve a problem? 00:04:48.730 --> 00:04:51.340 align:middle line:84% And that domain itself doesn't have to be engineering, 00:04:51.340 --> 00:04:52.960 align:middle line:90% doesn't have to be science per se. 00:04:52.960 --> 00:04:54.760 align:middle line:84% Really, I daresay we can generalize problem 00:04:54.760 --> 00:04:56.305 align:middle line:90% solving to be a picture like this. 00:04:56.305 --> 00:04:58.930 align:middle line:84% There's some kind of input, the problem that you want to solve. 00:04:58.930 --> 00:05:01.990 align:middle line:84% And there's an output, hopefully the solution to that problem. 00:05:01.990 --> 00:05:05.560 align:middle line:84% And then between is this sort of proverbial, a proverbial black box, 00:05:05.560 --> 00:05:08.740 align:middle line:84% this sort of secret sauce that somehow takes that input 00:05:08.740 --> 00:05:10.180 align:middle line:90% and produces that output. 00:05:10.180 --> 00:05:13.623 align:middle line:84% And it's not yet apparent to us how it does that. 00:05:13.623 --> 00:05:15.790 align:middle line:84% But that's the goal, ultimately, of computer science 00:05:15.790 --> 00:05:17.470 align:middle line:90% and solving problems more generally. 00:05:17.470 --> 00:05:19.180 align:middle line:84% But to get to that point, I claim that we 00:05:19.180 --> 00:05:21.910 align:middle line:84% need to talk a little bit about what computer scientists would 00:05:21.910 --> 00:05:24.820 align:middle line:84% call representation, like how you actually represent 00:05:24.820 --> 00:05:26.770 align:middle line:90% those inputs and those outputs. 00:05:26.770 --> 00:05:29.680 align:middle line:84% And odds are, even if you really aren't a computer person yourself, 00:05:29.680 --> 00:05:34.460 align:middle line:84% you probably know that computers only speak a certain language of sorts, 00:05:34.460 --> 00:05:37.180 align:middle line:90% an alphabet called binary. 00:05:37.180 --> 00:05:37.993 align:middle line:90% So binary. 00:05:37.993 --> 00:05:39.910 align:middle line:84% But probably fewer of you have an appreciation 00:05:39.910 --> 00:05:43.210 align:middle line:84% of what that actually means and how you get from 0s and 1s 00:05:43.210 --> 00:05:48.020 align:middle line:84% to Google documents and Facebook and Instagram and applications and all 00:05:48.020 --> 00:05:51.380 align:middle line:84% of the complexities that we use and carry around with us every day. 00:05:51.380 --> 00:05:54.628 align:middle line:84% But let's start with the simplest form of representation of information. 00:05:54.628 --> 00:05:56.920 align:middle line:84% Like if I were to start taking attendance in this room, 00:05:56.920 --> 00:06:00.130 align:middle line:84% I might, old school-style, just take a piece of chalk or a pencil 00:06:00.130 --> 00:06:02.937 align:middle line:90% and just say, OK, 1, 2, 3, 4. 00:06:02.937 --> 00:06:05.020 align:middle line:84% And then I might get a little efficient and say 5, 00:06:05.020 --> 00:06:06.478 align:middle line:90% just to make obvious that it's a 5. 00:06:06.478 --> 00:06:08.540 align:middle line:84% But these are just hash marks on a screen. 00:06:08.540 --> 00:06:10.480 align:middle line:84% And of course, I don't have to do it in chalk. 00:06:10.480 --> 00:06:14.290 align:middle line:84% I can just do 1, 2, 3, 4, 5 and then count even higher 00:06:14.290 --> 00:06:16.167 align:middle line:90% if I use other digits as well. 00:06:16.167 --> 00:06:18.250 align:middle line:84% And digits, it's kind of a nice coincidence there. 00:06:18.250 --> 00:06:20.125 align:middle line:84% And we'll come back to that in just a moment. 00:06:20.125 --> 00:06:23.410 align:middle line:84% This system of using hash marks on the board or using your own human fingers 00:06:23.410 --> 00:06:26.170 align:middle line:84% is what's called unary, uno implying one, 00:06:26.170 --> 00:06:28.370 align:middle line:84% where the hash mark is either there or it's not. 00:06:28.370 --> 00:06:32.080 align:middle line:84% And so, 1, 2, 3, 4, 5, it's like using sticks or fingers or hash marks. 00:06:32.080 --> 00:06:33.790 align:middle line:90% That's unary notation. 00:06:33.790 --> 00:06:36.340 align:middle line:84% There's only one letter in your alphabet, so to speak. 00:06:36.340 --> 00:06:39.940 align:middle line:84% And it happens to be a 1 or a hash mark or a finger, whatever 00:06:39.940 --> 00:06:41.950 align:middle line:90% the unit of measure happens to be. 00:06:41.950 --> 00:06:46.250 align:middle line:84% So you can get, though, from using that unary notation of course, 00:06:46.250 --> 00:06:49.000 align:middle line:84% counting up even higher if we use more hash marks or more fingers. 00:06:49.000 --> 00:06:51.700 align:middle line:84% And we get to the more familiar system that we all use, 00:06:51.700 --> 00:06:54.610 align:middle line:84% which is called the decimal system, dec meaning 10. 00:06:54.610 --> 00:06:58.090 align:middle line:84% And the only reason for that is because you've got 10 letters in your alphabet 00:06:58.090 --> 00:06:59.950 align:middle line:90% so to speak, 0 through 9. 00:06:59.950 --> 00:07:00.753 align:middle line:90% 10 total digits. 00:07:00.753 --> 00:07:03.670 align:middle line:84% And these are the kinds of numbers that you and I use and sort of take 00:07:03.670 --> 00:07:05.110 align:middle line:90% for granted every day. 00:07:05.110 --> 00:07:07.870 align:middle line:84% But a bunch of you already know and realize that computers somehow 00:07:07.870 --> 00:07:10.180 align:middle line:90% only speak 0s and 1s. 00:07:10.180 --> 00:07:12.520 align:middle line:84% And yet, my god, a computer, my phone, any number 00:07:12.520 --> 00:07:16.030 align:middle line:84% of electronic devices these days, are so much more powerful, it would seem, 00:07:16.030 --> 00:07:17.200 align:middle line:90% than us humans. 00:07:17.200 --> 00:07:19.570 align:middle line:84% So how is it that using just 0s and 1s, they 00:07:19.570 --> 00:07:21.397 align:middle line:90% can achieve that kind of complexity? 00:07:21.397 --> 00:07:23.980 align:middle line:84% Well, turns out it's pretty much the same way we humans think. 00:07:23.980 --> 00:07:27.550 align:middle line:84% It's just we haven't thought this way explicitly for quite some time. 00:07:27.550 --> 00:07:29.440 align:middle line:84% For instance, on the screen here is what? 00:07:29.440 --> 00:07:31.570 align:middle line:90% Shout out the obvious. 00:07:31.570 --> 00:07:32.840 align:middle line:90% 123. 00:07:32.840 --> 00:07:33.560 align:middle line:90% All right. 00:07:33.560 --> 00:07:34.630 align:middle line:90% But why is that? 00:07:34.630 --> 00:07:36.010 align:middle line:90% 123. 00:07:36.010 --> 00:07:38.800 align:middle line:84% Really, well, all that's on the screen is three symbols. 00:07:38.800 --> 00:07:42.100 align:middle line:84% And frankly, if we rewound quite a few years in your development, 00:07:42.100 --> 00:07:44.380 align:middle line:84% it would look like just three cryptic symbols. 00:07:44.380 --> 00:07:46.720 align:middle line:84% But you and I ascribe meaning to these symbols now. 00:07:46.720 --> 00:07:47.260 align:middle line:90% But why? 00:07:47.260 --> 00:07:49.180 align:middle line:90% And from where does this meaning come? 00:07:49.180 --> 00:07:51.250 align:middle line:84% Well, if you roll back far enough in time, 00:07:51.250 --> 00:07:54.510 align:middle line:84% odds are you'll recall that when thinking about a number like 1, 00:07:54.510 --> 00:07:59.320 align:middle line:84% a pattern like 123, we sort of instantly these days intuitively ascribe meaning. 00:07:59.320 --> 00:08:02.560 align:middle line:84% So this is the so-called 1s column or 1s place, 00:08:02.560 --> 00:08:07.360 align:middle line:84% this is the 10s column or 10s place, and this is the 100s column or 100s place. 00:08:07.360 --> 00:08:10.510 align:middle line:84% And so all of us rather instantaneously these days do the math. 00:08:10.510 --> 00:08:17.440 align:middle line:84% 100 times 1 plus 10 times 2 plus 1 times 3, which is, of course, 100 plus 20 00:08:17.440 --> 00:08:21.640 align:middle line:84% plus 3, which gets us back, to be fair, to the same symbols. 00:08:21.640 --> 00:08:23.410 align:middle line:84% But now they have meaning because we have 00:08:23.410 --> 00:08:25.720 align:middle line:84% imposed meaning based on the positions of those values 00:08:25.720 --> 00:08:27.130 align:middle line:90% and which symbols they are. 00:08:27.130 --> 00:08:31.030 align:middle line:84% So all of us do this every day any time we stare at or use a number. 00:08:31.030 --> 00:08:33.220 align:middle line:84% Well, it turns out that computers are actually 00:08:33.220 --> 00:08:35.679 align:middle line:90% doing fundamentally the same thing. 00:08:35.679 --> 00:08:39.100 align:middle line:84% They just tend to do it using fewer letters in their alphabet. 00:08:39.100 --> 00:08:42.580 align:middle line:84% They don't have 2s and 3s, let alone 8s and 9s. 00:08:42.580 --> 00:08:44.110 align:middle line:90% They only have 0s and 1s. 00:08:44.110 --> 00:08:48.310 align:middle line:84% But it still works, because instead of using these values, for instance, 00:08:48.310 --> 00:08:54.380 align:middle line:84% I can go ahead and use, not 0 through 9, but just 0 and 1 as follows. 00:08:54.380 --> 00:08:56.770 align:middle line:84% Let me give myself sort of three placeholders again, 00:08:56.770 --> 00:08:58.270 align:middle line:90% three columns if you will. 00:08:58.270 --> 00:09:01.630 align:middle line:84% But rather than call this 1, 10, 100, which if you 00:09:01.630 --> 00:09:04.350 align:middle line:90% think about it are powers of 10-- 00:09:04.350 --> 00:09:08.760 align:middle line:84% 10 to the 0 is 1; 10 to the 1 is 10; 10 to the 2 is 100-- 00:09:08.760 --> 00:09:10.840 align:middle line:90% we'll use powers of 2. 00:09:10.840 --> 00:09:14.420 align:middle line:84% So 2 to the 0 is going to give us 1 again. 00:09:14.420 --> 00:09:17.200 align:middle line:84% 2 to the 1 is going to give us 2 this time. 00:09:17.200 --> 00:09:20.800 align:middle line:84% And 2 to the 2, or 2 squared, is going to give us 4. 00:09:20.800 --> 00:09:28.050 align:middle line:84% And if we kept going, it'd be 8, 16, 32, 64, instead of 1,000, 10,000, 100,000, 00:09:28.050 --> 00:09:29.810 align:middle line:90% 1,000,000, and so forth. 00:09:29.810 --> 00:09:30.670 align:middle line:90% So same idea. 00:09:30.670 --> 00:09:33.230 align:middle line:84% Just a different base system, so to speak. 00:09:33.230 --> 00:09:37.330 align:middle line:84% Indeed, we're using now binary, because we have two letters in our alphabet, 0 00:09:37.330 --> 00:09:39.940 align:middle line:90% and 1, hence the bi prefix there. 00:09:39.940 --> 00:09:45.790 align:middle line:84% So in binary, suppose that you use, for instance, these digits here, 00:09:45.790 --> 00:09:47.800 align:middle line:90% these symbols, 000. 00:09:47.800 --> 00:09:53.020 align:middle line:84% What number is the computer storing if it's somehow thinking of 000, 00:09:53.020 --> 00:09:55.270 align:middle line:90% but in binary, not decimal? 00:09:55.270 --> 00:09:56.155 align:middle line:90% Yeah, it's just 0. 00:09:56.155 --> 00:09:57.780 align:middle line:90% The decimal number you and I know as 0. 00:09:57.780 --> 00:09:58.310 align:middle line:90% Why? 00:09:58.310 --> 00:10:02.200 align:middle line:84% Well, the super-quick math is, well, this is just 4 times 0 is 0, 00:10:02.200 --> 00:10:05.860 align:middle line:84% plus 2 times 0 is 0, plus 1 times 0 is 0. 00:10:05.860 --> 00:10:07.900 align:middle line:90% So that gets us back, of course, to 0. 00:10:07.900 --> 00:10:11.110 align:middle line:84% But in the computer, if it were instead storing a pattern of symbols that 00:10:11.110 --> 00:10:16.390 align:middle line:84% isn't 000, but maybe 001, you can probably imagine that now-- 00:10:16.390 --> 00:10:19.480 align:middle line:84% just do the quick math-- this is now the decimal number we know as 1, 00:10:19.480 --> 00:10:22.870 align:middle line:84% because it's 4 times 0, 2 times 0, but 1 times 1. 00:10:22.870 --> 00:10:27.740 align:middle line:84% Skipping ahead, you might be inclined now to represent the next number here 00:10:27.740 --> 00:10:28.240 align:middle line:90% as what? 00:10:28.240 --> 00:10:32.290 align:middle line:84% It's obviously not 002, because we don't have access to a digit 2. 00:10:32.290 --> 00:10:34.000 align:middle line:90% We only have 0s and 1s. 00:10:34.000 --> 00:10:37.570 align:middle line:84% So you might be inclined to do something like this, 11, right? 00:10:37.570 --> 00:10:40.720 align:middle line:84% Because if I'm counting to 2 on my fingers, it's 1, 2. 00:10:40.720 --> 00:10:43.270 align:middle line:84% So two hash marks on the board would seem to give me 2. 00:10:43.270 --> 00:10:44.350 align:middle line:90% But not in binary. 00:10:44.350 --> 00:10:45.640 align:middle line:90% This is unary. 00:10:45.640 --> 00:10:48.900 align:middle line:84% What do I get in binary with the pattern 011? 00:10:48.900 --> 00:10:49.400 align:middle line:90% AUDIENCE: 3. 00:10:49.400 --> 00:10:51.108 align:middle line:84% DAVID J. MALAN: Yeah, so it's actually 3. 00:10:51.108 --> 00:10:55.510 align:middle line:84% So the correct way of counting up from 0 on up in binary would be to start as we 00:10:55.510 --> 00:10:56.980 align:middle line:90% did, 000. 00:10:56.980 --> 00:10:58.870 align:middle line:90% Then we go up to 001. 00:10:58.870 --> 00:11:02.120 align:middle line:90% Then we go up to 010. 00:11:02.120 --> 00:11:04.353 align:middle line:90% Now we go up to 011. 00:11:04.353 --> 00:11:05.770 align:middle line:90% And anyone, how do you count to 4? 00:11:05.770 --> 00:11:08.620 align:middle line:90% What's the pattern of symbols then? 00:11:08.620 --> 00:11:10.280 align:middle line:90% Yeah, 100. 00:11:10.280 --> 00:11:16.870 align:middle line:84% Now skipping ahead, if we wanted to represent not 4, but rather this value, 00:11:16.870 --> 00:11:20.790 align:middle line:84% how high up can we go with just three columns? 00:11:20.790 --> 00:11:21.820 align:middle line:90% Seven, right? 00:11:21.820 --> 00:11:24.440 align:middle line:90% So it's 4 plus 2 plus 1 gives you 7. 00:11:24.440 --> 00:11:27.640 align:middle line:84% So if you wanted to represent 8, what happens next? 00:11:27.640 --> 00:11:29.140 align:middle line:90% Yeah, so you sort of carry the 1. 00:11:29.140 --> 00:11:32.060 align:middle line:84% So just like in our human world, when you go from 9 to 10, 00:11:32.060 --> 00:11:34.820 align:middle line:84% you typically carry the 1 to a new column over to the left. 00:11:34.820 --> 00:11:36.150 align:middle line:90% Exact same idea. 00:11:36.150 --> 00:11:39.590 align:middle line:84% So the number 8 in binary, so to speak, would now be this. 00:11:39.590 --> 00:11:44.670 align:middle line:84% But you need a fourth column, just like you would in our human decimal world. 00:11:44.670 --> 00:11:48.650 align:middle line:84% So what then is the mapping between these low-level ideas 00:11:48.650 --> 00:11:50.915 align:middle line:90% to actual physical computers? 00:11:50.915 --> 00:11:52.790 align:middle line:84% Well, inside of computers today, whether it's 00:11:52.790 --> 00:11:57.440 align:middle line:84% your Mac or PC or your iPhone or your Android phone, are millions, 00:11:57.440 --> 00:11:59.780 align:middle line:84% millions of things called transistors, which 00:11:59.780 --> 00:12:02.450 align:middle line:84% are tiny little switches that just turn on and off. 00:12:02.450 --> 00:12:05.240 align:middle line:84% If you've ever heard of a CPU, the central processing unit, that's 00:12:05.240 --> 00:12:08.630 align:middle line:84% the brain of the computer, or the phone these days, that just has so many 00:12:08.630 --> 00:12:11.300 align:middle line:84% of these microscopic switches that can turn things on and off. 00:12:11.300 --> 00:12:12.200 align:middle line:90% What are they doing? 00:12:12.200 --> 00:12:14.840 align:middle line:84% They're really just storing or not storing electricity. 00:12:14.840 --> 00:12:18.200 align:middle line:84% After all, what's the only thing you and I do probably at the end of the day 00:12:18.200 --> 00:12:21.560 align:middle line:84% or even in the middle of the day if we want to keep using our devices? 00:12:21.560 --> 00:12:24.130 align:middle line:84% We plug them into the wall or we plug it into a battery. 00:12:24.130 --> 00:12:27.440 align:middle line:84% So there's some low-level flow of electrons, or however that works. 00:12:27.440 --> 00:12:29.870 align:middle line:84% But generally speaking, the only physical input 00:12:29.870 --> 00:12:31.820 align:middle line:84% to your phone or your computer these days 00:12:31.820 --> 00:12:36.107 align:middle line:84% is an electrical socket or some battery in the wall or elsewhere. 00:12:36.107 --> 00:12:37.940 align:middle line:84% And that's kind of an interesting principle, 00:12:37.940 --> 00:12:41.780 align:middle line:84% because if the only input you have is there's either electricity flowing 00:12:41.780 --> 00:12:45.620 align:middle line:84% in the form of electrons or whatnot, or there's no electricity flowing, 00:12:45.620 --> 00:12:48.830 align:middle line:84% like the battery is dead or the plug isn't plugged in, well, 00:12:48.830 --> 00:12:52.625 align:middle line:84% that gives you two total states in the world, two different conditions 00:12:52.625 --> 00:12:53.750 align:middle line:90% that your device can be in. 00:12:53.750 --> 00:12:55.250 align:middle line:90% It's either plugged in or not. 00:12:55.250 --> 00:12:57.750 align:middle line:90% It's either drawing power, or it's not. 00:12:57.750 --> 00:13:02.400 align:middle line:84% And what's perfect about binary is that you have two digits, 0 and 1. 00:13:02.400 --> 00:13:04.400 align:middle line:84% That's all we have in the physical world when it 00:13:04.400 --> 00:13:06.720 align:middle line:90% comes to charging some physical device. 00:13:06.720 --> 00:13:09.410 align:middle line:84% So there's this really nice mapping between 0s and 1s 00:13:09.410 --> 00:13:13.307 align:middle line:84% and electricity or no electricity, or turning something on 00:13:13.307 --> 00:13:14.390 align:middle line:90% and turning something off. 00:13:14.390 --> 00:13:18.110 align:middle line:84% So for instance, if we use a very large transistor like this physical phone, 00:13:18.110 --> 00:13:21.110 align:middle line:84% I might say I have one switch on this phone. 00:13:21.110 --> 00:13:23.720 align:middle line:84% And indeed, I can now turn it on like this. 00:13:23.720 --> 00:13:26.300 align:middle line:84% So my phone, this physical device or switch, 00:13:26.300 --> 00:13:28.700 align:middle line:84% might now be representing the number we know as 1. 00:13:28.700 --> 00:13:32.960 align:middle line:84% And if I go ahead and turn it off, it's now representing, of course, 0. 00:13:32.960 --> 00:13:36.320 align:middle line:84% And if I grabbed a couple of more phones and sort of held them like this, 00:13:36.320 --> 00:13:39.710 align:middle line:84% you could imagine that each of these phones or, in turn, switches 00:13:39.710 --> 00:13:42.030 align:middle line:84% is just representing a column and a value. 00:13:42.030 --> 00:13:48.700 align:middle line:84% So if you give me two phones, I can count from 00 to 01 to 10 to 11. 00:13:48.700 --> 00:13:50.180 align:middle line:90% And that's 3 total. 00:13:50.180 --> 00:13:53.270 align:middle line:84% So with two phones, or two switches, I can count as high as 3. 00:13:53.270 --> 00:13:55.460 align:middle line:84% If you want me to count higher, to like 7, 00:13:55.460 --> 00:13:57.620 align:middle line:84% I'm going to need a third phone or a third switch. 00:13:57.620 --> 00:14:00.650 align:middle line:84% Or an 8, I'm going to need a fourth phone or a fourth switch. 00:14:00.650 --> 00:14:04.370 align:middle line:84% So this is what all of those transistors or switches inside of your computer 00:14:04.370 --> 00:14:07.500 align:middle line:84% are being used for, to store information. 00:14:07.500 --> 00:14:11.160 align:middle line:84% So once you have that ability to store information, 00:14:11.160 --> 00:14:14.210 align:middle line:84% you can start to represent anything that's familiar, right? 00:14:14.210 --> 00:14:16.730 align:middle line:84% With just 0s and 1s, switches that are on and off, 00:14:16.730 --> 00:14:20.090 align:middle line:84% you can represent these numbers that we think of as binary now. 00:14:20.090 --> 00:14:22.010 align:middle line:84% But you can map them, so to speak, to decimal, 00:14:22.010 --> 00:14:24.320 align:middle line:90% like the number 7 or the number 8. 00:14:24.320 --> 00:14:27.770 align:middle line:84% So how in the world, if all the phone or computer has 00:14:27.770 --> 00:14:31.910 align:middle line:84% is electricity and these switches and this ability to think in binary, 00:14:31.910 --> 00:14:33.710 align:middle line:84% how do you get to letters of the alphabet? 00:14:33.710 --> 00:14:35.002 align:middle line:90% How do you send a text message? 00:14:35.002 --> 00:14:37.460 align:middle line:84% How do you write a document, which, of course, involve 00:14:37.460 --> 00:14:40.250 align:middle line:90% alphabetical letters, not just numbers? 00:14:40.250 --> 00:14:42.440 align:middle line:90% What's the leap we now need to make? 00:14:42.440 --> 00:14:44.690 align:middle line:84% Well, we'll leverage what's called in computer science 00:14:44.690 --> 00:14:46.340 align:middle line:90% this notion of abstraction. 00:14:46.340 --> 00:14:48.200 align:middle line:84% We're not going to spend any more time in this class talking 00:14:48.200 --> 00:14:49.040 align:middle line:90% about electricity. 00:14:49.040 --> 00:14:52.290 align:middle line:84% That's sort of a very low-level detail, so to speak. 00:14:52.290 --> 00:14:56.000 align:middle line:84% In fact, we might rarely talk about binary, which conceptually 00:14:56.000 --> 00:14:59.840 align:middle line:84% is one level higher in your mind now than the electricity that 00:14:59.840 --> 00:15:00.830 align:middle line:90% flows from the wall. 00:15:00.830 --> 00:15:03.150 align:middle line:84% Who cares how the electricity works or flows? 00:15:03.150 --> 00:15:05.150 align:middle line:84% I just know that I can turn something on or off. 00:15:05.150 --> 00:15:06.800 align:middle line:90% From that, I can get binary. 00:15:06.800 --> 00:15:09.740 align:middle line:84% But if I have only have binary, I can only represent numbers. 00:15:09.740 --> 00:15:10.862 align:middle line:90% Now I want letters. 00:15:10.862 --> 00:15:12.570 align:middle line:84% So we need to now take things up a notch, 00:15:12.570 --> 00:15:15.620 align:middle line:84% so to speak, and start to use these same ingredients to represent 00:15:15.620 --> 00:15:19.510 align:middle line:84% things like the letter A. So how, whether you know this 00:15:19.510 --> 00:15:23.570 align:middle line:84% or not coming in the door, how, given only those inputs to the problem, 00:15:23.570 --> 00:15:27.260 align:middle line:84% might we think now about representing the letter A in a computer? 00:15:27.260 --> 00:15:31.670 align:middle line:84% If all that we have is binary or, in turn, switches or, in turn, 00:15:31.670 --> 00:15:33.580 align:middle line:90% electricity. 00:15:33.580 --> 00:15:34.512 align:middle line:90% What do you think? 00:15:34.512 --> 00:15:35.470 align:middle line:90% AUDIENCE: Using 8 bits. 00:15:35.470 --> 00:15:36.400 align:middle line:90% DAVID J. MALAN: Using 8 bits. 00:15:36.400 --> 00:15:38.370 align:middle line:84% So that's in the right direction, indeed. 00:15:38.370 --> 00:15:41.950 align:middle line:84% I'd probably want more than just three or four columns. 00:15:41.950 --> 00:15:43.842 align:middle line:84% And indeed, you've used the right term here. 00:15:43.842 --> 00:15:45.550 align:middle line:84% If you've ever heard the expression bits, 00:15:45.550 --> 00:15:48.940 align:middle line:84% that just stands for binary digits, condensed into one word. 00:15:48.940 --> 00:15:51.338 align:middle line:84% And so these indeed represent bits, a 0 and 1. 00:15:51.338 --> 00:15:53.380 align:middle line:84% OK, so yeah, we're going to need a few more bits. 00:15:53.380 --> 00:15:55.090 align:middle line:90% But how do we get to the letter A? 00:15:55.090 --> 00:15:56.530 align:middle line:90% How do we build up conceptually? 00:15:56.530 --> 00:15:57.280 align:middle line:90% How about in back? 00:15:57.280 --> 00:16:01.510 align:middle line:84% AUDIENCE: [INAUDIBLE] ascribe a value to A. 00:16:01.510 --> 00:16:04.173 align:middle line:84% And then isn't that like the alphabet model? 00:16:04.173 --> 00:16:06.090 align:middle line:84% DAVID J. MALAN: Yeah, I mean, that's literally 00:16:06.090 --> 00:16:09.210 align:middle line:84% all we can do is to-- all we have is the ability to store numbers. 00:16:09.210 --> 00:16:11.095 align:middle line:84% We humans just need to decide, you know what? 00:16:11.095 --> 00:16:14.220 align:middle line:84% In the context of a text message or the context of Google Docs or Microsoft 00:16:14.220 --> 00:16:15.210 align:middle line:90% Word, you know what? 00:16:15.210 --> 00:16:18.210 align:middle line:84% When you see a certain pattern of bits, don't display it as a number. 00:16:18.210 --> 00:16:19.920 align:middle line:90% Display it as a letter instead. 00:16:19.920 --> 00:16:24.210 align:middle line:84% So we might go super simple and say A is 1, and B is 2, and C is 3, 00:16:24.210 --> 00:16:25.118 align:middle line:90% and so forth. 00:16:25.118 --> 00:16:27.660 align:middle line:84% Well, humans decided not to use quite that mapping years ago. 00:16:27.660 --> 00:16:30.630 align:middle line:84% It turns out that the capital letter A in your phone or computer 00:16:30.630 --> 00:16:34.540 align:middle line:84% is actually stored using the number 65 in decimal. 00:16:34.540 --> 00:16:37.020 align:middle line:84% So the pattern of bits that gives you the number 65 00:16:37.020 --> 00:16:39.270 align:middle line:84% is what your phone or computer is storing 00:16:39.270 --> 00:16:42.060 align:middle line:90% if you want to represent the number 65. 00:16:42.060 --> 00:16:45.690 align:middle line:84% And humans came up with mappings for B and C and D and other letters as well. 00:16:45.690 --> 00:16:48.480 align:middle line:84% And they called this mapping ASCII, the American Standard 00:16:48.480 --> 00:16:49.938 align:middle line:90% Code for Information Interchange. 00:16:49.938 --> 00:16:52.980 align:middle line:84% Not interesting what the acronym stands for, but that it's indeed exactly 00:16:52.980 --> 00:16:56.620 align:middle line:84% as you described, a mapping between numbers and letters. 00:16:56.620 --> 00:16:58.470 align:middle line:84% So if we take this a little further, here's 00:16:58.470 --> 00:16:59.960 align:middle line:90% where the mapping goes thereafter. 00:16:59.960 --> 00:17:01.500 align:middle line:90% B is 66, it turns out. 00:17:01.500 --> 00:17:04.270 align:middle line:90% C is 67, and so forth. 00:17:04.270 --> 00:17:08.010 align:middle line:84% And so if right now you were to receive a message from a friend that 00:17:08.010 --> 00:17:11.550 align:middle line:84% happened to be implemented using 0s and 1s, 00:17:11.550 --> 00:17:14.099 align:middle line:84% and those 0s and 1s that you just received wirelessly 00:17:14.099 --> 00:17:21.750 align:middle line:84% somehow were representing the numbers, say, how about 72, 73, 33, what message 00:17:21.750 --> 00:17:24.600 align:middle line:90% did your friend just send you? 00:17:24.600 --> 00:17:27.180 align:middle line:90% If they sent you 72, 73, or 33. 00:17:27.180 --> 00:17:28.310 align:middle line:90% AUDIENCE: It's HI. 00:17:28.310 --> 00:17:28.820 align:middle line:90% DAVID J. MALAN: Say again. 00:17:28.820 --> 00:17:29.320 align:middle line:90% HI. 00:17:29.320 --> 00:17:32.717 align:middle line:84% And then that's H-I. What might the third one be? 00:17:32.717 --> 00:17:33.880 align:middle line:90% AUDIENCE: Exclamation. 00:17:33.880 --> 00:17:34.990 align:middle line:84% DAVID J. MALAN: Yeah, you would only have to-- 00:17:34.990 --> 00:17:36.580 align:middle line:84% you would only guess this unless you knew coming 00:17:36.580 --> 00:17:38.380 align:middle line:90% in it's indeed an exclamation point. 00:17:38.380 --> 00:17:41.742 align:middle line:90% Because H-I is 72, 73 exclamation point. 00:17:41.742 --> 00:17:44.200 align:middle line:84% If we actually looked beyond the dot, dot, dot on my slide, 00:17:44.200 --> 00:17:46.180 align:middle line:84% we would see that 33 is among those values. 00:17:46.180 --> 00:17:49.540 align:middle line:84% And indeed, that is how a computer represents an exclamation point. 00:17:49.540 --> 00:17:52.570 align:middle line:84% You receive either via wire from your desktop computer 00:17:52.570 --> 00:17:54.790 align:middle line:84% or wirelessly on your phone or laptop a pattern 00:17:54.790 --> 00:17:59.680 align:middle line:84% of 0's and 1's that represents the number, 33 in this case. 00:17:59.680 --> 00:18:03.640 align:middle line:84% And underneath the hood, really then, it's just some pattern of bits. 00:18:03.640 --> 00:18:06.540 align:middle line:84% It might be represented using light bulbs, sort of old school style. 00:18:06.540 --> 00:18:10.330 align:middle line:84% It might be represented using hash marks on the screen or 0's and 1's that you 00:18:10.330 --> 00:18:11.020 align:middle line:90% might draw. 00:18:11.020 --> 00:18:14.440 align:middle line:84% We can all just agree that there's probably a way to represent 0's and 1's 00:18:14.440 --> 00:18:16.055 align:middle line:90% by just turning things on and off. 00:18:16.055 --> 00:18:18.430 align:middle line:84% Now we can kind of think at a higher level of abstraction 00:18:18.430 --> 00:18:21.670 align:middle line:84% from the electricity down here, binary here, 00:18:21.670 --> 00:18:25.673 align:middle line:84% and now this thing called ASCII, which is one level conceptually above it. 00:18:25.673 --> 00:18:28.090 align:middle line:84% And indeed that's where we get this notion of abstraction. 00:18:28.090 --> 00:18:30.460 align:middle line:84% You have a low level detail, that frankly is not 00:18:30.460 --> 00:18:32.387 align:middle line:84% really all that interesting to a lot of us. 00:18:32.387 --> 00:18:33.720 align:middle line:90% Who cares how electricity works? 00:18:33.720 --> 00:18:35.440 align:middle line:90% We just care that it does work. 00:18:35.440 --> 00:18:38.740 align:middle line:84% But if you stipulate that it does, now you can represent decimal numbers. 00:18:38.740 --> 00:18:40.870 align:middle line:84% And then we can all agree to have some mapping 00:18:40.870 --> 00:18:43.630 align:middle line:90% as you propose to letters as well. 00:18:43.630 --> 00:18:47.590 align:middle line:84% So two fundamental ideas so far, representation and abstraction, 00:18:47.590 --> 00:18:49.330 align:middle line:90% that give us the more familiar. 00:18:49.330 --> 00:18:52.360 align:middle line:84% But what about any of the other symbols that we all use, right? 00:18:52.360 --> 00:18:54.760 align:middle line:84% American Standard Code for Information Interchange 00:18:54.760 --> 00:18:57.460 align:middle line:84% is itself a little biased toward American English. 00:18:57.460 --> 00:18:59.290 align:middle line:84% And indeed, that's what happened early on. 00:18:59.290 --> 00:19:04.542 align:middle line:84% There were only 128 and then eventually 256 possible characters 00:19:04.542 --> 00:19:07.000 align:middle line:84% that you could represent in a computer, which was generally 00:19:07.000 --> 00:19:10.810 align:middle line:84% biased to A through Z, capital and uppercase, some letter, some numbers, 00:19:10.810 --> 00:19:12.250 align:middle line:90% and some punctuation as well. 00:19:12.250 --> 00:19:14.950 align:middle line:84% But there's a lot more symbols in other languages that 00:19:14.950 --> 00:19:17.050 align:middle line:84% aren't represented on a typical keyboard, 00:19:17.050 --> 00:19:19.840 align:middle line:84% for instance any accented character, and Asian languages having 00:19:19.840 --> 00:19:21.220 align:middle line:90% a whole symbology as well. 00:19:21.220 --> 00:19:26.380 align:middle line:84% There's a lot more characters in the world than 128 or 256, certainly. 00:19:26.380 --> 00:19:27.890 align:middle line:90% So how do we get there? 00:19:27.890 --> 00:19:30.003 align:middle line:84% Well, the world came up with, indeed, yet 00:19:30.003 --> 00:19:32.920 align:middle line:84% other characters that you're familiar with as well, not to mention all 00:19:32.920 --> 00:19:36.340 align:middle line:84% of these guys which you probably use pretty incessantly these days. 00:19:36.340 --> 00:19:38.450 align:middle line:84% Those are just characters on the keyboard. 00:19:38.450 --> 00:19:40.513 align:middle line:84% They don't look like letters in any language. 00:19:40.513 --> 00:19:42.430 align:middle line:84% They look like a little comic book characters. 00:19:42.430 --> 00:19:47.800 align:middle line:84% These emojis are actually just a mapping from numbers to letters, as well. 00:19:47.800 --> 00:19:50.200 align:middle line:84% And that is thanks to something called Unicode. 00:19:50.200 --> 00:19:54.760 align:middle line:84% So years after ASCII was decided by a whole bunch of folks decades ago, 00:19:54.760 --> 00:19:58.240 align:middle line:84% Unicode was developed to not use a total as you proposed 8 bits, 00:19:58.240 --> 00:20:01.930 align:middle line:84% but Unicode allows you to use maybe 16 bits or 24 bits 00:20:01.930 --> 00:20:06.220 align:middle line:84% or even 32 bits, which means the more columns you have, the way bigger 00:20:06.220 --> 00:20:10.000 align:middle line:84% numbers you can represent, because you keep having more and more and more 00:20:10.000 --> 00:20:11.410 align:middle line:90% columns or places. 00:20:11.410 --> 00:20:15.290 align:middle line:84% So Unicode allows you way more than the original value. 00:20:15.290 --> 00:20:17.770 align:middle line:84% So for instance as of this year, we double checked, 00:20:17.770 --> 00:20:21.200 align:middle line:84% this is the most popular emoji still in use to this day. 00:20:21.200 --> 00:20:23.500 align:middle line:90% This is the face with tears of joy. 00:20:23.500 --> 00:20:25.000 align:middle line:90% They all have names, as well. 00:20:25.000 --> 00:20:27.580 align:middle line:84% Anyone want to hazard a guess as to what number this is? 00:20:27.580 --> 00:20:28.870 align:middle line:90% It's not 65. 00:20:28.870 --> 00:20:31.270 align:middle line:90% It's not 66, not 72, 73, 33. 00:20:31.270 --> 00:20:32.440 align:middle line:90% We've seen those. 00:20:32.440 --> 00:20:33.347 align:middle line:90% AUDIENCE: 100. 00:20:33.347 --> 00:20:34.180 align:middle line:90% DAVID J. MALAN: 100. 00:20:34.180 --> 00:20:34.680 align:middle line:90% Higher. 00:20:34.680 --> 00:20:35.543 align:middle line:90% AUDIENCE: 1,000. 00:20:35.543 --> 00:20:36.460 align:middle line:90% DAVID J. MALAN: 1,000. 00:20:36.460 --> 00:20:37.060 align:middle line:90% Higher. 00:20:37.060 --> 00:20:38.430 align:middle line:90% AUDIENCE: Billions. 00:20:38.430 --> 00:20:41.260 align:middle line:90% DAVID J. MALAN: A billion is too high. 00:20:41.260 --> 00:20:46.120 align:middle line:90% It is 128,514, completely arbitrary. 00:20:46.120 --> 00:20:49.150 align:middle line:84% But we humans, unbeknownst to us, have agreed 00:20:49.150 --> 00:20:53.470 align:middle line:84% that this number shall be displayed as a picture of a smiling face, that's 00:20:53.470 --> 00:20:57.430 align:middle line:84% smiling so much that it has tears of joy in its eyes. 00:20:57.430 --> 00:21:01.280 align:middle line:84% And every other emoji you've ever sent, similarly has a mapping as well. 00:21:01.280 --> 00:21:03.880 align:middle line:84% But if you really want to take the fun out of emojis, 00:21:03.880 --> 00:21:05.890 align:middle line:84% next time you send an emoji to a friend, this 00:21:05.890 --> 00:21:08.050 align:middle line:84% is literally what you're sending to your friend. 00:21:08.050 --> 00:21:11.470 align:middle line:84% Some esoteric pattern of 0's and 1's that their phone is just 00:21:11.470 --> 00:21:15.310 align:middle line:84% displaying in a more interesting way using a font of sorts 00:21:15.310 --> 00:21:17.725 align:middle line:90% to interpret those bits. 00:21:17.725 --> 00:21:20.350 align:middle line:84% All right, so that was a whirlwind tour so far from electricity 00:21:20.350 --> 00:21:21.280 align:middle line:90% on up to emojis. 00:21:21.280 --> 00:21:24.690 align:middle line:90% Any questions so far? 00:21:24.690 --> 00:21:26.382 align:middle line:90% Yeah. 00:21:26.382 --> 00:21:29.840 align:middle line:84% AUDIENCE: How does syntax work in terms of, like, when we have words, 00:21:29.840 --> 00:21:34.286 align:middle line:84% we have spaces in between them so we know when one starts and the next ends. 00:21:34.286 --> 00:21:37.250 align:middle line:90% But on a computer, do you have-- 00:21:37.250 --> 00:21:40.708 align:middle line:84% is it just a long sequence of 1s and 0s and switches. 00:21:40.708 --> 00:21:42.778 align:middle line:90% How does the computer know when to stop? 00:21:42.778 --> 00:21:44.320 align:middle line:90% DAVID J. MALAN: Really good question. 00:21:44.320 --> 00:21:47.320 align:middle line:84% So in simplest form, if you go way back into time when you had those old 00:21:47.320 --> 00:21:49.957 align:middle line:84% big monitors called CRT or Cathode Ray Tubes 00:21:49.957 --> 00:21:53.040 align:middle line:84% where you could actually see the dots composing the letters on the screen. 00:21:53.040 --> 00:21:55.498 align:middle line:84% If you have a childhood calculator, that's kind of similar. 00:21:55.498 --> 00:21:58.800 align:middle line:84% The little LED show you really the physical representation 00:21:58.800 --> 00:21:59.760 align:middle line:90% of those values. 00:21:59.760 --> 00:22:02.177 align:middle line:84% When you don't have fonts, everything is just fixed width, 00:22:02.177 --> 00:22:03.968 align:middle line:84% like someone built a piece of hardware that 00:22:03.968 --> 00:22:07.230 align:middle line:84% will display the first character here, the next character here, and so forth. 00:22:07.230 --> 00:22:09.390 align:middle line:84% And typewriters in yesteryear did exactly that. 00:22:09.390 --> 00:22:11.160 align:middle line:90% There was no proportionality. 00:22:11.160 --> 00:22:13.770 align:middle line:84% There was no kerning, so to speak, between characters. 00:22:13.770 --> 00:22:16.170 align:middle line:84% But once you have fancier Macs and PCs and phones 00:22:16.170 --> 00:22:18.090 align:middle line:84% these days were born for the notion of fonts. 00:22:18.090 --> 00:22:21.150 align:middle line:84% And Apple years ago really spearheaded this, especially. 00:22:21.150 --> 00:22:24.480 align:middle line:84% So there are other 0's and 1's in any word document 00:22:24.480 --> 00:22:28.320 align:middle line:84% or any Google document that you use that are storing other patterns of bits that 00:22:28.320 --> 00:22:30.840 align:middle line:84% essentially tell the MAC, PC or phone what font 00:22:30.840 --> 00:22:32.880 align:middle line:90% to use to display those characters. 00:22:32.880 --> 00:22:35.880 align:middle line:84% And these days-- and we'll talk about this actually in just one moment-- 00:22:35.880 --> 00:22:40.440 align:middle line:84% your screen is just this amazing canvas of like millions of dots called pixels. 00:22:40.440 --> 00:22:43.023 align:middle line:84% And these fonts can sort of use those pixels in different way. 00:22:43.023 --> 00:22:44.648 align:middle line:90% And sometimes they'll be more squished. 00:22:44.648 --> 00:22:45.970 align:middle line:90% Sometimes they'll be wider. 00:22:45.970 --> 00:22:47.310 align:middle line:90% But it's more 0's and 1's. 00:22:47.310 --> 00:22:50.770 align:middle line:84% And humans just needed to decide, Apple and Microsoft and elsewhere, 00:22:50.770 --> 00:22:55.200 align:middle line:84% what patterns of bits represent Times New Roman or Comic 00:22:55.200 --> 00:22:58.990 align:middle line:90% Sans or some other such fonts as well. 00:22:58.990 --> 00:23:03.060 align:middle line:84% All right, so suffice it to say that in a smiley face like face 00:23:03.060 --> 00:23:05.587 align:middle line:84% with tears of joy, there's a lot of yellow dots 00:23:05.587 --> 00:23:07.170 align:middle line:90% or it would seem or just yellow color. 00:23:07.170 --> 00:23:09.725 align:middle line:84% And indeed that dot is generally known as a pixel. 00:23:09.725 --> 00:23:12.350 align:middle line:84% Well a pixel is sort of another thing that-- well, the computer 00:23:12.350 --> 00:23:13.770 align:middle line:90% has got to represent it somehow. 00:23:13.770 --> 00:23:17.400 align:middle line:84% After all how does the computer know to show me yellow or green or blue 00:23:17.400 --> 00:23:18.570 align:middle line:90% or anything else? 00:23:18.570 --> 00:23:20.757 align:middle line:90% Well, it reduces to pixels, as well. 00:23:20.757 --> 00:23:23.340 align:middle line:84% You might have heard this acronym in some context in the past. 00:23:23.340 --> 00:23:24.835 align:middle line:90% RGB stands for? 00:23:24.835 --> 00:23:25.960 align:middle line:90% AUDIENCE: Red, green, blue. 00:23:25.960 --> 00:23:27.120 align:middle line:90% DAVID J. MALAN: Yeah, red, green blue. 00:23:27.120 --> 00:23:29.370 align:middle line:84% And if you hadn't heard that before, it's no big deal. 00:23:29.370 --> 00:23:31.920 align:middle line:84% It just describes a common convention for computers 00:23:31.920 --> 00:23:34.080 align:middle line:90% to store any color of the rainbow. 00:23:34.080 --> 00:23:37.490 align:middle line:84% They breakdown every color you can think of into some amount of red, 00:23:37.490 --> 00:23:39.240 align:middle line:84% some amount of green, some amount of blue, 00:23:39.240 --> 00:23:43.170 align:middle line:84% that if you overlap those three shades, you get the color that you want, 00:23:43.170 --> 00:23:44.820 align:middle line:90% for instance something like yellow. 00:23:44.820 --> 00:23:47.220 align:middle line:84% So for instance, if we consider this picture here, 00:23:47.220 --> 00:23:50.880 align:middle line:84% this is three pixels side by side or really RGB, a triple 00:23:50.880 --> 00:23:54.150 align:middle line:84% if you will, three different values of sorts. 00:23:54.150 --> 00:23:55.170 align:middle line:90% So red comes first. 00:23:55.170 --> 00:23:56.460 align:middle line:90% Green comes second. 00:23:56.460 --> 00:23:57.700 align:middle line:90% And blue comes next. 00:23:57.700 --> 00:24:01.170 align:middle line:84% So really underneath the hood, suppose that your computer were storing 00:24:01.170 --> 00:24:04.920 align:middle line:84% the same numbers as before, 72, 73, 33, but now it's 00:24:04.920 --> 00:24:08.430 align:middle line:84% in the context of Photoshop or a browser or some program that's 00:24:08.430 --> 00:24:10.740 align:middle line:90% designed to show graphics and not text. 00:24:10.740 --> 00:24:13.140 align:middle line:84% Well, the computer will interpret potentially 00:24:13.140 --> 00:24:17.430 align:middle line:84% that same pattern of 0's and 1's in just a different way. 00:24:17.430 --> 00:24:20.550 align:middle line:84% Rather than display them as text, like HI! 00:24:20.550 --> 00:24:24.690 align:middle line:84% H-I exclamation point, it'll display it as the combination of these three 00:24:24.690 --> 00:24:25.440 align:middle line:90% colors. 00:24:25.440 --> 00:24:28.800 align:middle line:84% So you'll take some amount of red, some amount of green, some amount of blue. 00:24:28.800 --> 00:24:32.310 align:middle line:84% And it looks like a good amount of red, a good amount of green, and less blue, 00:24:32.310 --> 00:24:35.880 align:middle line:84% just based on those numbers 72, 73, and then less, 33. 00:24:35.880 --> 00:24:43.990 align:middle line:84% And if you actually combine those with each other, what you'll ultimately get 00:24:43.990 --> 00:24:47.980 align:middle line:84% is, if we merge them together, that same shade of yellow. 00:24:47.980 --> 00:24:50.530 align:middle line:84% Now let me stipulate for the moment that each 00:24:50.530 --> 00:24:53.380 align:middle line:84% of those values of red and green and blue by human convention 00:24:53.380 --> 00:24:54.940 align:middle line:90% tend to use 8 bits. 00:24:54.940 --> 00:24:58.900 align:middle line:84% So with 8 bits, anyone want to guess how high you can count 00:24:58.900 --> 00:25:00.520 align:middle line:90% if you have 8 columns on the board? 00:25:00.520 --> 00:25:01.532 align:middle line:90% AUDIENCE: [INAUDIBLE] 00:25:01.532 --> 00:25:03.740 align:middle line:84% DAVID J. MALAN: Yeah, you have to do some quick math. 00:25:03.740 --> 00:25:08.017 align:middle line:84% But if you literally went 1, 2, 3, 4, 5, 6, 7, 8, this is the 1's place. 00:25:08.017 --> 00:25:10.100 align:middle line:84% This is the 2's place, the 4's place and so forth. 00:25:10.100 --> 00:25:13.130 align:middle line:84% If you do that math, you can count as high as 255 00:25:13.130 --> 00:25:17.400 align:middle line:90% using 8 total bits or 8 total columns. 00:25:17.400 --> 00:25:18.990 align:middle line:90% This is very common unit of measure. 00:25:18.990 --> 00:25:22.250 align:middle line:84% And it's one of those things eventually that will just become second nature, 00:25:22.250 --> 00:25:23.750 align:middle line:90% because it's used in so many places. 00:25:23.750 --> 00:25:25.280 align:middle line:90% And indeed it's used in colors. 00:25:25.280 --> 00:25:29.330 align:middle line:84% The computers of today typically use 8 bits, eight 0's and 1's to represent 00:25:29.330 --> 00:25:32.180 align:middle line:84% how much red you want for every dot on the screen, 8 more bits 00:25:32.180 --> 00:25:34.820 align:middle line:84% to represent how much green you want on the screen, 8 more bits 00:25:34.820 --> 00:25:36.110 align:middle line:90% to represent how much blue. 00:25:36.110 --> 00:25:40.200 align:middle line:84% So they spend 24 bits total to represent how much red, how much green, 00:25:40.200 --> 00:25:42.890 align:middle line:84% how much blue each dot on your screen should be and then 00:25:42.890 --> 00:25:48.270 align:middle line:84% display the resulting value as it might be here with this yellow dot. 00:25:48.270 --> 00:25:50.658 align:middle line:84% But the only thing that's changed is the context 00:25:50.658 --> 00:25:53.450 align:middle line:84% in which those bits are interpreted, not a word processing program. 00:25:53.450 --> 00:25:57.240 align:middle line:84% But like a graphics program, it still reduces to 0's and 1's. 00:25:57.240 --> 00:25:59.810 align:middle line:84% And you can see these pixels or dots, right. 00:25:59.810 --> 00:26:01.920 align:middle line:90% This is that same emoji as before. 00:26:01.920 --> 00:26:06.290 align:middle line:84% And if I start to zoom in on this, you start to notice a pattern. 00:26:06.290 --> 00:26:10.610 align:middle line:84% And indeed that like lovely shade of yellow and the black eyes and so forth 00:26:10.610 --> 00:26:13.820 align:middle line:84% are actually just a whole bunch of dots that when you look at it normally, 00:26:13.820 --> 00:26:16.610 align:middle line:84% they're so small you don't realize that it's a very jagged image. 00:26:16.610 --> 00:26:19.010 align:middle line:84% But if you zoom in on it quite a bit, you actually 00:26:19.010 --> 00:26:21.623 align:middle line:90% start to see the pixels on the screen. 00:26:21.623 --> 00:26:24.290 align:middle line:84% And you can kind of do this, not so much with phones these days, 00:26:24.290 --> 00:26:26.510 align:middle line:84% if you've ever heard of retina displays and the fancy things 00:26:26.510 --> 00:26:28.730 align:middle line:84% that Android phones and iPhones have, your human eyes 00:26:28.730 --> 00:26:30.710 align:middle line:90% can't really even see the dots anymore. 00:26:30.710 --> 00:26:33.560 align:middle line:84% But if you go home to your TV or look at an older TV, 00:26:33.560 --> 00:26:37.470 align:middle line:84% especially and get way too close to be comfortable watching it, 00:26:37.470 --> 00:26:39.530 align:middle line:84% you'll actually see these same dots as well. 00:26:39.530 --> 00:26:42.620 align:middle line:84% And that just means every one of the yellow or black or gray dots 00:26:42.620 --> 00:26:47.370 align:middle line:84% on the screen is being represented by this Mac or PC using 24 bits. 00:26:47.370 --> 00:26:49.520 align:middle line:84% So the top left hand corner, that's 24 bits. 00:26:49.520 --> 00:26:53.400 align:middle line:84% The next dot over is 24 more bits, 24 more bits, and so forth. 00:26:53.400 --> 00:26:56.300 align:middle line:84% So if now you've ever taken a photo and you've stored 00:26:56.300 --> 00:27:00.170 align:middle line:84% the file like a JPEG on your computer and it takes up 1 megabyte. 00:27:00.170 --> 00:27:02.990 align:middle line:90% One megabyte means one million bits-- 00:27:02.990 --> 00:27:05.360 align:middle line:90% 1 million bytes. 00:27:05.360 --> 00:27:06.800 align:middle line:90% And a byte anyone know? 00:27:06.800 --> 00:27:07.730 align:middle line:90% AUDIENCE: 8 bits. 00:27:07.730 --> 00:27:08.930 align:middle line:90% DAVID J. MALAN: It's just 8 bits, right? 00:27:08.930 --> 00:27:10.540 align:middle line:90% One bit is pretty useless, right. 00:27:10.540 --> 00:27:11.990 align:middle line:90% You can only count to 1. 00:27:11.990 --> 00:27:15.210 align:middle line:84% But 8 bits, you can count, we just said, to 255. 00:27:15.210 --> 00:27:17.450 align:middle line:84% So most people in the world talk about bytes. 00:27:17.450 --> 00:27:19.680 align:middle line:84% One megabyte just means one million bytes. 00:27:19.680 --> 00:27:22.580 align:middle line:90% So that's a lot more 0's and 1's. 00:27:22.580 --> 00:27:27.140 align:middle line:84% So once you have a file on your hard drive storing an image, 00:27:27.140 --> 00:27:29.810 align:middle line:84% the bigger the photo is, the bigger the file is going to be. 00:27:29.810 --> 00:27:32.660 align:middle line:84% Or the higher the resolution is, the more dots your photos have, 00:27:32.660 --> 00:27:33.770 align:middle line:90% the bigger the file is going to be. 00:27:33.770 --> 00:27:34.280 align:middle line:90% Why? 00:27:34.280 --> 00:27:36.350 align:middle line:84% Well, because for every one of those dots we-- 00:27:36.350 --> 00:27:39.740 align:middle line:84% at the risk of oversimplifying-- you have to store another 24 bits, 24 00:27:39.740 --> 00:27:42.360 align:middle line:90% bits, 24 bits, 24 bits, and so forth. 00:27:42.360 --> 00:27:45.140 align:middle line:84% So the bigger the image, the more disk space it's going to take up 00:27:45.140 --> 00:27:48.590 align:middle line:84% and the fewer files you can even store, therefore, on your Mac or PC. 00:27:48.590 --> 00:27:51.560 align:middle line:84% This is why, ultimately, you run out of space. 00:27:51.560 --> 00:27:53.000 align:middle line:90% Now I borrowed this from online. 00:27:53.000 --> 00:27:56.190 align:middle line:84% We'll see if it sort of remains a thing this year as well. 00:27:56.190 --> 00:27:59.600 align:middle line:84% But you might have noticed quite a few GIFs, Graphical Interchange 00:27:59.600 --> 00:28:03.297 align:middle line:84% Formats being posted to this Facebook and certainly many others online. 00:28:03.297 --> 00:28:06.380 align:middle line:84% You might have noticed that some of those graphics are sometimes animated. 00:28:06.380 --> 00:28:07.370 align:middle line:90% They literally say GIF. 00:28:07.370 --> 00:28:09.740 align:middle line:84% And if you click on it, something sort of happens. 00:28:09.740 --> 00:28:13.040 align:middle line:84% And sometimes you can upload videos, certainly to sites like Facebook 00:28:13.040 --> 00:28:14.510 align:middle line:90% as well, and hit a play icon. 00:28:14.510 --> 00:28:15.923 align:middle line:90% And then that plays as well. 00:28:15.923 --> 00:28:18.090 align:middle line:84% Well, how does that fit into this sort of hierarchy? 00:28:18.090 --> 00:28:21.170 align:middle line:84% Well, again, we started with electricity, 0's and 1's, then 00:28:21.170 --> 00:28:22.190 align:middle line:90% we had letters. 00:28:22.190 --> 00:28:24.980 align:middle line:84% But instead, if you don't interpret those 0's and 1's as letters, 00:28:24.980 --> 00:28:28.310 align:middle line:84% but sort of conceptually think about them now as colors, you have images. 00:28:28.310 --> 00:28:31.160 align:middle line:84% That's all an image is, a bunch of dots or pixels. 00:28:31.160 --> 00:28:32.870 align:middle line:90% Well, what is an animated GIF? 00:28:32.870 --> 00:28:34.700 align:middle line:84% If you've ever seen some meme going around 00:28:34.700 --> 00:28:38.312 align:middle line:84% where there is sort of an animation, it's just image, image, image, image. 00:28:38.312 --> 00:28:40.520 align:middle line:84% And sometimes it loops-- image, image, image, image-- 00:28:40.520 --> 00:28:42.650 align:middle line:90% and it creates the illusion of motion. 00:28:42.650 --> 00:28:44.900 align:middle line:84% If you were a kid and ever had one of those flip books 00:28:44.900 --> 00:28:47.870 align:middle line:84% with like hundreds of pages of like cartoon drawings, 00:28:47.870 --> 00:28:51.770 align:middle line:84% and you flip it really fast, that's just creating the illusion of a video 00:28:51.770 --> 00:28:54.290 align:middle line:84% by showing you lots of frames per second. 00:28:54.290 --> 00:28:55.970 align:middle line:90% And that's all the video is. 00:28:55.970 --> 00:28:58.430 align:middle line:84% Once we agree that, yeah, I can store images 00:28:58.430 --> 00:29:00.740 align:middle line:84% because this is just a bunch of pixels, each of which 00:29:00.740 --> 00:29:04.610 align:middle line:84% is interpreted left to right as red, green, blue, red, green, blue, how 00:29:04.610 --> 00:29:06.530 align:middle line:90% much color I want for each dot. 00:29:06.530 --> 00:29:09.470 align:middle line:84% Well, then all you need to do is store more of those pixels 00:29:09.470 --> 00:29:13.250 align:middle line:84% to represent the second frame of a movie, the third frame of a movie. 00:29:13.250 --> 00:29:15.320 align:middle line:84% And in our human world in Hollywood most movies 00:29:15.320 --> 00:29:18.830 align:middle line:84% are 24 frames per second or 30 frames per second. 00:29:18.830 --> 00:29:21.830 align:middle line:84% That just means when you're watching a video or even an animated GIF, 00:29:21.830 --> 00:29:25.220 align:middle line:84% you're watching dozens of images fly by your eyes 00:29:25.220 --> 00:29:28.760 align:middle line:84% every second creating the illusion, therefore, of motion. 00:29:28.760 --> 00:29:30.502 align:middle line:90% And that's all a video file is. 00:29:30.502 --> 00:29:32.210 align:middle line:84% And so here too, you can take the fun out 00:29:32.210 --> 00:29:34.940 align:middle line:84% of clicking on any of the means online because you're just 00:29:34.940 --> 00:29:39.320 align:middle line:84% looking at bits and bits and bits flying across the screen in some pattern. 00:29:39.320 --> 00:29:41.780 align:middle line:84% Musically as well, if you've ever played a tune 00:29:41.780 --> 00:29:44.210 align:middle line:84% on a keyboard or some other device, well, we 00:29:44.210 --> 00:29:47.000 align:middle line:84% could think about how we can represent sounds as well, right. 00:29:47.000 --> 00:29:49.640 align:middle line:90% These are musical notes, so to speak. 00:29:49.640 --> 00:29:52.160 align:middle line:84% And each of those notes might be played on, for instance, 00:29:52.160 --> 00:29:54.390 align:middle line:90% a piano for some unit of time. 00:29:54.390 --> 00:29:57.180 align:middle line:84% So maybe one second per note or much faster than that. 00:29:57.180 --> 00:30:00.650 align:middle line:84% So you could imagine maybe storing with 0's and 1's the note 00:30:00.650 --> 00:30:05.140 align:middle line:84% you want to represent, maybe A or B or C or D, E, F, G, the amount of time 00:30:05.140 --> 00:30:06.640 align:middle line:90% that you want to play that note for. 00:30:06.640 --> 00:30:09.140 align:middle line:84% Maybe it's a split set and maybe it's a quarter of a second, 00:30:09.140 --> 00:30:10.760 align:middle line:90% maybe it's a full second or the like. 00:30:10.760 --> 00:30:12.370 align:middle line:84% And if you really want to get fancy, we can maybe 00:30:12.370 --> 00:30:14.110 align:middle line:84% store a third value, how loud do you want 00:30:14.110 --> 00:30:16.400 align:middle line:90% that note to be at some moment in time. 00:30:16.400 --> 00:30:21.922 align:middle line:84% And if you just imagine now these triples, note and duration and volume 00:30:21.922 --> 00:30:24.880 align:middle line:84% and just keep doing note, duration, volume, note, duration, volume, now 00:30:24.880 --> 00:30:28.810 align:middle line:84% you have a whole musical staff that can be played audibly so 00:30:28.810 --> 00:30:30.580 align:middle line:90% long as you have speakers as well. 00:30:30.580 --> 00:30:35.050 align:middle line:84% So it's just using these bits in different patterns in different ways. 00:30:35.050 --> 00:30:37.870 align:middle line:84% So that's how we might represent inputs and outputs. 00:30:37.870 --> 00:30:40.840 align:middle line:84% When you save a file on Microsoft Word or Adobe Photoshop, 00:30:40.840 --> 00:30:44.200 align:middle line:84% you're creating an output by saving these patterns of 0's and 1's 00:30:44.200 --> 00:30:47.100 align:middle line:90% to your computer's, say, hard drive. 00:30:47.100 --> 00:30:49.630 align:middle line:84% All right, so that gives us inputs and outputs. 00:30:49.630 --> 00:30:52.450 align:middle line:84% But what's inside of the so called black box? 00:30:52.450 --> 00:30:55.432 align:middle line:84% This really is where computer science now comes into play. 00:30:55.432 --> 00:30:56.890 align:middle line:90% These are things called algorithms. 00:30:56.890 --> 00:31:01.377 align:middle line:84% And in your own understanding now what is an algorithm if you could? 00:31:01.377 --> 00:31:02.210 align:middle line:90% What's an algorithm? 00:31:02.210 --> 00:31:03.910 align:middle line:90% Let me go a little farther back. 00:31:03.910 --> 00:31:04.660 align:middle line:90% Yeah, in the back. 00:31:04.660 --> 00:31:05.540 align:middle line:90% AUDIENCE: Instruction. 00:31:05.540 --> 00:31:07.998 align:middle line:84% DAVID J. MALAN: An instruction to do something, presumably. 00:31:07.998 --> 00:31:09.790 align:middle line:90% Other perspectives? 00:31:09.790 --> 00:31:12.160 align:middle line:84% And algorithm is an instruction, something else? 00:31:12.160 --> 00:31:12.679 align:middle line:90% Yeah. 00:31:12.679 --> 00:31:13.804 align:middle line:90% AUDIENCE: A path to follow. 00:31:13.804 --> 00:31:15.179 align:middle line:90% DAVID J. MALAN: A path to follow. 00:31:15.179 --> 00:31:16.720 align:middle line:90% So a logical path to follow, yeah. 00:31:16.720 --> 00:31:17.928 align:middle line:90% And let me combine those two. 00:31:17.928 --> 00:31:20.980 align:middle line:84% It's really like step by step instructions for, shall we say, 00:31:20.980 --> 00:31:22.240 align:middle line:90% solving a problem. 00:31:22.240 --> 00:31:23.650 align:middle line:90% That's all an algorithm is. 00:31:23.650 --> 00:31:25.600 align:middle line:84% And so when you hear about algorithms and machine learning 00:31:25.600 --> 00:31:27.760 align:middle line:84% and artificial intelligence which use algorithms, 00:31:27.760 --> 00:31:30.052 align:middle line:84% those are just step by step instructions that computers 00:31:30.052 --> 00:31:31.940 align:middle line:90% are using to solve some problem. 00:31:31.940 --> 00:31:35.480 align:middle line:84% So that's, I claim, what would be inside of this black box in the middle. 00:31:35.480 --> 00:31:37.270 align:middle line:90% So what might a sample algorithm be? 00:31:37.270 --> 00:31:39.480 align:middle line:84% Well one that you saw an illusion to a little bit 00:31:39.480 --> 00:31:42.340 align:middle line:84% ago is this old school device here, so a phone book. 00:31:42.340 --> 00:31:45.730 align:middle line:84% And inside of a phone book are hundreds or thousands of names and numbers, 00:31:45.730 --> 00:31:48.877 align:middle line:84% typically alphabetical from A to Z. And even though this is old school 00:31:48.877 --> 00:31:50.710 align:middle line:84% and most of us don't even use these anymore, 00:31:50.710 --> 00:31:53.590 align:middle line:84% frankly, it's the same thing in our Android phones and iPhones. 00:31:53.590 --> 00:31:55.510 align:middle line:84% Those just happen to be digitally implemented. 00:31:55.510 --> 00:31:58.130 align:middle line:84% But they're still sorted A to Z, top to bottom. 00:31:58.130 --> 00:32:01.480 align:middle line:84% And so instead of flipping through pages one at a time or two at a time, now 00:32:01.480 --> 00:32:03.857 align:middle line:84% we're just kind of scrolling through one at a time. 00:32:03.857 --> 00:32:06.190 align:middle line:84% But of course, on our phones, you can search for things, 00:32:06.190 --> 00:32:09.010 align:middle line:84% and you can type in a friend's name and try to look them up in your phone. 00:32:09.010 --> 00:32:11.600 align:middle line:84% Well, back in the day, you would do that's similar in spirit, 00:32:11.600 --> 00:32:14.517 align:middle line:84% but you would have to do it with your own human eyes and not software. 00:32:14.517 --> 00:32:18.250 align:middle line:84% But how is software implementing that same step by step approach? 00:32:18.250 --> 00:32:21.100 align:middle line:84% Well, if I want to find someone like Mike Smith in this phone 00:32:21.100 --> 00:32:23.192 align:middle line:84% book, last name Smith starting with S, well, I 00:32:23.192 --> 00:32:26.150 align:middle line:84% could certainly just start at the beginning and look on the first page. 00:32:26.150 --> 00:32:27.370 align:middle line:90% And nope, he's not there. 00:32:27.370 --> 00:32:29.105 align:middle line:90% Second page, nope, he's not there. 00:32:29.105 --> 00:32:29.980 align:middle line:90% Nope, he's not there. 00:32:29.980 --> 00:32:31.255 align:middle line:90% One page at a time. 00:32:31.255 --> 00:32:33.130 align:middle line:84% That is a step by step process, an algorithm. 00:32:33.130 --> 00:32:34.370 align:middle line:90% Is it correct? 00:32:34.370 --> 00:32:35.740 align:middle line:90% AUDIENCE: Yes. 00:32:35.740 --> 00:32:38.740 align:middle line:84% DAVID J. MALAN: Yeah, it's correct in the sense that if Mike is in here, 00:32:38.740 --> 00:32:40.810 align:middle line:90% I will find him if he is. 00:32:40.810 --> 00:32:42.510 align:middle line:90% Is it good algorithm? 00:32:42.510 --> 00:32:43.570 align:middle line:90% AUDIENCE: No. 00:32:43.570 --> 00:32:44.740 align:middle line:84% DAVID J. MALAN: No, I mean it's pretty stupid. 00:32:44.740 --> 00:32:46.820 align:middle line:84% This is going to take me forever to go one page at a time. 00:32:46.820 --> 00:32:48.695 align:middle line:84% So in grade school I could do things twice as 00:32:48.695 --> 00:32:52.805 align:middle line:90% fast by going 2, 4, 6, 8, 10, 12-- 00:32:52.805 --> 00:32:54.430 align:middle line:90% that's actually easier said than done-- 00:32:54.430 --> 00:32:56.847 align:middle line:84% and so forth and fly through the phone book twice as fast. 00:32:56.847 --> 00:32:58.390 align:middle line:90% Is that algorithm correct? 00:32:58.390 --> 00:32:59.350 align:middle line:90% AUDIENCE: No, it isn't. 00:32:59.350 --> 00:32:59.590 align:middle line:90% DAVID J. MALAN: No. 00:32:59.590 --> 00:33:00.820 align:middle line:90% Why, what's the catch? 00:33:00.820 --> 00:33:02.080 align:middle line:90% AUDIENCE: You could skip him. 00:33:02.080 --> 00:33:03.670 align:middle line:84% DAVID J. MALAN: Yeah, I could skip them accidentally, right? 00:33:03.670 --> 00:33:06.462 align:middle line:84% Once I get pretty deep into the phone book I just might get unlucky 00:33:06.462 --> 00:33:09.250 align:middle line:84% and he happens to be sandwiched in between two of the pages 00:33:09.250 --> 00:33:10.422 align:middle line:90% that I'm flying through. 00:33:10.422 --> 00:33:11.380 align:middle line:90% So they're still fixed. 00:33:11.380 --> 00:33:13.990 align:middle line:84% I don't have to just never use two things at a time. 00:33:13.990 --> 00:33:17.020 align:middle line:84% I can just make sure that when I hit Sn in the phone book 00:33:17.020 --> 00:33:20.720 align:middle line:84% or maybe the T section, I know I have to at least double back maybe one page. 00:33:20.720 --> 00:33:24.490 align:middle line:84% So I can fix that bug or mistake, as it would be called in programming, 00:33:24.490 --> 00:33:25.930 align:middle line:90% and then see if he's on that page. 00:33:25.930 --> 00:33:27.930 align:middle line:84% But most of us if we're going to use this technology at all 00:33:27.930 --> 00:33:30.082 align:middle line:84% are not going to search one or two pages at a time. 00:33:30.082 --> 00:33:31.540 align:middle line:90% What's a normal person going to do? 00:33:31.540 --> 00:33:32.880 align:middle line:90% AUDIENCE: Just open it. 00:33:32.880 --> 00:33:33.050 align:middle line:90% DAVID J. MALAN: Sorry. 00:33:33.050 --> 00:33:34.075 align:middle line:90% AUDIENCE: Just open it. 00:33:34.075 --> 00:33:35.283 align:middle line:90% DAVID J. MALAN: Just open it. 00:33:35.283 --> 00:33:36.460 align:middle line:90% OK, I am in the M section. 00:33:36.460 --> 00:33:37.210 align:middle line:90% I don't see Mike. 00:33:37.210 --> 00:33:38.463 align:middle line:90% AUDIENCE: Keep going. 00:33:38.463 --> 00:33:39.838 align:middle line:90% DAVID J. MALAN: Keep going where? 00:33:39.838 --> 00:33:41.470 align:middle line:84% AUDIENCE: To the S, like there's more pages. 00:33:41.470 --> 00:33:42.590 align:middle line:90% DAVID J. MALAN: OK some more pages. 00:33:42.590 --> 00:33:43.590 align:middle line:90% But direction matters. 00:33:43.590 --> 00:33:46.940 align:middle line:84% So I probably want to go to like this way to the S's if I'm ending up 00:33:46.940 --> 00:33:48.020 align:middle line:90% in the middle in the M's. 00:33:48.020 --> 00:33:49.470 align:middle line:90% But what does that mean? 00:33:49.470 --> 00:33:53.480 align:middle line:84% It means that I know Mike is not in any of this half of the phone book. 00:33:53.480 --> 00:33:58.610 align:middle line:84% So both figuratively and literally, we can tear the problem in half, 00:33:58.610 --> 00:34:00.020 align:middle line:90% tear the problem in half. 00:34:00.020 --> 00:34:03.320 align:middle line:84% And now I'm left not with one byte or two bytes out of the problem 00:34:03.320 --> 00:34:05.390 align:middle line:84% as my first algorithms involved, now I've 00:34:05.390 --> 00:34:08.364 align:middle line:84% taken like 500 bytes out of the problem all at once. 00:34:08.364 --> 00:34:09.739 align:middle line:90% But they're not incorrect, right. 00:34:09.739 --> 00:34:13.280 align:middle line:84% I know Mike, as you say, it's not there because he's toward the S's. 00:34:13.280 --> 00:34:15.300 align:middle line:90% All right, what do I do now? 00:34:15.300 --> 00:34:15.906 align:middle line:90% I open it up. 00:34:15.906 --> 00:34:17.239 align:middle line:90% All right, ah, slightly too far. 00:34:17.239 --> 00:34:18.650 align:middle line:90% I'm in the T section now. 00:34:18.650 --> 00:34:21.120 align:middle line:90% What do I obviously do next? 00:34:21.120 --> 00:34:22.010 align:middle line:90% Now he's this way. 00:34:22.010 --> 00:34:25.880 align:middle line:84% But that means there are like 250 pages that I know he's not on. 00:34:25.880 --> 00:34:28.969 align:middle line:84% So again, my algorithm of 1 and 2 at a time 00:34:28.969 --> 00:34:32.510 align:middle line:84% is completely blown away by this much faster algorithm as well. 00:34:32.510 --> 00:34:34.949 align:middle line:84% And I can repeat and I can repeat and repeat. 00:34:34.949 --> 00:34:37.907 align:middle line:84% And if I did it right, hopefully, I'm going to end up with, eventually, 00:34:37.907 --> 00:34:39.860 align:middle line:84% if we fast forward one page and Mike Smith 00:34:39.860 --> 00:34:42.520 align:middle line:84% is either on the phone book's page or he's not. 00:34:42.520 --> 00:34:44.480 align:middle line:90% I can go ahead and call him then. 00:34:44.480 --> 00:34:45.710 align:middle line:90% So this is just intuitive. 00:34:45.710 --> 00:34:48.350 align:middle line:84% And frankly, that's exactly what your phones 00:34:48.350 --> 00:34:50.090 align:middle line:90% are doing when you search for a friend. 00:34:50.090 --> 00:34:51.949 align:middle line:90% It happens in a split second. 00:34:51.949 --> 00:34:55.340 align:middle line:84% But your phone typically, if you're looking for Smith in your phone, 00:34:55.340 --> 00:34:58.100 align:middle line:84% it's not searching from top to bottom among your contacts. 00:34:58.100 --> 00:35:00.440 align:middle line:84% It's jumping mathematically to whatever the middle is. 00:35:00.440 --> 00:35:03.680 align:middle line:84% And that's probably M, give or take, depending on the distribution 00:35:03.680 --> 00:35:05.100 align:middle line:90% of your friend's last names. 00:35:05.100 --> 00:35:07.640 align:middle line:84% And then it's going to jump forward or back, 00:35:07.640 --> 00:35:11.030 align:middle line:84% without you seeing this as a human, finding that value. 00:35:11.030 --> 00:35:12.410 align:middle line:90% And what's the takeaway there? 00:35:12.410 --> 00:35:14.880 align:middle line:84% Well, just how much more efficient was this? 00:35:14.880 --> 00:35:16.700 align:middle line:84% Well, the first algorithm, how many steps 00:35:16.700 --> 00:35:22.240 align:middle line:84% might it take me in 1,000 page phone book to find Mike Smith? 00:35:22.240 --> 00:35:24.910 align:middle line:84% Yeah, I don't know like 700, 800 something like that, 00:35:24.910 --> 00:35:26.170 align:middle line:90% like hundreds of pages. 00:35:26.170 --> 00:35:29.140 align:middle line:84% What about the 2's approach, 2 pages at a time? 00:35:29.140 --> 00:35:32.590 align:middle line:84% Like 350, 400 pages, right, half as many pages, since I'm 00:35:32.590 --> 00:35:33.910 align:middle line:90% flying through twice as fast. 00:35:33.910 --> 00:35:37.060 align:middle line:84% How many times is it going to take me to look for Mike Smith using 00:35:37.060 --> 00:35:40.750 align:middle line:84% the third algorithm where I kept dividing the problem in half, 00:35:40.750 --> 00:35:44.290 align:middle line:84% dividing and conquering if you will, and it started with 1,000 pages? 00:35:44.290 --> 00:35:47.210 align:middle line:90% AUDIENCE: Three. 00:35:47.210 --> 00:35:50.420 align:middle line:84% DAVID J. MALAN: Three, more than three, unless I get lucky. 00:35:50.420 --> 00:35:54.830 align:middle line:84% It's closer to 8, 9, 10, right, because 1,000 in half is 500, 00:35:54.830 --> 00:35:57.033 align:middle line:84% then 250, then 125, then I have to round. 00:35:57.033 --> 00:35:57.950 align:middle line:90% And then I keep going. 00:35:57.950 --> 00:36:00.110 align:middle line:84% But I can do that 10-ish times, depending 00:36:00.110 --> 00:36:04.700 align:middle line:84% on the precise number of pages, 9 or 10 times will get me to one final page. 00:36:04.700 --> 00:36:07.130 align:middle line:84% So that means I started with 1,000 pages at first. 00:36:07.130 --> 00:36:10.040 align:middle line:84% I can in 10 steps, your phone can in 10 steps, 00:36:10.040 --> 00:36:13.850 align:middle line:84% find that friend in the phone book, if they are actually there. 00:36:13.850 --> 00:36:18.290 align:middle line:84% The first two algorithms would have taken 700 steps, 350 steps, or at worst 00:36:18.290 --> 00:36:21.050 align:middle line:84% the whole phone book if, I just keep going and don't find him. 00:36:21.050 --> 00:36:23.882 align:middle line:84% The algorithm that we had more intuitively is indeed the same. 00:36:23.882 --> 00:36:26.090 align:middle line:84% And without getting too mathematical, we can actually 00:36:26.090 --> 00:36:27.740 align:middle line:90% appreciate this even graphically. 00:36:27.740 --> 00:36:31.088 align:middle line:84% So here's sort of a very simple chart on the x-axis or horizontal, 00:36:31.088 --> 00:36:34.130 align:middle line:84% it's the size of the problem, like how many pages are in your phone book. 00:36:34.130 --> 00:36:36.560 align:middle line:84% The vertical axis on the left is how much time does it 00:36:36.560 --> 00:36:39.590 align:middle line:84% take you to solve the problem-- seconds, page turns, 00:36:39.590 --> 00:36:41.330 align:middle line:90% whenever your unit of measure is. 00:36:41.330 --> 00:36:43.520 align:middle line:84% Well, the first algorithm I can draw like this. 00:36:43.520 --> 00:36:44.570 align:middle line:90% It's a straight line. 00:36:44.570 --> 00:36:48.680 align:middle line:84% The slope has a 1 to 1 ratio, because if Verizon or the phone company 00:36:48.680 --> 00:36:51.290 align:middle line:84% next year adds one more page to the phone book, 00:36:51.290 --> 00:36:53.577 align:middle line:84% that might push Mike one more page forward. 00:36:53.577 --> 00:36:55.910 align:middle line:84% So that might take me one more unit of time to find him. 00:36:55.910 --> 00:36:57.590 align:middle line:90% So a 1 over 1 slope. 00:36:57.590 --> 00:37:00.380 align:middle line:84% The second algorithm is also a straight line. 00:37:00.380 --> 00:37:03.890 align:middle line:84% It's just lower than the red line, because for any given number of pages 00:37:03.890 --> 00:37:06.132 align:middle line:84% on the x-axis, wherever I want to put my hand, 00:37:06.132 --> 00:37:08.090 align:middle line:84% I'm going to hit the yellow line at some point, 00:37:08.090 --> 00:37:10.215 align:middle line:84% and that's how many page turns or seconds it takes, 00:37:10.215 --> 00:37:12.740 align:middle line:84% but if I go higher up, twice as high up, then 00:37:12.740 --> 00:37:15.830 align:middle line:84% I'll see how much time the first algorithm took, the red line, 00:37:15.830 --> 00:37:17.870 align:middle line:90% because it's working half as fast. 00:37:17.870 --> 00:37:22.078 align:middle line:84% But the third algorithm is what we'll call this curved green line. 00:37:22.078 --> 00:37:23.870 align:middle line:84% It's a different shape and even if you have 00:37:23.870 --> 00:37:25.745 align:middle line:84% hazy memories as to what the term means, it's 00:37:25.745 --> 00:37:29.060 align:middle line:84% what we called at some point in your mathematical backgrounds, logarithmic. 00:37:29.060 --> 00:37:32.600 align:middle line:84% And if you haven't seen this term, not to worry if it's unfamiliar altogether. 00:37:32.600 --> 00:37:36.020 align:middle line:84% But this has a fundamentally different shape, a fundamentally different shape. 00:37:36.020 --> 00:37:37.070 align:middle line:90% It's not a straight line. 00:37:37.070 --> 00:37:38.090 align:middle line:90% It's curved. 00:37:38.090 --> 00:37:41.780 align:middle line:84% And notice that it almost kind of sort of gets flat even. 00:37:41.780 --> 00:37:43.910 align:middle line:90% It never becomes flat. 00:37:43.910 --> 00:37:48.890 align:middle line:84% It just grows or rises ever so slowly as you go farther and farther out. 00:37:48.890 --> 00:37:49.490 align:middle line:90% Why? 00:37:49.490 --> 00:37:51.407 align:middle line:84% Well, think about it from another perspective. 00:37:51.407 --> 00:37:54.390 align:middle line:84% If Verizon doubles the number of people in the phone book next year, 00:37:54.390 --> 00:37:57.350 align:middle line:84% maybe two towns East Haven and New Haven merged together into one 00:37:57.350 --> 00:37:59.690 align:middle line:84% bigger phone book with twice as many pages, 00:37:59.690 --> 00:38:01.760 align:middle line:84% well, how many more steps will take you to find 00:38:01.760 --> 00:38:04.070 align:middle line:90% Mike Smith next year, in that case? 00:38:04.070 --> 00:38:05.510 align:middle line:90% Like, one more step. 00:38:05.510 --> 00:38:10.100 align:middle line:84% That's a really powerful idea, just to go up one second or one page turn 00:38:10.100 --> 00:38:12.350 align:middle line:84% on the vertical axis, you have to go way, 00:38:12.350 --> 00:38:16.620 align:middle line:84% way out on the x-axis, which again represents the number of pages. 00:38:16.620 --> 00:38:17.982 align:middle line:90% And that's a powerful algorithm. 00:38:17.982 --> 00:38:19.940 align:middle line:84% And what I claim is that even if you're feeling 00:38:19.940 --> 00:38:22.697 align:middle line:84% uneasy with the idea of computer science, let alone programming, 00:38:22.697 --> 00:38:25.280 align:middle line:84% a lot of the ideas we're going to explore this semester really 00:38:25.280 --> 00:38:27.065 align:middle line:90% are as familiar as that. 00:38:27.065 --> 00:38:28.940 align:middle line:84% And it's really just a process of translating 00:38:28.940 --> 00:38:35.300 align:middle line:84% those ideas and that human intuition you already have into what we'll call code. 00:38:35.300 --> 00:38:38.570 align:middle line:84% And what a perfect setup to actually introduce some code, but not 00:38:38.570 --> 00:38:40.040 align:middle line:90% in specific programming language. 00:38:40.040 --> 00:38:41.930 align:middle line:90% So we'll begin with this, pseudocode. 00:38:41.930 --> 00:38:44.120 align:middle line:90% So pseudocode is not a formal language. 00:38:44.120 --> 00:38:45.590 align:middle line:90% There's no one way to write it. 00:38:45.590 --> 00:38:48.710 align:middle line:84% And everyone of us on the staff might write the following algorithm 00:38:48.710 --> 00:38:50.000 align:middle line:90% in a slightly different way. 00:38:50.000 --> 00:38:52.760 align:middle line:84% You just use English like syntax and grammar 00:38:52.760 --> 00:38:56.130 align:middle line:84% or whatever your spoken language is to convey your ideas. 00:38:56.130 --> 00:38:59.600 align:middle line:84% So for instance to implement that algorithm 00:38:59.600 --> 00:39:03.410 align:middle line:84% that I ended on, finding Mike Smith by dividing and conquering again 00:39:03.410 --> 00:39:06.590 align:middle line:84% and again, how would Express that a little more methodically in such a way 00:39:06.590 --> 00:39:09.450 align:middle line:84% that another person or ultimately a computer could understand? 00:39:09.450 --> 00:39:12.200 align:middle line:84% Well, I might jot down that step 1 is just pick up the phone book. 00:39:12.200 --> 00:39:13.460 align:middle line:90% That's where I began. 00:39:13.460 --> 00:39:16.820 align:middle line:84% Step 2 would be open to the middle of the phone book, you know, give or take. 00:39:16.820 --> 00:39:19.653 align:middle line:84% I can be a little sloppy about it even if I want in the human world. 00:39:19.653 --> 00:39:21.530 align:middle line:90% And it will average out in the end. 00:39:21.530 --> 00:39:25.252 align:middle line:84% Step 3, look at the names, looking for Mike Smith on the current page. 00:39:25.252 --> 00:39:27.960 align:middle line:84% It's the M section, so I already know he's not going to be there. 00:39:27.960 --> 00:39:29.960 align:middle line:84% So then I have to ask myself a question, though. 00:39:29.960 --> 00:39:34.640 align:middle line:84% If Smith is among the names, what do I probably want to do? 00:39:34.640 --> 00:39:36.800 align:middle line:84% Call him or do something with that information. 00:39:36.800 --> 00:39:39.032 align:middle line:84% So I'll indent that underneath to make clear 00:39:39.032 --> 00:39:40.490 align:middle line:90% that there's cause and effect here. 00:39:40.490 --> 00:39:43.280 align:middle line:84% If step 4 is true, then I should do step 5. 00:39:43.280 --> 00:39:44.870 align:middle line:90% That's all the indentation means. 00:39:44.870 --> 00:39:46.890 align:middle line:84% But if Mike is not on the page I'm looking at, 00:39:46.890 --> 00:39:48.932 align:middle line:84% which he's not going to be if it's the M section, 00:39:48.932 --> 00:39:52.097 align:middle line:84% then I might ask well else if Smith is earlier in the book to the left 00:39:52.097 --> 00:39:53.180 align:middle line:90% then what do I want to do? 00:39:53.180 --> 00:39:56.750 align:middle line:84% Well, as you proposed, go to the left of the book, and in this case, 00:39:56.750 --> 00:39:59.630 align:middle line:90% open to middle of left of book. 00:39:59.630 --> 00:40:04.580 align:middle line:84% And if I then don't find that he's earlier in the book, but rather, 00:40:04.580 --> 00:40:07.820 align:middle line:90% then I have to go back to line 3. 00:40:07.820 --> 00:40:08.510 align:middle line:90% Why? 00:40:08.510 --> 00:40:11.750 align:middle line:84% Well let's be clear, if on line 6 Smith is earlier in the book, 00:40:11.750 --> 00:40:15.830 align:middle line:84% he's to the left of where I am in the book, what do I want to do? 00:40:15.830 --> 00:40:18.630 align:middle line:84% I want to open to the middle of the left half of the book. 00:40:18.630 --> 00:40:22.610 align:middle line:84% And then go back to step 3 because the next step should be, look at the names, 00:40:22.610 --> 00:40:24.740 align:middle line:84% if I've just jumped elsewhere in the book. 00:40:24.740 --> 00:40:28.340 align:middle line:84% And I can repeat the same process again and again without writing this down 00:40:28.340 --> 00:40:30.380 align:middle line:90% to be 20 or 30 or 40 lines. 00:40:30.380 --> 00:40:34.290 align:middle line:84% I can reuse some of my own syntax to be more efficient. 00:40:34.290 --> 00:40:36.440 align:middle line:84% But if Mike is later in the book, I instead 00:40:36.440 --> 00:40:39.180 align:middle line:84% want to open to the middle of the right half of the book, 00:40:39.180 --> 00:40:42.710 align:middle line:84% and then again, go back to step 3, because I want to see 00:40:42.710 --> 00:40:45.770 align:middle line:90% if he's on now that page to the right. 00:40:45.770 --> 00:40:47.000 align:middle line:90% Now I'm not quite done. 00:40:47.000 --> 00:40:49.900 align:middle line:84% Mike's either there or he's to the left or to the right. 00:40:49.900 --> 00:40:52.308 align:middle line:90% Or there's one fourth case, so to speak. 00:40:52.308 --> 00:40:53.350 align:middle line:90% AUDIENCE: He's not there. 00:40:53.350 --> 00:40:54.310 align:middle line:90% DAVID J. MALAN: He's not there. 00:40:54.310 --> 00:40:55.510 align:middle line:90% And I should consider this. 00:40:55.510 --> 00:40:57.770 align:middle line:84% So if I want to make sure I should say else. 00:40:57.770 --> 00:41:01.640 align:middle line:84% If he doesn't fall into any of those three scenarios, I should just quit. 00:41:01.640 --> 00:41:04.810 align:middle line:84% And if we fast forwarded a bit among the delights in any programming class, 00:41:04.810 --> 00:41:08.200 align:middle line:84% ultimately is your first of many bugs or mistakes that you might make. 00:41:08.200 --> 00:41:11.470 align:middle line:84% And you've seen bugs before in the world of Macs and PC and even phones. 00:41:11.470 --> 00:41:14.740 align:middle line:84% If you've ever seen annoying little spinning beach ball on Mac OS, 00:41:14.740 --> 00:41:17.710 align:middle line:84% or you've seen the little hourglass things spin endlessly on Windows, 00:41:17.710 --> 00:41:20.890 align:middle line:84% or if you're iPhone or Android phone just freezes altogether, 00:41:20.890 --> 00:41:24.730 align:middle line:84% very likely the human who wrote the code that your phone or laptop are running 00:41:24.730 --> 00:41:28.060 align:middle line:84% at that moment just didn't anticipate some fourth 00:41:28.060 --> 00:41:30.370 align:middle line:90% or some fifth possible scenario. 00:41:30.370 --> 00:41:32.890 align:middle line:84% And therefore, there was no line of code that the computer 00:41:32.890 --> 00:41:35.120 align:middle line:90% could use to handle that scenario. 00:41:35.120 --> 00:41:39.770 align:middle line:84% So it just crashes or spins forever or reboots or does something unexpected. 00:41:39.770 --> 00:41:42.580 align:middle line:84% So even something like this, if you left out this condition, 00:41:42.580 --> 00:41:45.250 align:middle line:84% you might be looking for Mike endlessly, spinning beach ball, 00:41:45.250 --> 00:41:48.940 align:middle line:84% if you never actually tell yourself to quit or to exit. 00:41:48.940 --> 00:41:51.220 align:middle line:84% So we'll see more evidence of that before long. 00:41:51.220 --> 00:41:54.090 align:middle line:84% But let's apply some now programming terms to these ideas here. 00:41:54.090 --> 00:41:55.840 align:middle line:84% So highlighted in yellow now or henceforth 00:41:55.840 --> 00:41:57.910 align:middle line:90% are what we're going to call functions. 00:41:57.910 --> 00:42:01.540 align:middle line:84% These are just actions or verbs that tell the computer or the human 00:42:01.540 --> 00:42:05.320 align:middle line:84% or the robot what to do in pseudocode here. 00:42:05.320 --> 00:42:06.838 align:middle line:90% Those are all verbs or actions. 00:42:06.838 --> 00:42:09.880 align:middle line:84% Here we have what I'm going to call-- what we're going to call conditions 00:42:09.880 --> 00:42:10.900 align:middle line:90% or branches. 00:42:10.900 --> 00:42:14.473 align:middle line:84% These are like decision points or metaphorical forks in the road. 00:42:14.473 --> 00:42:16.390 align:middle line:84% You're either going to go this way or that way 00:42:16.390 --> 00:42:19.730 align:middle line:84% just like in the phone book or maybe a third or fourth direction as well. 00:42:19.730 --> 00:42:22.480 align:middle line:84% But how do you decide what road to go down logically? 00:42:22.480 --> 00:42:25.150 align:middle line:84% These are a little more fancy called Boolean expressions, 00:42:25.150 --> 00:42:28.300 align:middle line:84% after a mathematician named Boole in yesteryear. 00:42:28.300 --> 00:42:30.880 align:middle line:84% And a Boolean expression is just a question 00:42:30.880 --> 00:42:37.210 align:middle line:84% that has a yes no answer or a true false answer, or, if you will, a 1 0 answer. 00:42:37.210 --> 00:42:39.378 align:middle line:90% We could reduce that to bits as well. 00:42:39.378 --> 00:42:41.420 align:middle line:84% Lastly, we'll have these things highlighted here, 00:42:41.420 --> 00:42:43.090 align:middle line:90% which we're going to call loops. 00:42:43.090 --> 00:42:46.210 align:middle line:84% And going back to line 3 is indeed inducing this kind of idea, 00:42:46.210 --> 00:42:49.450 align:middle line:84% go back and do something again such that you're in some kind of cycle 00:42:49.450 --> 00:42:51.100 align:middle line:90% or as we'll say a loop. 00:42:51.100 --> 00:42:53.020 align:middle line:84% And those are four of the ideas in programming 00:42:53.020 --> 00:42:55.910 align:middle line:84% that we'll see now in actual code and four of the ideas 00:42:55.910 --> 00:42:57.910 align:middle line:84% that will persist throughout the whole semester. 00:42:57.910 --> 00:43:00.160 align:middle line:84% These relatively simple building blocks that you and I 00:43:00.160 --> 00:43:03.580 align:middle line:84% use every day, either intuitively or maybe even on paper, 00:43:03.580 --> 00:43:08.140 align:middle line:84% are just ways of breaking down problems into step by step instructions 00:43:08.140 --> 00:43:09.820 align:middle line:90% or, again, algorithms. 00:43:09.820 --> 00:43:12.820 align:middle line:84% But we're going to add a few things to the list in just a moment, things 00:43:12.820 --> 00:43:16.180 align:middle line:84% called variables which you might recall from algebra or math more generally, 00:43:16.180 --> 00:43:19.120 align:middle line:84% things called threads which are a little more specific to computing, 00:43:19.120 --> 00:43:21.940 align:middle line:84% and events which we'll see, especially later in the semester. 00:43:21.940 --> 00:43:26.080 align:middle line:84% But we're going to do this as playfully as we can by way of this character 00:43:26.080 --> 00:43:27.250 align:middle line:90% here named Scratch. 00:43:27.250 --> 00:43:30.250 align:middle line:84% And odds are some of you probably used in high school, middle school, 00:43:30.250 --> 00:43:31.360 align:middle line:90% in grade school-- 00:43:31.360 --> 00:43:32.330 align:middle line:90% yes, a few. 00:43:32.330 --> 00:43:34.990 align:middle line:84% So Scratch is this amazing language from MIT's Media 00:43:34.990 --> 00:43:36.575 align:middle line:90% Lab developed some years ago. 00:43:36.575 --> 00:43:38.950 align:middle line:84% And, indeed, it's targeted primarily at younger students. 00:43:38.950 --> 00:43:41.500 align:middle line:84% But it actually encapsulates all of these ideas 00:43:41.500 --> 00:43:42.880 align:middle line:90% that we've discussed thus far. 00:43:42.880 --> 00:43:47.050 align:middle line:84% And we use it in CS50 as a springboard in the first week to our second week, 00:43:47.050 --> 00:43:50.260 align:middle line:84% wherein next week we'll introduce you to a language or two-- 00:43:50.260 --> 00:43:53.890 align:middle line:84% a week and a half about, we'll introduce you to a more text-based language, 00:43:53.890 --> 00:43:58.090 align:middle line:84% more traditional language called C. But let's see if we can't see-- 00:43:58.090 --> 00:44:02.050 align:middle line:84% no pun intended-- let's see if we can't see some of these same ideas in some 00:44:02.050 --> 00:44:03.500 align:middle line:90% of the code here as well. 00:44:03.500 --> 00:44:07.985 align:middle line:84% So I'm going to go to a website here Scratch.MIT.edu. 00:44:07.985 --> 00:44:10.610 align:middle line:84% And ultimately, in a week and a half when the first problem set 00:44:10.610 --> 00:44:12.160 align:middle line:84% or programming assignment for the course is due, 00:44:12.160 --> 00:44:14.660 align:middle line:84% we'll provide you with all of this step by step instructions 00:44:14.660 --> 00:44:16.482 align:middle line:90% to do the same thing yourself. 00:44:16.482 --> 00:44:18.940 align:middle line:84% The first thing you can do is you'll see in the homework is 00:44:18.940 --> 00:44:20.440 align:middle line:90% to create something in Scratch. 00:44:20.440 --> 00:44:23.230 align:middle line:84% And you'll be prompted first to create a user name and password so that you 00:44:23.230 --> 00:44:24.460 align:middle line:90% have somewhere to save your file. 00:44:24.460 --> 00:44:26.500 align:middle line:84% But I'm just going to do my things here on the fly. 00:44:26.500 --> 00:44:29.000 align:middle line:84% And by default, you'll see an environment that looks like this. 00:44:29.000 --> 00:44:31.042 align:middle line:84% And I'm going to go ahead and dismiss the default 00:44:31.042 --> 00:44:34.310 align:middle line:84% tutorial, just to give a definition of what's here on the screen. 00:44:34.310 --> 00:44:38.167 align:middle line:84% So on the left hand side here is a whole bunch of seeming puzzle pieces, 00:44:38.167 --> 00:44:40.000 align:middle line:84% little colorful blocks that in just a moment 00:44:40.000 --> 00:44:43.240 align:middle line:84% I'm going to drag and drop and interlock them like an actual puzzle. 00:44:43.240 --> 00:44:46.240 align:middle line:84% In the middle here is what we'll just call the programming area. 00:44:46.240 --> 00:44:49.240 align:middle line:84% This is the editor where I'm going to drag and drop those puzzle pieces. 00:44:49.240 --> 00:44:51.790 align:middle line:84% And over here is what MIT calls the stage. 00:44:51.790 --> 00:44:55.450 align:middle line:84% It is the area of the screen where Scratch, the default cat that we see, 00:44:55.450 --> 00:44:57.610 align:middle line:84% can move up, down, left, right make sounds, or do 00:44:57.610 --> 00:44:59.300 align:middle line:90% any number of other things. 00:44:59.300 --> 00:45:01.990 align:middle line:84% So we're going to create code by dragging and dropping 00:45:01.990 --> 00:45:03.550 align:middle line:90% those puzzle pieces into the middle. 00:45:03.550 --> 00:45:06.850 align:middle line:84% And then when I click the Start button, effectively, well, things 00:45:06.850 --> 00:45:08.570 align:middle line:90% start to happen. 00:45:08.570 --> 00:45:11.650 align:middle line:84% So perhaps the very first thing or simplest thing I can do with Scratch 00:45:11.650 --> 00:45:12.400 align:middle line:90% is this. 00:45:12.400 --> 00:45:16.060 align:middle line:84% Notice how in the left hand side here, there's these colorful categories 00:45:16.060 --> 00:45:20.470 align:middle line:84% that just group different ideas into different types of puzzle pieces 00:45:20.470 --> 00:45:21.530 align:middle line:90% or blocks. 00:45:21.530 --> 00:45:24.340 align:middle line:84% The first one up here under Events is where I want to begin. 00:45:24.340 --> 00:45:28.870 align:middle line:84% The act of clicking a start button on a phone or a laptop 00:45:28.870 --> 00:45:30.910 align:middle line:84% is what a computer scientist calls an event. 00:45:30.910 --> 00:45:34.120 align:middle line:84% It's something that happens that the computer can listen for. 00:45:34.120 --> 00:45:36.640 align:middle line:84% And we'll see now that there's this little green flag, 00:45:36.640 --> 00:45:40.690 align:middle line:84% like in a game, that when clicked over here at top right, 00:45:40.690 --> 00:45:44.020 align:middle line:84% will just start the code running based on whatever I've typed. 00:45:44.020 --> 00:45:47.020 align:middle line:84% Now the only thing I want to do is make Scratch look a little different. 00:45:47.020 --> 00:45:49.680 align:middle line:84% And if I scroll over to Looks over here in purple, 00:45:49.680 --> 00:45:52.870 align:middle line:84% there's a whole bunch of puzzle pieces, one of which is just say Hello 00:45:52.870 --> 00:45:56.470 align:middle line:84% by default. So I'm going to go ahead and drag and drop that puzzle piece next. 00:45:56.470 --> 00:45:59.450 align:middle line:84% And notice that as I get close to an existing puzzle piece, 00:45:59.450 --> 00:46:01.690 align:middle line:84% they're sort of magnetic and they want to interlock. 00:46:01.690 --> 00:46:04.730 align:middle line:84% So if I just let go, they now snap together. 00:46:04.730 --> 00:46:08.890 align:middle line:84% And one of the very first programs written years ago, 00:46:08.890 --> 00:46:11.930 align:middle line:84% historically, had just this phrase here, hello world. 00:46:11.930 --> 00:46:14.780 align:middle line:84% Some of the very first few words ever spoken in a computer program. 00:46:14.780 --> 00:46:16.900 align:middle line:90% So we'll repeat that legacy here. 00:46:16.900 --> 00:46:18.430 align:middle line:90% So I now have a program. 00:46:18.430 --> 00:46:19.670 align:middle line:90% It's super simple. 00:46:19.670 --> 00:46:21.370 align:middle line:90% It's only got two puzzle pieces. 00:46:21.370 --> 00:46:23.120 align:middle line:90% But how do I go ahead and play it? 00:46:23.120 --> 00:46:25.090 align:middle line:90% Well, the code is telling me what to do. 00:46:25.090 --> 00:46:30.070 align:middle line:84% When the green flag is clicked, go ahead and say, hello world. 00:46:30.070 --> 00:46:31.503 align:middle line:90% So that is a program, right? 00:46:31.503 --> 00:46:32.170 align:middle line:90% There's no text. 00:46:32.170 --> 00:46:33.010 align:middle line:90% There's no C++. 00:46:33.010 --> 00:46:33.760 align:middle line:90% There's no Java. 00:46:33.760 --> 00:46:37.010 align:middle line:84% There's no Swift or any languages that might generally have heard of thus far. 00:46:37.010 --> 00:46:39.550 align:middle line:84% Scratch itself is a language that happens to be graphical. 00:46:39.550 --> 00:46:43.220 align:middle line:84% But it has the same ideas that we'll see in fancier form soon. 00:46:43.220 --> 00:46:45.970 align:middle line:84% In fact, what has just happened-- let me go back for just a moment 00:46:45.970 --> 00:46:49.770 align:middle line:90% here over to the where we began. 00:46:49.770 --> 00:46:52.270 align:middle line:84% And you'll recall we had this definition of problem solving. 00:46:52.270 --> 00:46:55.330 align:middle line:84% Inputs passed into algorithms which yields outputs. 00:46:55.330 --> 00:46:59.110 align:middle line:84% Well, let me propose that we consider the input in this particular program 00:46:59.110 --> 00:47:01.360 align:middle line:84% just to be this, hello world, the words I happen 00:47:01.360 --> 00:47:04.030 align:middle line:90% to type into that little ovular box. 00:47:04.030 --> 00:47:06.610 align:middle line:84% Then the algorithm is just to say something, 00:47:06.610 --> 00:47:09.760 align:middle line:84% like that is the code that's taking as input those words. 00:47:09.760 --> 00:47:11.290 align:middle line:90% And what is the output going to be? 00:47:11.290 --> 00:47:13.390 align:middle line:84% Well, hopefully, if the code works, it's going 00:47:13.390 --> 00:47:16.660 align:middle line:84% to make the cat say with a little speech bubble, hello world. 00:47:16.660 --> 00:47:17.650 align:middle line:90% That's the output. 00:47:17.650 --> 00:47:20.875 align:middle line:84% So this super simple program already fits into this paradigm. 00:47:20.875 --> 00:47:23.500 align:middle line:84% Well, what if I want to do something a little more interesting? 00:47:23.500 --> 00:47:25.160 align:middle line:90% Let me go over here now. 00:47:25.160 --> 00:47:29.830 align:middle line:84% And let me go ahead and let's see what else can I have Scratch do for me here? 00:47:29.830 --> 00:47:32.620 align:middle line:84% It looks like there's a whole bunch of movement that I can do. 00:47:32.620 --> 00:47:34.510 align:middle line:84% It looks like there is a whole bunch of Looks 00:47:34.510 --> 00:47:36.850 align:middle line:90% I can give him with saying something. 00:47:36.850 --> 00:47:39.010 align:middle line:90% It looks like their Sound capability. 00:47:39.010 --> 00:47:41.260 align:middle line:84% Let me scroll down here to Sensing, for instance. 00:47:41.260 --> 00:47:44.438 align:middle line:84% This one's interesting, ask, what's your name, and wait. 00:47:44.438 --> 00:47:46.480 align:middle line:84% So I can maybe make this program more interactive 00:47:46.480 --> 00:47:49.260 align:middle line:84% so that I have to do something beyond just click a green flag. 00:47:49.260 --> 00:47:51.760 align:middle line:84% Well, let me go ahead and get rid of this for just a moment. 00:47:51.760 --> 00:47:54.593 align:middle line:84% And get rid of a block, you can just take it to the left and let go. 00:47:54.593 --> 00:47:55.420 align:middle line:90% And it disappears. 00:47:55.420 --> 00:47:57.190 align:middle line:90% Let me drag this one in here. 00:47:57.190 --> 00:48:00.460 align:middle line:84% And I'm fine with that, ask, whats your name, and wait. 00:48:00.460 --> 00:48:03.160 align:middle line:84% And notice over here, this puzzle piece is a little special. 00:48:03.160 --> 00:48:07.360 align:middle line:84% It comes with a sort of special dependent piece, the answer 00:48:07.360 --> 00:48:09.670 align:middle line:84% that the human has typed into their keyboard. 00:48:09.670 --> 00:48:11.450 align:middle line:90% So how do I go ahead and use this? 00:48:11.450 --> 00:48:14.740 align:middle line:90% Well, let me go back to Looks up here. 00:48:14.740 --> 00:48:18.430 align:middle line:84% Let me go ahead and say something for two seconds. 00:48:18.430 --> 00:48:20.080 align:middle line:90% And what do I want to say here? 00:48:20.080 --> 00:48:22.450 align:middle line:90% Let me go ahead and say, hello comma. 00:48:22.450 --> 00:48:26.890 align:middle line:84% And then let me go back to Sensing to get this thing. 00:48:26.890 --> 00:48:27.730 align:middle line:90% Oh, no, sorry. 00:48:27.730 --> 00:48:29.170 align:middle line:84% Let me go ahead and get one more puzzle piece. 00:48:29.170 --> 00:48:30.760 align:middle line:90% Say something else for two seconds. 00:48:30.760 --> 00:48:34.330 align:middle line:84% But notice this, I don't have to say anything there per say. 00:48:34.330 --> 00:48:36.238 align:middle line:90% I can instead go to this answer. 00:48:36.238 --> 00:48:38.530 align:middle line:84% And even though it doesn't quite look like it will fit, 00:48:38.530 --> 00:48:39.880 align:middle line:90% these blocks will grow to fill. 00:48:39.880 --> 00:48:41.800 align:middle line:90% And indeed, it feels like it's magnetic. 00:48:41.800 --> 00:48:45.520 align:middle line:84% Now I can say, hello comma, and then say so and so's name. 00:48:45.520 --> 00:48:46.820 align:middle line:90% So let's try this. 00:48:46.820 --> 00:48:49.605 align:middle line:84% Let me go ahead now and click the red stop sign, now 00:48:49.605 --> 00:48:50.980 align:middle line:90% the green flag, what's your name. 00:48:50.980 --> 00:48:53.110 align:middle line:84% I'll go ahead and type in David and hit Enter. 00:48:53.110 --> 00:48:56.620 align:middle line:90% Hello comma David. 00:48:56.620 --> 00:48:59.840 align:middle line:84% I mean, kind of underwhelming and kind of stupid, aesthetically, why? 00:48:59.840 --> 00:49:01.330 align:middle line:90% Like what rubs you the wrong way? 00:49:01.330 --> 00:49:02.860 align:middle line:90% AUDIENCE: It's too long. 00:49:02.860 --> 00:49:06.550 align:middle line:84% DAVID J. MALAN: It's like two seconds hello David, like I just want to say it 00:49:06.550 --> 00:49:08.390 align:middle line:90% all in one breath, if you will. 00:49:08.390 --> 00:49:11.710 align:middle line:84% But I can't type in words and then drag that puzzle piece there, 00:49:11.710 --> 00:49:15.040 align:middle line:84% because it's going to overwrite or fill the white oval. 00:49:15.040 --> 00:49:16.120 align:middle line:90% So what can I do? 00:49:16.120 --> 00:49:17.560 align:middle line:84% Well, if you start to poke around-- and this 00:49:17.560 --> 00:49:19.330 align:middle line:84% is a lot of what programming is initially, 00:49:19.330 --> 00:49:22.930 align:middle line:84% just reading the documentation or googling for definitions of functions 00:49:22.930 --> 00:49:26.270 align:middle line:84% that exist you haven't heard of yet or just skimming a list like this. 00:49:26.270 --> 00:49:28.570 align:middle line:84% Well, I'm going to go down here and scroll further. 00:49:28.570 --> 00:49:32.500 align:middle line:84% Well, this is a little weird for a default example, join apple and banana. 00:49:32.500 --> 00:49:34.993 align:middle line:84% But those are just sample words that you can plug in. 00:49:34.993 --> 00:49:37.660 align:middle line:84% So you know what I'm going to do, I'm going to grab this answer. 00:49:37.660 --> 00:49:38.530 align:middle line:90% And I'm going to move-- 00:49:38.530 --> 00:49:39.850 align:middle line:84% I'm going to get rid of the second say block, 00:49:39.850 --> 00:49:41.980 align:middle line:84% because I really just want one thing to happen. 00:49:41.980 --> 00:49:42.730 align:middle line:90% And you know what? 00:49:42.730 --> 00:49:45.700 align:middle line:84% I'm going to change apple to hello comma. 00:49:45.700 --> 00:49:48.760 align:middle line:84% And I'm going to change banana to answer. 00:49:48.760 --> 00:49:50.860 align:middle line:84% And joining is going to do what's more fancily 00:49:50.860 --> 00:49:54.005 align:middle line:84% called a concatenate, combine two things left and right. 00:49:54.005 --> 00:49:55.630 align:middle line:90% And then let me go ahead and drag this. 00:49:55.630 --> 00:49:57.730 align:middle line:84% It's going to magnetically snap into place. 00:49:57.730 --> 00:50:01.307 align:middle line:84% And now I think we have the right idea, what's your name. 00:50:01.307 --> 00:50:02.140 align:middle line:90% Let me try it again. 00:50:02.140 --> 00:50:03.160 align:middle line:90% David. 00:50:03.160 --> 00:50:04.810 align:middle line:90% Hello comma David. 00:50:04.810 --> 00:50:08.860 align:middle line:84% But notice how we're sort of building up almost vertically on the program 00:50:08.860 --> 00:50:12.220 align:middle line:84% by nesting and nesting and kind of stacking these puzzle pieces. 00:50:12.220 --> 00:50:13.150 align:middle line:90% But that's OK. 00:50:13.150 --> 00:50:14.800 align:middle line:90% And notice here what's happening. 00:50:14.800 --> 00:50:18.700 align:middle line:84% So this puzzle piece here, Ask, is somehow asking the user for input 00:50:18.700 --> 00:50:22.030 align:middle line:84% and then returning it in some sense, handing it back in a variable 00:50:22.030 --> 00:50:23.810 align:middle line:90% as we'll call it called Answer. 00:50:23.810 --> 00:50:26.950 align:middle line:84% So in computer science and programming, we don't call variables x, y, z. 00:50:26.950 --> 00:50:30.460 align:middle line:84% Typically, we give them actual names that are more descriptive, like Answer. 00:50:30.460 --> 00:50:32.660 align:middle line:90% So here is a variable storing an answer. 00:50:32.660 --> 00:50:34.233 align:middle line:90% And we can now use that here. 00:50:34.233 --> 00:50:35.025 align:middle line:90% Well, what is Join? 00:50:35.025 --> 00:50:37.570 align:middle line:84% Join is another function, an action or verb, 00:50:37.570 --> 00:50:40.390 align:middle line:84% that's going to join two inputs together and create 00:50:40.390 --> 00:50:42.640 align:middle line:90% one new output like hello comma David. 00:50:42.640 --> 00:50:46.210 align:middle line:84% That output can become some other function's input, 00:50:46.210 --> 00:50:47.920 align:middle line:90% hence the stacking that I'm doing. 00:50:47.920 --> 00:50:53.530 align:middle line:84% So hello comma David is what's actually passed into the Say function. 00:50:53.530 --> 00:50:55.773 align:middle line:84% And that's why I see my name ultimately printed. 00:50:55.773 --> 00:50:58.190 align:middle line:84% So if we break this down into the same paradigm as before, 00:50:58.190 --> 00:51:00.790 align:middle line:84% if we start with problem solving as before, 00:51:00.790 --> 00:51:04.120 align:middle line:84% the input initially to the Ask block is, what's your name. 00:51:04.120 --> 00:51:06.580 align:middle line:84% And the algorithm in question is, of course, ask. 00:51:06.580 --> 00:51:10.150 align:middle line:84% The output of that is whatever the human's answer was stored in this thing 00:51:10.150 --> 00:51:13.300 align:middle line:84% called a variable, just by Scratch for me automatically. 00:51:13.300 --> 00:51:16.960 align:middle line:84% Well, then if I consider the second line of code, there's two inputs, 00:51:16.960 --> 00:51:17.757 align:middle line:90% and that's OK. 00:51:17.757 --> 00:51:20.590 align:middle line:84% You don't have to pass in just one input you can pass in zero or one 00:51:20.590 --> 00:51:21.820 align:middle line:90% or two or more. 00:51:21.820 --> 00:51:26.110 align:middle line:84% Hello comma and answer are my two inputs to this process. 00:51:26.110 --> 00:51:28.938 align:middle line:84% The algorithm now is going to be that join function. 00:51:28.938 --> 00:51:30.730 align:middle line:84% And it's going to figure out how to combine 00:51:30.730 --> 00:51:32.140 align:middle line:90% these two things, left and right. 00:51:32.140 --> 00:51:34.840 align:middle line:84% The output is hopefully going to be hello comma David. 00:51:34.840 --> 00:51:38.230 align:middle line:84% But now that output, if we shift it over, 00:51:38.230 --> 00:51:42.190 align:middle line:84% can become the input to some other algorithm or function. 00:51:42.190 --> 00:51:43.960 align:middle line:90% And that function here might be say. 00:51:43.960 --> 00:51:46.690 align:middle line:84% And that hopefully is going to output hello comma 00:51:46.690 --> 00:51:48.790 align:middle line:90% David right out of the cat's mouth. 00:51:48.790 --> 00:51:51.352 align:middle line:84% So again, problem solving is reduced to different forms 00:51:51.352 --> 00:51:52.810 align:middle line:90% based on the language you're using. 00:51:52.810 --> 00:51:54.160 align:middle line:84% And at the moment the language we're using 00:51:54.160 --> 00:51:55.990 align:middle line:84% is indeed this language called Scratch that 00:51:55.990 --> 00:52:01.030 align:middle line:84% allows us to program, literally, by just dragging and dropping puzzle pieces. 00:52:01.030 --> 00:52:06.430 align:middle line:84% Any questions then on these steps thus far? 00:52:06.430 --> 00:52:06.940 align:middle line:90% No. 00:52:06.940 --> 00:52:09.773 align:middle line:84% All right, well let's try something a little fancier how about this? 00:52:09.773 --> 00:52:11.920 align:middle line:84% Instead of when the green flag is clicked, 00:52:11.920 --> 00:52:14.712 align:middle line:84% let's actually make them can do something a little more interesting 00:52:14.712 --> 00:52:16.980 align:middle line:90% like play sound meow until it's done. 00:52:16.980 --> 00:52:18.960 align:middle line:90% [CAT MEOWING] 00:52:18.960 --> 00:52:22.077 align:middle line:84% OK, adorable didn't take much effort, but an adorable program. 00:52:22.077 --> 00:52:23.910 align:middle line:84% But if I wanted it to meow again, I can do-- 00:52:23.910 --> 00:52:24.452 align:middle line:90% [CAT MEOWING] 00:52:24.452 --> 00:52:25.860 align:middle line:90% --click the green flag. 00:52:25.860 --> 00:52:27.000 align:middle line:90% [CAT MEOWING] 00:52:27.000 --> 00:52:28.020 align:middle line:90% Click the green flag. 00:52:28.020 --> 00:52:29.578 align:middle line:90% This is not the most interactive. 00:52:29.578 --> 00:52:31.120 align:middle line:90% Well, it's actually very interactive. 00:52:31.120 --> 00:52:33.750 align:middle line:84% It's not the most automated program, like if you have to play-- 00:52:33.750 --> 00:52:34.292 align:middle line:90% [CAT MEOWING] 00:52:34.292 --> 00:52:36.930 align:middle line:84% --the game again every time you want to hear the cat meow. 00:52:36.930 --> 00:52:37.472 align:middle line:90% [CAT MEOWING] 00:52:37.472 --> 00:52:39.960 align:middle line:84% So what kind of programming construct or idea 00:52:39.960 --> 00:52:41.952 align:middle line:90% can we use from before to automate this? 00:52:41.952 --> 00:52:42.660 align:middle line:90% AUDIENCE: A loop. 00:52:42.660 --> 00:52:44.285 align:middle line:90% DAVID J. MALAN: Yes, some kind of loop. 00:52:44.285 --> 00:52:48.150 align:middle line:84% So if I kind of poke around in Scratch indeed under Control in orange, 00:52:48.150 --> 00:52:51.480 align:middle line:84% there's a couple of looping blocks, repeat some number of times 10 00:52:51.480 --> 00:52:53.590 align:middle line:84% by default, but I can change that, or forever. 00:52:53.590 --> 00:52:56.770 align:middle line:84% I can the cat meow forever if I do something like this. 00:52:56.770 --> 00:52:58.260 align:middle line:90% Let me grab the forever block. 00:52:58.260 --> 00:52:59.730 align:middle line:90% And I don't want to put it here. 00:52:59.730 --> 00:53:02.730 align:middle line:84% I want to logically kind of break this up and reconstitute it. 00:53:02.730 --> 00:53:03.720 align:middle line:90% Let me put it in here. 00:53:03.720 --> 00:53:06.210 align:middle line:84% And again that gap will grow to fill the block. 00:53:06.210 --> 00:53:07.890 align:middle line:90% Now let me connect it to the green flag. 00:53:07.890 --> 00:53:08.432 align:middle line:90% So that now-- 00:53:08.432 --> 00:53:11.750 align:middle line:90% [CAT MEOWING] 00:53:11.750 --> 00:53:13.885 align:middle line:84% --I mean, it's not a very happy cat perhaps. 00:53:13.885 --> 00:53:14.670 align:middle line:90% [CAT MEOWING] 00:53:14.670 --> 00:53:15.960 align:middle line:90% So maybe I should grab this. 00:53:15.960 --> 00:53:16.290 align:middle line:90% [CAT MEOWING] 00:53:16.290 --> 00:53:17.865 align:middle line:90% And notice this is all very interactive. 00:53:17.865 --> 00:53:18.407 align:middle line:90% [CAT MEOWING] 00:53:18.407 --> 00:53:21.205 align:middle line:84% Let me wait one second after playing the sound. 00:53:21.205 --> 00:53:22.400 align:middle line:90% [CAT MEOWING] 00:53:22.400 --> 00:53:25.460 align:middle line:84% Now it's a little less worrisome what the cat is doing. 00:53:25.460 --> 00:53:26.700 align:middle line:90% [CAT MEOWING] 00:53:26.700 --> 00:53:29.448 align:middle line:84% And so we now have a program that's actually using a loop. 00:53:29.448 --> 00:53:29.990 align:middle line:90% [CAT MEOWING] 00:53:29.990 --> 00:53:31.532 align:middle line:90% Well, we can use loops in other ways. 00:53:31.532 --> 00:53:33.890 align:middle line:84% Let me go ahead and open up something that I-- 00:53:33.890 --> 00:53:37.430 align:middle line:84% let's have the cat, for instance, count up here. 00:53:37.430 --> 00:53:38.180 align:middle line:90% So how about this? 00:53:38.180 --> 00:53:39.200 align:middle line:90% Let me get rid of this. 00:53:39.200 --> 00:53:40.480 align:middle line:90% Let me undo this. 00:53:40.480 --> 00:53:42.290 align:middle line:90% And let me go ahead and grab a variable. 00:53:42.290 --> 00:53:44.873 align:middle line:84% And it turns out you don't have to just use the answer that we 00:53:44.873 --> 00:53:45.831 align:middle line:90% got from the Ask block. 00:53:45.831 --> 00:53:48.706 align:middle line:84% That variable you just kind of get automatically for free in Scratch. 00:53:48.706 --> 00:53:49.680 align:middle line:90% You can make your own. 00:53:49.680 --> 00:53:51.690 align:middle line:84% So I'm going to actually create a variable here. 00:53:51.690 --> 00:53:53.420 align:middle line:90% And I'm going to call it counter. 00:53:53.420 --> 00:53:55.340 align:middle line:90% And sure, I'm going to click OK. 00:53:55.340 --> 00:53:58.190 align:middle line:84% Notice, it gave me now a new orange puzzle piece called 00:53:58.190 --> 00:54:00.200 align:middle line:90% counter that I can now use somewhere. 00:54:00.200 --> 00:54:02.090 align:middle line:84% So it also gave me these other orange puzzle 00:54:02.090 --> 00:54:03.792 align:middle line:90% pieces, like set counter to zero. 00:54:03.792 --> 00:54:05.000 align:middle line:90% And that's what I want to do. 00:54:05.000 --> 00:54:05.917 align:middle line:90% I don't want to just-- 00:54:05.917 --> 00:54:08.660 align:middle line:84% I want to write a program now in a loop just counts upward. 00:54:08.660 --> 00:54:11.110 align:middle line:84% So to do this, I'm going to grab that and set the counter 00:54:11.110 --> 00:54:13.550 align:middle line:90% to equal to 0, then forever. 00:54:13.550 --> 00:54:17.630 align:middle line:84% I'm going to go ahead and what I'm going to save the value of that counter. 00:54:17.630 --> 00:54:19.220 align:middle line:90% So I'm going to drag this in here. 00:54:19.220 --> 00:54:20.730 align:middle line:90% 2 seconds is going to take too long. 00:54:20.730 --> 00:54:22.610 align:middle line:90% So let's just change it to 1 second. 00:54:22.610 --> 00:54:26.150 align:middle line:84% Now I'm going to go back to my variable category. 00:54:26.150 --> 00:54:29.000 align:middle line:84% And I'm just going to drag this one in here, just as I did before 00:54:29.000 --> 00:54:30.710 align:middle line:90% with like hello, my name. 00:54:30.710 --> 00:54:35.180 align:middle line:84% And then sure, I'll go ahead and wait 1 second just to slow things down. 00:54:35.180 --> 00:54:36.972 align:middle line:84% And then I'm going to go back to variables. 00:54:36.972 --> 00:54:39.097 align:middle line:84% And again, I'm doing this quickly only because I've 00:54:39.097 --> 00:54:40.530 align:middle line:90% kind of tinkered with this before. 00:54:40.530 --> 00:54:42.530 align:middle line:90% I'm going to change the counter by 1. 00:54:42.530 --> 00:54:44.480 align:middle line:90% So notice I've made a fancier program. 00:54:44.480 --> 00:54:47.030 align:middle line:84% But logically, it's just going to set the counter to 0. 00:54:47.030 --> 00:54:50.360 align:middle line:84% And then it's forever going to say the counter's value, wait a second, 00:54:50.360 --> 00:54:54.182 align:middle line:84% change the counter by 1, then do it again and again and again and again. 00:54:54.182 --> 00:54:55.640 align:middle line:90% There won't be any sound this time. 00:54:55.640 --> 00:54:59.750 align:middle line:84% But we will see that Scratch in this way can count, it would seem, from 0 00:54:59.750 --> 00:55:02.540 align:middle line:90% on up to infinity, theoretically. 00:55:02.540 --> 00:55:06.430 align:middle line:84% But we'll see that infinity-- things tend to break as you approach infinity 00:55:06.430 --> 00:55:07.340 align:middle line:90% in most programs. 00:55:07.340 --> 00:55:09.132 align:middle line:90% But more on that before long. 00:55:09.132 --> 00:55:11.840 align:middle line:84% Well, let me go ahead and open a few that I brought with me here. 00:55:11.840 --> 00:55:14.870 align:middle line:84% In fact, on the course's website, you'll see for every lecture, 00:55:14.870 --> 00:55:17.690 align:middle line:84% whether here or online, all of the materials that we use 00:55:17.690 --> 00:55:20.340 align:middle line:84% and what I'm doing is running source code, programming code. 00:55:20.340 --> 00:55:24.560 align:middle line:84% And if I click on Studio here, I'll actually see all of the code 00:55:24.560 --> 00:55:26.170 align:middle line:90% that I brought with me today. 00:55:26.170 --> 00:55:29.750 align:middle line:84% And I'm going to go ahead and open up an example now called Pet. 00:55:29.750 --> 00:55:32.180 align:middle line:84% What about a program now that synthesizes those two ideas 00:55:32.180 --> 00:55:35.600 align:middle line:84% using sound in a loop, but also using that loop 00:55:35.600 --> 00:55:37.250 align:middle line:90% to do something again and again? 00:55:37.250 --> 00:55:39.350 align:middle line:84% Well, let me go ahead and see what happens here. 00:55:39.350 --> 00:55:40.892 align:middle line:90% I'm going to go ahead and See Inside. 00:55:40.892 --> 00:55:42.920 align:middle line:84% And you can actually see the code in question. 00:55:42.920 --> 00:55:45.050 align:middle line:90% And now watch this. 00:55:45.050 --> 00:55:49.280 align:middle line:84% I've clicked the green flag, but nothing seems to be happening. 00:55:49.280 --> 00:55:51.022 align:middle line:90% What should I do? 00:55:51.022 --> 00:55:52.730 align:middle line:84% And I clearly wrote this program already. 00:55:52.730 --> 00:55:54.200 align:middle line:90% AUDIENCE: Put the mouse over the cat. 00:55:54.200 --> 00:55:56.070 align:middle line:84% DAVID J. MALAN: Yeah, I should put the mouse over the cat it seems. 00:55:56.070 --> 00:55:56.570 align:middle line:90% Why? 00:55:56.570 --> 00:55:59.670 align:middle line:84% Because it says forever ask the following question 00:55:59.670 --> 00:56:03.410 align:middle line:84% if you're touching mouse pointer, then play the sound meow until done. 00:56:03.410 --> 00:56:04.160 align:middle line:90% So let's try that. 00:56:04.160 --> 00:56:04.730 align:middle line:90% Here we go. 00:56:04.730 --> 00:56:06.880 align:middle line:90% [CAT MEOWING] 00:56:06.880 --> 00:56:07.890 align:middle line:90% Ah, so now it's like-- 00:56:07.890 --> 00:56:09.015 align:middle line:90% now it is more interactive. 00:56:09.015 --> 00:56:09.390 align:middle line:90% [CAT MEOWING] 00:56:09.390 --> 00:56:11.640 align:middle line:84% And you're sort of petting the cat with your cursor. 00:56:11.640 --> 00:56:14.080 align:middle line:90% [CAT MEOWING] 00:56:14.080 --> 00:56:16.410 align:middle line:84% But if you hold it there, gets a little noise. 00:56:16.410 --> 00:56:17.040 align:middle line:90% [CAT MEOWING] 00:56:17.040 --> 00:56:20.070 align:middle line:84% Let me go ahead and open a slightly different one, Pet1. 00:56:20.070 --> 00:56:22.530 align:middle line:84% Notice, I'm starting to count zero, just as I did here, 00:56:22.530 --> 00:56:25.572 align:middle line:84% just because that's a computer science convention to start counting at 0. 00:56:25.572 --> 00:56:27.283 align:middle line:90% So Pet1 is now my second example. 00:56:27.283 --> 00:56:28.950 align:middle line:90% Let me go ahead and see inside this one. 00:56:28.950 --> 00:56:30.117 align:middle line:90% It's a little more involved. 00:56:30.117 --> 00:56:31.330 align:middle line:90% [CAT MEOWING] 00:56:31.330 --> 00:56:33.230 align:middle line:90% What should I perhaps not do this time? 00:56:33.230 --> 00:56:37.757 align:middle line:90% [CAT MEOWING] 00:56:37.757 --> 00:56:38.590 align:middle line:90% It's a little small. 00:56:38.590 --> 00:56:39.280 align:middle line:90% Let me zoom in. 00:56:39.280 --> 00:56:44.570 align:middle line:90% [CAT MEOWING] 00:56:44.570 --> 00:56:45.888 align:middle line:90% All right, so now logically-- 00:56:45.888 --> 00:56:46.430 align:middle line:90% [CAT MEOWING] 00:56:46.430 --> 00:56:49.130 align:middle line:84% --it seems clear that I shouldn't, for instance do-- 00:56:49.130 --> 00:56:50.280 align:middle line:90% [LION ROARING] 00:56:50.280 --> 00:56:50.780 align:middle line:90% --that. 00:56:50.780 --> 00:56:51.530 align:middle line:90% [CAT MEOWING] 00:56:51.530 --> 00:56:53.540 align:middle line:84% So don't pet the cat in that particular case. 00:56:53.540 --> 00:56:56.040 align:middle line:84% But again, notice, all we're doing, even though the programs 00:56:56.040 --> 00:56:59.270 align:middle line:84% are getting a little more fancy and a little more involved, 00:56:59.270 --> 00:57:02.480 align:middle line:84% I'm just composing more advanced algorithms using all 00:57:02.480 --> 00:57:03.980 align:middle line:90% of these individual building blocks. 00:57:03.980 --> 00:57:07.410 align:middle line:84% We can make a really adorable cat, for instance, do this. 00:57:07.410 --> 00:57:09.710 align:middle line:84% Let me go ahead and repeat the following forever. 00:57:09.710 --> 00:57:12.380 align:middle line:84% Let me go ahead and find the Motion block. 00:57:12.380 --> 00:57:15.980 align:middle line:84% And I'm going to go ahead and point towards the mouse pointer my, cursor. 00:57:15.980 --> 00:57:18.610 align:middle line:84% And then I'm going to go ahead and use this one, move 10 steps. 00:57:18.610 --> 00:57:20.360 align:middle line:84% But I'm going to do it one step at a time. 00:57:20.360 --> 00:57:22.340 align:middle line:84% A step is like dots on the screen, pixels. 00:57:22.340 --> 00:57:25.430 align:middle line:84% So one step means at one dot at a time, instead of 10. 00:57:25.430 --> 00:57:26.750 align:middle line:90% Let me play this. 00:57:26.750 --> 00:57:30.616 align:middle line:84% And now we have sort of a cat that follows me. 00:57:30.616 --> 00:57:32.840 align:middle line:90% But I'm much faster than him. 00:57:32.840 --> 00:57:36.710 align:middle line:84% And so I could, for instance stop this, have him work faster, 00:57:36.710 --> 00:57:38.060 align:middle line:90% and do 10 times as many things. 00:57:38.060 --> 00:57:41.570 align:middle line:84% And now he'll actually follow my cursor until he gets there. 00:57:41.570 --> 00:57:43.940 align:middle line:84% And now this is kind of a bug or my mistake, 00:57:43.940 --> 00:57:46.205 align:middle line:84% right, like he's apparently going just past my cursor. 00:57:46.205 --> 00:57:47.330 align:middle line:90% So then he's doubling back. 00:57:47.330 --> 00:57:48.380 align:middle line:90% But then he's gone just too far. 00:57:48.380 --> 00:57:49.340 align:middle line:90% So he's doubling back. 00:57:49.340 --> 00:57:50.490 align:middle line:90% So this is a bug. 00:57:50.490 --> 00:57:52.820 align:middle line:84% And it's because I'm taking 10 steps at a time. 00:57:52.820 --> 00:57:56.075 align:middle line:84% It's kind of jumping over my cursor, in this case here. 00:57:56.075 --> 00:57:58.700 align:middle line:84% Well, let's go ahead and make something a little more involved. 00:57:58.700 --> 00:58:01.225 align:middle line:84% Let me go ahead and open this one, Bounce0. 00:58:01.225 --> 00:58:04.100 align:middle line:84% So I'm going to go ahead and open this one, just as you can do later. 00:58:04.100 --> 00:58:10.150 align:middle line:84% Bounce0 takes that same idea, but automates it this time. 00:58:10.150 --> 00:58:14.130 align:middle line:84% So this is kind of interesting, because it's now responding to its environment. 00:58:14.130 --> 00:58:17.850 align:middle line:84% And if I zoom in there, notice that it's still the same amount of movement idea, 00:58:17.850 --> 00:58:19.330 align:middle line:90% but it's not following my cursor. 00:58:19.330 --> 00:58:21.372 align:middle line:84% But it is asking the question, if you're touching 00:58:21.372 --> 00:58:25.690 align:middle line:84% the edge, a Boolean expression, turn yourself around 180 degrees. 00:58:25.690 --> 00:58:28.380 align:middle line:84% Now we could do something kind of interesting there. 00:58:28.380 --> 00:58:31.770 align:middle line:84% Notice that in Scratch, and now this has less academic value, 00:58:31.770 --> 00:58:33.600 align:middle line:90% has this ability to play with sounds. 00:58:33.600 --> 00:58:39.000 align:middle line:84% And if I go in here for instance and Add Sound, oops, not Search for Sound. 00:58:39.000 --> 00:58:45.010 align:middle line:84% And I go ahead and Record Sound and allow my microphone to be used again. 00:58:45.010 --> 00:58:46.330 align:middle line:90% Ouch. 00:58:46.330 --> 00:58:50.190 align:middle line:84% OK that's what the word Ouch looks like apparently in a computer. 00:58:50.190 --> 00:58:52.560 align:middle line:84% And now let me go ahead and go back to code. 00:58:52.560 --> 00:58:57.690 align:middle line:84% And now if I go to Sound, you'll see play sound meow until done. 00:58:57.690 --> 00:58:58.370 align:middle line:90% That's fine. 00:58:58.370 --> 00:59:01.710 align:middle line:84% But what I actually want to do is play sound recording 1. 00:59:01.710 --> 00:59:04.020 align:middle line:84% That was the default name I just gave it. 00:59:04.020 --> 00:59:05.690 align:middle line:90% So now. 00:59:05.690 --> 00:59:07.570 align:middle line:90% Ouch. 00:59:07.570 --> 00:59:08.910 align:middle line:90% Ouch. 00:59:08.910 --> 00:59:09.410 align:middle line:90% Ouch. 00:59:09.410 --> 00:59:09.910 align:middle line:90% [LAUGHTER] 00:59:09.910 --> 00:59:12.927 align:middle line:84% OK, so we can do even more than that there. 00:59:12.927 --> 00:59:14.760 align:middle line:84% But you know what this looks a little silly. 00:59:14.760 --> 00:59:16.560 align:middle line:90% So, you know, the sound aside. 00:59:16.560 --> 00:59:17.550 align:middle line:90% Ouch. 00:59:17.550 --> 00:59:20.470 align:middle line:90% He's not really-- ouch-- walking-- 00:59:20.470 --> 00:59:22.440 align:middle line:90% ouch-- right, he's not really walking. 00:59:22.440 --> 00:59:24.360 align:middle line:84% He's just kind of sliding across the screen. 00:59:24.360 --> 00:59:25.110 align:middle line:90% But you know what? 00:59:25.110 --> 00:59:27.600 align:middle line:84% What is just walking well walking is really just animation. 00:59:27.600 --> 00:59:29.892 align:middle line:84% And if this is what the cat looks like by default. What 00:59:29.892 --> 00:59:33.210 align:middle line:84% if I use some graphic artistry and just kind of give him another look, 00:59:33.210 --> 00:59:34.753 align:middle line:90% another costume as Scratch calls it. 00:59:34.753 --> 00:59:35.670 align:middle line:90% And now I'm in slides. 00:59:35.670 --> 00:59:38.910 align:middle line:84% I'm just going to go back and forth left and right, first, second, first, 00:59:38.910 --> 00:59:39.540 align:middle line:90% second. 00:59:39.540 --> 00:59:42.360 align:middle line:84% And if I do this, you know, now it kind of looks like he's walking. 00:59:42.360 --> 00:59:43.860 align:middle line:90% This is like a really bad flip book. 00:59:43.860 --> 00:59:47.370 align:middle line:84% Like you have every page he just moves like halfway toward his step. 00:59:47.370 --> 00:59:50.262 align:middle line:84% But that's really all animation is, is tricking our human eyes 00:59:50.262 --> 00:59:52.470 align:middle line:84% into thinking that something's happening in real time 00:59:52.470 --> 00:59:55.528 align:middle line:84% when really you're just seeing photographs fly by your eyes. 00:59:55.528 --> 00:59:56.820 align:middle line:90% But I can go ahead and do this. 00:59:56.820 --> 01:00:01.530 align:middle line:84% So in fact if I go into Bounce1, I did this in advance already here. 01:00:01.530 --> 01:00:04.170 align:middle line:84% And this one's just a little fancier, such 01:00:04.170 --> 01:00:07.460 align:middle line:90% that now he's really moving, right? 01:00:07.460 --> 01:00:11.510 align:middle line:84% And if you really want to see it, we can move just five steps at a time. 01:00:11.510 --> 01:00:14.430 align:middle line:90% 01:00:14.430 --> 01:00:18.520 align:middle line:84% Actually that's-- oops, not 51, 1 step at a time. 01:00:18.520 --> 01:00:21.960 align:middle line:84% And he's moving slower, but now it's changing costume a little too fast. 01:00:21.960 --> 01:00:24.900 align:middle line:84% So it's only once we kind of find the sweet spot, maybe 50 step, OK, 01:00:24.900 --> 01:00:25.900 align:middle line:90% now a little too fast. 01:00:25.900 --> 01:00:26.910 align:middle line:90% [LAUGHTER] 01:00:26.910 --> 01:00:29.220 align:middle line:84% But this is all animation is, whether you're doing it 01:00:29.220 --> 01:00:32.037 align:middle line:84% in software or manually or flip book style, 01:00:32.037 --> 01:00:34.620 align:middle line:84% you just have this ability to create now the notion of motion. 01:00:34.620 --> 01:00:35.730 align:middle line:90% But there's some other features too. 01:00:35.730 --> 01:00:37.830 align:middle line:84% We've seen variables as I mentioned before. 01:00:37.830 --> 01:00:41.490 align:middle line:84% But it turns out we can take advantage of fancier techniques in programming 01:00:41.490 --> 01:00:43.952 align:middle line:90% as well, like in the sea lion here. 01:00:43.952 --> 01:00:46.410 align:middle line:84% So this one's interesting because this is the first Scratch 01:00:46.410 --> 01:00:48.300 align:middle line:84% program for which I kind of have to scroll 01:00:48.300 --> 01:00:50.850 align:middle line:84% to see two different algorithms, both of which 01:00:50.850 --> 01:00:52.980 align:middle line:84% are going to run when the green flag is clicked. 01:00:52.980 --> 01:00:54.540 align:middle line:84% And we won't get into the weeds of the code. 01:00:54.540 --> 01:00:55.560 align:middle line:90% All the code is online. 01:00:55.560 --> 01:00:58.410 align:middle line:84% And for the first problem set you'll be able to take a closer look. 01:00:58.410 --> 01:01:00.180 align:middle line:84% But notice what happens with this program. 01:01:00.180 --> 01:01:01.770 align:middle line:90% [SEA LION BARKING] 01:01:01.770 --> 01:01:02.415 align:middle line:90% He just barks-- 01:01:02.415 --> 01:01:03.290 align:middle line:90% [SEA LION BARKING] 01:01:03.290 --> 01:01:05.280 align:middle line:90% --endlessly in a loop-- 01:01:05.280 --> 01:01:06.390 align:middle line:90% [SEA LION BARKING] 01:01:06.390 --> 01:01:10.680 align:middle line:84% --because, notice this, there is this forever block down here. 01:01:10.680 --> 01:01:11.430 align:middle line:90% [SEA LION BARKING] 01:01:11.430 --> 01:01:11.985 align:middle line:90% This is annoying. 01:01:11.985 --> 01:01:12.735 align:middle line:90% [SEA LION BARKING] 01:01:12.735 --> 01:01:15.960 align:middle line:84% And if you can read the code, how can I stop him from barking? 01:01:15.960 --> 01:01:16.780 align:middle line:90% [SEA LION BARKING] 01:01:16.780 --> 01:01:18.010 align:middle line:90% AUDIENCE: The space bar. 01:01:18.010 --> 01:01:18.290 align:middle line:90% DAVID J. MALAN: Yeah. 01:01:18.290 --> 01:01:18.540 align:middle line:90% [SEA LION BARKING] 01:01:18.540 --> 01:01:20.130 align:middle line:90% There seems to be the space bar. 01:01:20.130 --> 01:01:20.880 align:middle line:90% [SEA LION BARKING] 01:01:20.880 --> 01:01:23.895 align:middle line:84% If key space is pressed, set a variable called muted to true. 01:01:23.895 --> 01:01:24.690 align:middle line:90% [SEA LION BARKING] 01:01:24.690 --> 01:01:26.250 align:middle line:90% Rather check if muted is true. 01:01:26.250 --> 01:01:27.000 align:middle line:90% [SEA LION BARKING] 01:01:27.000 --> 01:01:28.380 align:middle line:90% And if so change it to false. 01:01:28.380 --> 01:01:29.130 align:middle line:90% [SEA LION BARKING] 01:01:29.130 --> 01:01:30.335 align:middle line:90% Else set it to true. 01:01:30.335 --> 01:01:31.085 align:middle line:90% [SEA LION BARKING] 01:01:31.085 --> 01:01:34.593 align:middle line:90% So if I hit the space bar, now he stops. 01:01:34.593 --> 01:01:36.010 align:middle line:90% But I haven't stopped the program. 01:01:36.010 --> 01:01:37.090 align:middle line:90% If I hit the space bar again-- 01:01:37.090 --> 01:01:37.450 align:middle line:90% [SEA LION BARKING] 01:01:37.450 --> 01:01:38.560 align:middle line:90% --he's still going. 01:01:38.560 --> 01:01:41.080 align:middle line:84% But what I'm doing is I'm changing a variable called 01:01:41.080 --> 01:01:44.260 align:middle line:90% muted to true or false to 1 or 0. 01:01:44.260 --> 01:01:47.620 align:middle line:84% And then up above in my code, I'm actually checking here. 01:01:47.620 --> 01:01:51.400 align:middle line:84% If muted is false, then play the sea lion sound. 01:01:51.400 --> 01:01:53.947 align:middle line:84% So if it's not muted, go ahead and play the sound. 01:01:53.947 --> 01:01:56.530 align:middle line:84% So it's a way of creating your own questions that you yourself 01:01:56.530 --> 01:02:00.280 align:middle line:84% can answer ultimately, so that you can finally have more interactivity. 01:02:00.280 --> 01:02:04.630 align:middle line:84% And speaking of interactivity too, if you ever played the game Marco Polo 01:02:04.630 --> 01:02:08.110 align:middle line:84% in like a pool as a kid, for instance, it's this game where one person-- 01:02:08.110 --> 01:02:11.558 align:middle line:84% everyone-- one kid like covers his or her eyes, and then everyone-- 01:02:11.558 --> 01:02:14.350 align:middle line:84% they yell out Marco-- and I look like an idiot right now, don't I-- 01:02:14.350 --> 01:02:16.660 align:middle line:90% and then everyone else yells out polo. 01:02:16.660 --> 01:02:21.250 align:middle line:84% And you try to find the other person in an otherwise dark space or pool space 01:02:21.250 --> 01:02:22.600 align:middle line:90% with your eyes closed. 01:02:22.600 --> 01:02:26.740 align:middle line:84% So if I go ahead and play this now, notice what if I hit the space bar now, 01:02:26.740 --> 01:02:31.038 align:middle line:84% the orange puppet says Marco and then the blue puppet says Polo. 01:02:31.038 --> 01:02:32.830 align:middle line:84% Now it's not hard to implement that in code 01:02:32.830 --> 01:02:35.990 align:middle line:84% with just one single script, as Scratch calls it. 01:02:35.990 --> 01:02:39.670 align:middle line:84% But notice that each sprite here can have its own scripts. 01:02:39.670 --> 01:02:41.830 align:middle line:90% This is the orange Muppet script. 01:02:41.830 --> 01:02:44.178 align:middle line:90% This is the blue one's script as well. 01:02:44.178 --> 01:02:45.970 align:middle line:84% So notice that what the orange guy is doing 01:02:45.970 --> 01:02:49.900 align:middle line:84% is this, if the key space is pressed, say Marco for two seconds. 01:02:49.900 --> 01:02:52.793 align:middle line:84% But other sprites, other characters, can't just 01:02:52.793 --> 01:02:54.460 align:middle line:90% look on the screen for what's happening. 01:02:54.460 --> 01:02:57.170 align:middle line:84% They have to be communicated with more programmatically. 01:02:57.170 --> 01:03:00.160 align:middle line:84% So there's this notion in computer science called events. 01:03:00.160 --> 01:03:03.310 align:middle line:84% This puppet can broadcast an event, which is like a secret message 01:03:03.310 --> 01:03:05.440 align:middle line:90% that only computers can hear. 01:03:05.440 --> 01:03:09.310 align:middle line:84% And the blue puppet, notice, can be listening for that event. 01:03:09.310 --> 01:03:12.280 align:middle line:84% And he can respond, not when the green flag 01:03:12.280 --> 01:03:14.560 align:middle line:84% is clicked, but to a different event when he 01:03:14.560 --> 01:03:17.900 align:middle line:90% receives this event from someone else. 01:03:17.900 --> 01:03:22.060 align:middle line:84% So you can have multiple characters on your screen somehow intercommunicating 01:03:22.060 --> 01:03:24.140 align:middle line:90% in this way, as well. 01:03:24.140 --> 01:03:28.060 align:middle line:84% And lastly, let's go ahead and take a look at this here. 01:03:28.060 --> 01:03:31.090 align:middle line:84% I'm going to go ahead and open up an example of coughing, 01:03:31.090 --> 01:03:33.100 align:middle line:90% so kind of a simple example. 01:03:33.100 --> 01:03:35.770 align:middle line:84% And this example of coughing just has a sprite doing something 01:03:35.770 --> 01:03:40.390 align:middle line:90% like this, cough, cough, cough. 01:03:40.390 --> 01:03:41.050 align:middle line:90% It works. 01:03:41.050 --> 01:03:43.300 align:middle line:84% It's correct, if my goal was to cough three times. 01:03:43.300 --> 01:03:46.480 align:middle line:84% But it's poorly designed, right, like even knowing what we know already, 01:03:46.480 --> 01:03:48.930 align:middle line:84% you can kind of imagine doing this better using what? 01:03:48.930 --> 01:03:49.750 align:middle line:90% AUDIENCE: A loop. 01:03:49.750 --> 01:03:51.490 align:middle line:90% DAVID J. MALAN: Yeah, so using a loop. 01:03:51.490 --> 01:03:56.040 align:middle line:84% So in fact in Cough1, which is a newer version of this, it's the same idea. 01:03:56.040 --> 01:03:57.600 align:middle line:90% Let me See Inside. 01:03:57.600 --> 01:03:58.530 align:middle line:90% Let me hit Play. 01:03:58.530 --> 01:03:59.852 align:middle line:90% It does the same thing. 01:03:59.852 --> 01:04:02.310 align:middle line:84% But notice that I'm using the repeat block, so not forever, 01:04:02.310 --> 01:04:04.018 align:middle line:84% because I only want to cough three times. 01:04:04.018 --> 01:04:05.850 align:middle line:90% Forever would be bad, probably. 01:04:05.850 --> 01:04:07.350 align:middle line:90% But three times seems reasonable. 01:04:07.350 --> 01:04:08.730 align:middle line:90% But I can do it now in a loop. 01:04:08.730 --> 01:04:10.950 align:middle line:84% But notice, that if you wanted to now use 01:04:10.950 --> 01:04:13.710 align:middle line:84% this notion of coughing in like another program you write, 01:04:13.710 --> 01:04:16.002 align:middle line:84% it's a little annoying that you would just kind of copy 01:04:16.002 --> 01:04:17.725 align:middle line:84% paste these puzzle pieces again and again 01:04:17.725 --> 01:04:20.850 align:middle line:84% and again anywhere in your program when you want to make a character cough. 01:04:20.850 --> 01:04:24.930 align:middle line:84% But what Scratch provides us with has actually this capability as well. 01:04:24.930 --> 01:04:28.890 align:middle line:84% At the very bottom of Scratch is this pink piece for Make Block. 01:04:28.890 --> 01:04:31.080 align:middle line:90% You can make your own functions. 01:04:31.080 --> 01:04:35.100 align:middle line:84% You can make reusable puzzle pieces that you can then use in different places. 01:04:35.100 --> 01:04:38.818 align:middle line:84% And so, for instance, if I want to make a puzzle piece that coughs, 01:04:38.818 --> 01:04:40.860 align:middle line:84% so that I don't have to construct it from scratch 01:04:40.860 --> 01:04:44.110 align:middle line:84% like that-- no pun intended-- notice what I can do here. 01:04:44.110 --> 01:04:45.350 align:middle line:90% I can literally in Scratch-- 01:04:45.350 --> 01:04:47.850 align:middle line:84% and this may be something you use for your own problem set-- 01:04:47.850 --> 01:04:51.780 align:middle line:84% define a new pink piece called cough or whatever you want, attach 01:04:51.780 --> 01:04:54.540 align:middle line:84% some puzzle pieces below it, like say cough for 1 second, 01:04:54.540 --> 01:04:56.100 align:middle line:90% then wait for 1 second. 01:04:56.100 --> 01:05:00.790 align:middle line:84% And then you can use that puzzle piece in your own code sort of out of sight, 01:05:00.790 --> 01:05:01.530 align:middle line:90% out of mind. 01:05:01.530 --> 01:05:03.270 align:middle line:90% Now I can program like this. 01:05:03.270 --> 01:05:05.910 align:middle line:84% So a moment ago there was like five or six puzzle pieces. 01:05:05.910 --> 01:05:09.690 align:middle line:84% Now it's been whittled down to three by making my own puzzle piece 01:05:09.690 --> 01:05:12.883 align:middle line:84% cough that takes its own input and produces its own output. 01:05:12.883 --> 01:05:16.050 align:middle line:84% And suffice it to say, you can have your own functions, your own pink puzzle 01:05:16.050 --> 01:05:20.790 align:middle line:84% pieces that take one input or two inputs not just zero inputs in this case. 01:05:20.790 --> 01:05:24.600 align:middle line:84% And it's a way of modularizing your code ultimately and making 01:05:24.600 --> 01:05:27.010 align:middle line:90% it ever more usable. 01:05:27.010 --> 01:05:28.802 align:middle line:84% So that was a lot of little demonstrations. 01:05:28.802 --> 01:05:30.885 align:middle line:84% But it's worth kind of bringing this all together. 01:05:30.885 --> 01:05:32.670 align:middle line:84% Ultimately in problem set 0, the challenge 01:05:32.670 --> 01:05:34.530 align:middle line:84% ahead is going to make anything of interest 01:05:34.530 --> 01:05:37.920 align:middle line:84% to you, whether it's a game, an interactive animation, or artistic work 01:05:37.920 --> 01:05:39.360 align:middle line:90% all implemented in Scratch. 01:05:39.360 --> 01:05:42.840 align:middle line:84% And we thought we'd share with you the project from a former student here 01:05:42.840 --> 01:05:46.260 align:middle line:84% called Ivy's Hardest Game, not to intimidate. 01:05:46.260 --> 01:05:49.290 align:middle line:84% But we'd need in closing just one brave volunteer 01:05:49.290 --> 01:05:54.810 align:middle line:84% who would be comfortable playing one of your predecessor's homework assignments 01:05:54.810 --> 01:05:57.800 align:middle line:84% in front of a few people and on the internet. 01:05:57.800 --> 01:06:00.678 align:middle line:84% Hi, yeah, OK, right there in the green is it. 01:06:00.678 --> 01:06:01.470 align:middle line:90% Yeah, come on down. 01:06:01.470 --> 01:06:02.754 align:middle line:90% What's your name? 01:06:02.754 --> 01:06:04.155 align:middle line:90% AUDIENCE: Owen. 01:06:04.155 --> 01:06:05.090 align:middle line:90% DAVID J. MALAN: Owen. 01:06:05.090 --> 01:06:08.420 align:middle line:90% OK, come on down. 01:06:08.420 --> 01:06:09.295 align:middle line:90% All right yes. 01:06:09.295 --> 01:06:09.878 align:middle line:90% Encourage him. 01:06:09.878 --> 01:06:14.740 align:middle line:90% [APPLAUSE] 01:06:14.740 --> 01:06:17.515 align:middle line:90% OK, OK, sorry your name again was? 01:06:17.515 --> 01:06:18.140 align:middle line:90% AUDIENCE: Owen. 01:06:18.140 --> 01:06:18.380 align:middle line:90% DAVID J. MALAN: Owen. 01:06:18.380 --> 01:06:18.840 align:middle line:90% David. 01:06:18.840 --> 01:06:19.548 align:middle line:90% Nice to meet you. 01:06:19.548 --> 01:06:20.300 align:middle line:90% Come on around. 01:06:20.300 --> 01:06:22.258 align:middle line:84% I'm going to go ahead and full screen the game. 01:06:22.258 --> 01:06:23.570 align:middle line:90% We won't actually look inside. 01:06:23.570 --> 01:06:25.960 align:middle line:84% I'm going to go ahead and click the green flag. 01:06:25.960 --> 01:06:29.360 align:middle line:84% And you're just going to use the keyboard ultimately to play this game. 01:06:29.360 --> 01:06:30.821 align:middle line:90% [MUSIC PLAYING - NFL THEME SONG] 01:06:30.821 --> 01:06:33.256 align:middle line:84% OK, you can raise the volume a little bit, Brian. 01:06:33.256 --> 01:06:35.691 align:middle line:90% [MUSIC PLAYING - NFL THEME SONG] 01:06:35.691 --> 01:06:36.908 align:middle line:90% Oh, yeah. 01:06:36.908 --> 01:06:39.075 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:06:39.075 --> 01:06:41.070 align:middle line:90% (SINGING) Can't touch this. 01:06:41.070 --> 01:06:42.232 align:middle line:90% Can't touch this. 01:06:42.232 --> 01:06:44.877 align:middle line:90% 01:06:44.877 --> 01:06:46.738 align:middle line:90% AUDIENCE: I move cursor to the right? 01:06:46.738 --> 01:06:48.280 align:middle line:90% DAVID J. MALAN: So you'll notice now. 01:06:48.280 --> 01:06:51.357 align:middle line:84% I'll explain the pedagogy ultimately of what you're now doing here. 01:06:51.357 --> 01:06:53.524 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:06:53.524 --> 01:06:54.295 align:middle line:90% [LAUGHTER] 01:06:54.295 --> 01:06:55.420 align:middle line:90% So what is the Yale symbol? 01:06:55.420 --> 01:06:57.610 align:middle line:84% Now it's wearing a costume that's not a cat. 01:06:57.610 --> 01:07:00.340 align:middle line:90% It's instead the Y, Yale logo. 01:07:00.340 --> 01:07:02.720 align:middle line:84% There's a second sprite, MC Hammer at the end. 01:07:02.720 --> 01:07:05.500 align:middle line:84% He's the one who's trying to touch with the other sprite. 01:07:05.500 --> 01:07:09.130 align:middle line:84% There's now two more crimson sprites, Harvard logos. 01:07:09.130 --> 01:07:11.890 align:middle line:84% Each of which has its own puzzle pieces all operating 01:07:11.890 --> 01:07:13.810 align:middle line:90% when the green flag started. 01:07:13.810 --> 01:07:15.244 align:middle line:90% There he goes. 01:07:15.244 --> 01:07:15.744 align:middle line:90% [LAUGHTER] 01:07:15.744 --> 01:07:21.010 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:07:21.010 --> 01:07:24.110 align:middle line:84% And notice, Owen is not able to go past the black walls. 01:07:24.110 --> 01:07:24.610 align:middle line:90% [LAUGHTER] 01:07:24.610 --> 01:07:26.005 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:07:26.005 --> 01:07:26.935 align:middle line:90% AUDIENCE: Aah. 01:07:26.935 --> 01:07:29.732 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:07:29.732 --> 01:07:31.190 align:middle line:90% DAVID J. MALAN: OK, here comes MIT. 01:07:31.190 --> 01:07:35.600 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:07:35.600 --> 01:07:37.560 align:middle line:90% AUDIENCE: Aah. 01:07:37.560 --> 01:07:42.970 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:07:42.970 --> 01:07:46.780 align:middle line:84% DAVID J. MALAN: You'll notice the MIT sprite is a little smarter, 01:07:46.780 --> 01:07:50.340 align:middle line:90% artificial intelligence, if you will. 01:07:50.340 --> 01:07:52.360 align:middle line:90% Nice. 01:07:52.360 --> 01:07:53.300 align:middle line:90% AUDIENCE: Aah. 01:07:53.300 --> 01:07:56.870 align:middle line:84% DAVID J. MALAN: OK, the walls are now gone, 01:07:56.870 --> 01:08:00.285 align:middle line:84% so there is no if touching edge, then bounce anymore. 01:08:00.285 --> 01:08:00.785 align:middle line:90% Nice. 01:08:00.785 --> 01:08:04.580 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:08:04.580 --> 01:08:06.390 align:middle line:90% [LAUGHTER] 01:08:06.390 --> 01:08:06.890 align:middle line:90% Nice. 01:08:06.890 --> 01:08:09.610 align:middle line:90% 01:08:09.610 --> 01:08:11.250 align:middle line:90% Two of them. 01:08:11.250 --> 01:08:13.857 align:middle line:84% Notice they're clearly pointing toward him. 01:08:13.857 --> 01:08:14.440 align:middle line:90% AUDIENCE: Aah. 01:08:14.440 --> 01:08:18.189 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:08:18.189 --> 01:08:19.250 align:middle line:90% DAVID J. MALAN: Nice. 01:08:19.250 --> 01:08:20.887 align:middle line:90% Oh. 01:08:20.887 --> 01:08:21.729 align:middle line:90% AUDIENCE: Aah. 01:08:21.729 --> 01:08:24.300 align:middle line:90% DAVID J. MALAN: Hang in there. 01:08:24.300 --> 01:08:26.550 align:middle line:90% Class might run a minute or two late. 01:08:26.550 --> 01:08:27.180 align:middle line:90% Nice. 01:08:27.180 --> 01:08:28.125 align:middle line:90% Second to last level. 01:08:28.125 --> 01:08:31.770 align:middle line:90% 01:08:31.770 --> 01:08:33.010 align:middle line:90% Yes. 01:08:33.010 --> 01:08:33.510 align:middle line:90% All right. 01:08:33.510 --> 01:08:41.478 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:08:41.478 --> 01:08:44.069 align:middle line:90% Oh, Dartmouth got you. 01:08:44.069 --> 01:08:46.457 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:08:46.457 --> 01:08:47.790 align:middle line:90% Hang in there, a few more lives. 01:08:47.790 --> 01:08:51.779 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] 01:08:51.779 --> 01:08:52.479 align:middle line:90% Hang in there. 01:08:52.479 --> 01:08:55.562 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] (SINGING) Can't touch 01:08:55.562 --> 01:08:56.310 align:middle line:90% this. 01:08:56.310 --> 01:08:57.609 align:middle line:90% Yes. 01:08:57.609 --> 01:08:58.566 align:middle line:90% Yes. 01:08:58.566 --> 01:08:59.359 align:middle line:90% AUDIENCE: Aah. 01:08:59.359 --> 01:09:00.040 align:middle line:90% DAVID J. MALAN: One more try. 01:09:00.040 --> 01:09:00.770 align:middle line:90% One more try. 01:09:00.770 --> 01:09:02.939 align:middle line:84% [MUSIC PLAYING - MC HAMMER, "YOU CAN'T TOUCH THIS"] (SINGING) Break it down. 01:09:02.939 --> 01:09:04.772 align:middle line:84% All right, a big round of applause for Owen. 01:09:04.772 --> 01:09:05.930 align:middle line:90% [APPLAUSE] 01:09:05.930 --> 01:09:08.020 align:middle line:90% Here you go. 01:09:08.020 --> 01:09:08.580 align:middle line:90% Thank you. 01:09:08.580 --> 01:09:12.630 align:middle line:90% 01:09:12.630 --> 01:09:16.302 align:middle line:84% Allow us to conclude in our final moments with a look now of what else 01:09:16.302 --> 01:09:17.260 align:middle line:90% awaits with the course. 01:09:17.260 --> 01:09:19.177 align:middle line:84% Just as in Cambridge now, there is a tradition 01:09:19.177 --> 01:09:21.880 align:middle line:84% here in New Haven of a whole series of events. 01:09:21.880 --> 01:09:24.880 align:middle line:84% The first of which is CS50 Puzzle Day in just a weekend or so. 01:09:24.880 --> 01:09:27.630 align:middle line:84% The second of which is the CS50 Hackathon, an opportunity with all 01:09:27.630 --> 01:09:30.750 align:middle line:84% of your classmates up at Harvard, if you'd like, to join us from 7:00 01:09:30.750 --> 01:09:33.300 align:middle line:84% PM to 7:00 AM working on your final projects. 01:09:33.300 --> 01:09:35.760 align:middle line:84% And ultimately the CS50 Fair, a campus wide exhibition 01:09:35.760 --> 01:09:39.170 align:middle line:84% here at Yale of all of your final projects. 01:09:39.170 --> 01:09:40.920 align:middle line:84% So even if you've never programmed before, 01:09:40.920 --> 01:09:44.100 align:middle line:84% here is what awaits you in the next weeks of class. 01:09:44.100 --> 01:09:52.052 align:middle line:90% [MUSIC PLAYING - "LIVE IN THE MOMENT"] 01:09:52.052 --> 01:10:00.004 align:middle line:84% (SINGING) My home is a girl with eyes like wishing wells. 01:10:00.004 --> 01:10:07.956 align:middle line:90% I'm not alone, but I'm still lonely. 01:10:07.956 --> 01:10:13.948 align:middle line:84% Those days are done, but I'm still glowing. 01:10:13.948 --> 01:10:20.409 align:middle line:84% Ooh, la, la, la, la, la, let's live in the moment. 01:10:20.409 --> 01:10:25.379 align:middle line:84% Come back Sunday morning, a lie, oh well. 01:10:25.379 --> 01:10:29.355 align:middle line:84% When you're gone, goodbye, so long, farewell. 01:10:29.355 --> 01:10:34.822 align:middle line:84% Ooh, la, la, la, la, la, let's live in the moment. 01:10:34.822 --> 01:10:40.786 align:middle line:84% Come back Sunday morning with that soul to sell. 01:10:40.786 --> 01:10:43.768 align:middle line:84% When you're gone, goodbye, so long, farewell. 01:10:43.768 --> 01:10:48.738 align:middle line:90% 01:10:48.738 --> 01:10:56.193 align:middle line:84% My home is a girl who can't wait for time to tell. 01:10:56.193 --> 01:11:06.630 align:middle line:84% God only knows we don't need history when your family swinging 01:11:06.630 --> 01:11:11.103 align:middle line:90% from the branches of the trees. 01:11:11.103 --> 01:11:18.480 align:middle line:84% God only knows we don't need ghost stories. 01:11:18.480 --> 01:11:19.980 align:middle line:90% Ooh, la, la, la, la. 01:11:19.980 --> 01:11:21.480 align:middle line:90% All right, that's it. 01:11:21.480 --> 01:11:24.530 align:middle line:90% Christina's 50th cake is now served.