All language subtitles for jkl;jkj;jklj;jkljkl;tuiyiuiuyp

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 0 00:00:00,000 --> 00:00:03,486 [MUSIC PLAYING] 1 00:00:03,486 --> 00:01:30,636 2 00:01:30,636 --> 00:01:34,620 [AUDIENCE EXCLAIMING] 3 00:01:34,620 --> 00:01:38,106 [APPLAUSE] 4 00:01:38,106 --> 00:01:42,588 5 00:01:42,588 --> 00:01:44,170 SPOT: Hello, world. 6 00:01:44,170 --> 00:01:47,860 This is CS50, Harvard University's introduction 7 00:01:47,860 --> 00:01:50,740 to the intellectual enterprises of computer science 8 00:01:50,740 --> 00:01:53,080 and the art of programming. 9 00:01:53,080 --> 00:01:54,190 Woof, woof. 10 00:01:54,190 --> 00:01:57,613 [LAUGHTER] 11 00:01:57,613 --> 00:02:08,870 12 00:02:08,870 --> 00:02:10,857 I'm sorry, Dave. 13 00:02:10,857 --> 00:02:12,440 [PINK, "WHAT ABOUT US"] What about us? 14 00:02:12,440 --> 00:02:15,350 15 00:02:15,350 --> 00:02:16,310 What about us? 16 00:02:16,310 --> 00:02:17,534 La-da-da-da-da-da-da. 17 00:02:17,534 --> 00:02:18,965 La-da-da-da-da-da-da. 18 00:02:18,965 --> 00:02:21,827 We are searchlights. 19 00:02:21,827 --> 00:02:23,750 We can see in the dark. 20 00:02:23,750 --> 00:02:27,020 21 00:02:27,020 --> 00:02:31,280 We are rockets pointed up at the stars. 22 00:02:31,280 --> 00:02:34,710 23 00:02:34,710 --> 00:02:38,610 We are billions of beautiful hearts. 24 00:02:38,610 --> 00:02:41,977 25 00:02:41,977 --> 00:02:46,750 And you sold us down the river too far. 26 00:02:46,750 --> 00:02:49,570 27 00:02:49,570 --> 00:02:51,920 What about us? 28 00:02:51,920 --> 00:02:57,270 What about all the times you said you had the answers? 29 00:02:57,270 --> 00:02:59,270 What about us? 30 00:02:59,270 --> 00:03:05,270 What about all the broken happy ever-afters? 31 00:03:05,270 --> 00:03:06,770 What about us? 32 00:03:06,770 --> 00:03:12,770 What about all the plans that ended in disaster? 33 00:03:12,770 --> 00:03:14,980 What about love? 34 00:03:14,980 --> 00:03:16,149 What about trust? 35 00:03:16,149 --> 00:03:18,145 What about us? 36 00:03:18,145 --> 00:03:21,139 37 00:03:21,139 --> 00:03:24,632 La-da-da-da-da-da-da. 38 00:03:24,632 --> 00:03:28,624 La-da-da-da-da-da-da. 39 00:03:28,624 --> 00:03:30,121 La-da-da-da-da-da-da. 40 00:03:30,121 --> 00:03:33,115 41 00:03:33,115 --> 00:03:34,612 La-da-da-da-da-da-da. 42 00:03:34,612 --> 00:03:55,107 43 00:03:55,107 --> 00:03:56,190 DAVID J. MALAN: All right. 44 00:03:56,190 --> 00:03:56,840 So-- 45 00:03:56,840 --> 00:04:00,340 [APPLAUSE, CHEERING] 46 00:04:00,340 --> 00:04:02,660 47 00:04:02,660 --> 00:04:05,480 This is CS50, Harvard University's introduction 48 00:04:05,480 --> 00:04:07,790 to the intellectual enterprises of computer science 49 00:04:07,790 --> 00:04:09,200 and the art of programming. 50 00:04:09,200 --> 00:04:11,090 And this is Spot. 51 00:04:11,090 --> 00:04:13,370 And our thanks to our friends at 3D Cowboys 52 00:04:13,370 --> 00:04:15,080 for bringing him by class today. 53 00:04:15,080 --> 00:04:18,524 Perhaps a round of applause for our special Professor [INAUDIBLE].. 54 00:04:18,524 --> 00:04:21,860 [APPLAUSE] 55 00:04:21,860 --> 00:04:22,820 My name is David Malan. 56 00:04:22,820 --> 00:04:26,270 And I actually took this class, CS50, myself, some years ago. 57 00:04:26,270 --> 00:04:27,500 But I almost didn't. 58 00:04:27,500 --> 00:04:30,590 And I didn't because when I got to campus, as a first-year, 59 00:04:30,590 --> 00:04:33,350 I really gravitated toward things already familiar, things 60 00:04:33,350 --> 00:04:35,450 with which I was already comfortable, specifically, government. 61 00:04:35,450 --> 00:04:38,700 And I came in here thinking I was going to major or concentrate in government. 62 00:04:38,700 --> 00:04:41,840 And it was only once I got to sophomore year, fall semester, 63 00:04:41,840 --> 00:04:44,300 that some friends of mine were coming to this class called 64 00:04:44,300 --> 00:04:48,290 CS50 that was very much to beware at the time, in that it 65 00:04:48,290 --> 00:04:50,870 was an unfamiliar field to so many of us, myself included. 66 00:04:50,870 --> 00:04:54,320 But I got up the nerve to go over the threshold, sit in on the first class, 67 00:04:54,320 --> 00:04:56,280 just shop it, so to speak. 68 00:04:56,280 --> 00:04:57,570 And I was hooked. 69 00:04:57,570 --> 00:05:00,470 I found that homework was, for the first time, fun. 70 00:05:00,470 --> 00:05:03,783 And this was after having enrolled only because the professor let 71 00:05:03,783 --> 00:05:06,200 me enroll pass/fail or [INAUDIBLE] because I didn't really 72 00:05:06,200 --> 00:05:07,283 think I could even cut it. 73 00:05:07,283 --> 00:05:10,020 But fast forward to five Mondays later in the semester, 74 00:05:10,020 --> 00:05:12,020 I actually switched to a letter grade, deciding, 75 00:05:12,020 --> 00:05:14,240 wow, this is actually something for me. 76 00:05:14,240 --> 00:05:17,480 And I say this because computer science, what 77 00:05:17,480 --> 00:05:19,640 I didn't realize about it at the time, really 78 00:05:19,640 --> 00:05:23,680 is this very general purpose way of thinking and way of solving problems. 79 00:05:23,680 --> 00:05:26,490 And even if this is the only CS class you ever take, 80 00:05:26,490 --> 00:05:29,940 even if this is the only formal training you have in programming 81 00:05:29,940 --> 00:05:32,550 as a practical skill, it's just so darn applicable 82 00:05:32,550 --> 00:05:35,670 to so many other fields-- the arts, humanities, social sciences, 83 00:05:35,670 --> 00:05:39,660 natural sciences, and beyond, and certainly within the STEM fields, 84 00:05:39,660 --> 00:05:40,530 themselves. 85 00:05:40,530 --> 00:05:43,810 That said, it's going to often feel a little something like this. 86 00:05:43,810 --> 00:05:47,310 This is from our friends at MIT, down the road, which is one of their hacks 87 00:05:47,310 --> 00:05:51,300 whereby they connected a fire hydrant to a drinking fountain, 88 00:05:51,300 --> 00:05:54,960 with a little sign up there that says, "GETTING AN EDUCATION FROM MIT IS LIKE 89 00:05:54,960 --> 00:05:57,480 DRINKING FROM A FIRE HOSE," which is to say that it's 90 00:05:57,480 --> 00:05:59,310 going to feel, quite often, in this class, 91 00:05:59,310 --> 00:06:01,260 too, that there's just a lot of information. 92 00:06:01,260 --> 00:06:03,960 And you can't possibly absorb it all, but realize 93 00:06:03,960 --> 00:06:06,750 that's to be expected, especially in an introductory class. 94 00:06:06,750 --> 00:06:11,520 The whole point is for so much of it to feel new, but with practice, with time, 95 00:06:11,520 --> 00:06:14,390 with years, even, looking back, will you get all the more 96 00:06:14,390 --> 00:06:15,640 comfortable with the material. 97 00:06:15,640 --> 00:06:18,340 But you're not meant to feel comfortable along the way. 98 00:06:18,340 --> 00:06:20,340 And so let me encourage you, invite you, expect 99 00:06:20,340 --> 00:06:23,580 you to get comfortable feeling uncomfortable along the way, 100 00:06:23,580 --> 00:06:27,390 whether you have or have not prior computer science or programming 101 00:06:27,390 --> 00:06:28,080 experience. 102 00:06:28,080 --> 00:06:32,130 Now, back in my day, the class' syllabus was a little bit different. 103 00:06:32,130 --> 00:06:35,438 And, really, when I and all of my classmates exited the class, 104 00:06:35,438 --> 00:06:37,230 we would say to friends that we learned how 105 00:06:37,230 --> 00:06:40,860 to program in C, which is a language that we, ourselves, will still 106 00:06:40,860 --> 00:06:41,860 learn in this class. 107 00:06:41,860 --> 00:06:44,040 But that was it for languages. 108 00:06:44,040 --> 00:06:46,950 But nowadays, as you'll see, we'll explore not just 109 00:06:46,950 --> 00:06:49,560 this older language called C, but a more modern language 110 00:06:49,560 --> 00:06:53,580 called Python that's very much in vogue for data science, and web applications, 111 00:06:53,580 --> 00:06:54,460 and much more. 112 00:06:54,460 --> 00:06:56,293 But we'll also introduce you, along the way, 113 00:06:56,293 --> 00:07:01,020 to another language called S-Q-L or SQL, which is specifically for databases. 114 00:07:01,020 --> 00:07:03,330 And SQL is a different type of programming language 115 00:07:03,330 --> 00:07:06,060 that's just going to give you different ways of solving problems, 116 00:07:06,060 --> 00:07:09,480 different building blocks with which to express problems you want to solve. 117 00:07:09,480 --> 00:07:11,670 We'll introduce you, toward the end of the semester, 118 00:07:11,670 --> 00:07:14,040 yet another language, JavaScript, often used 119 00:07:14,040 --> 00:07:17,415 with markup languages called HTML and CSS, with which maybe you 120 00:07:17,415 --> 00:07:19,290 have some experience if you've made websites. 121 00:07:19,290 --> 00:07:23,640 But we'll do this because so many of today's actual real-world software 122 00:07:23,640 --> 00:07:24,630 is web-based. 123 00:07:24,630 --> 00:07:27,450 Or it's phone-based, mobile-based, but even then, 124 00:07:27,450 --> 00:07:30,000 it's using these same languages, like JavaScript. 125 00:07:30,000 --> 00:07:32,700 And so by the end of CS50, in particular, 126 00:07:32,700 --> 00:07:35,820 you won't know how to program in X, or Y, or Z, per se. 127 00:07:35,820 --> 00:07:39,150 But, period, you'll learn how to program. 128 00:07:39,150 --> 00:07:41,190 And, indeed, among the goals of this class 129 00:07:41,190 --> 00:07:45,540 is to equip you with enough of a set of concepts, enough practical skills 130 00:07:45,540 --> 00:07:49,440 and experience that after CS50, again, if you never take another CS class, 131 00:07:49,440 --> 00:07:51,690 you can teach yourself new languages. 132 00:07:51,690 --> 00:07:52,650 And you won't feel-- 133 00:07:52,650 --> 00:07:55,440 you won't have been reliant on a class to, indeed, 134 00:07:55,440 --> 00:07:57,508 introduce you to each and one of those ideas. 135 00:07:57,508 --> 00:07:59,550 And what are we going to do, then, in this class? 136 00:07:59,550 --> 00:08:01,260 And, really, what are we going to start doing today? 137 00:08:01,260 --> 00:08:03,402 Well, we're going to learn how to solve problems. 138 00:08:03,402 --> 00:08:05,610 And that's really what computer science is all about. 139 00:08:05,610 --> 00:08:09,090 We'll, very specifically, today, knock off a few to-dos. 140 00:08:09,090 --> 00:08:12,130 We'll learn how to represent simple things, like numbers. 141 00:08:12,130 --> 00:08:14,880 We'll learn how to represent letters of an alphabet, like English. 142 00:08:14,880 --> 00:08:17,130 We'll learn how to represent colors-- red, green, blue, 143 00:08:17,130 --> 00:08:18,240 and everything in between. 144 00:08:18,240 --> 00:08:20,610 We'll learn how to represent, more interestingly, 145 00:08:20,610 --> 00:08:23,430 full-fledged images that you might see on the web or your phone. 146 00:08:23,430 --> 00:08:26,730 We'll talk about representing videos and even audio files. 147 00:08:26,730 --> 00:08:29,540 So, by the end of today, alone, you will exit here 148 00:08:29,540 --> 00:08:31,850 with a newfound mental model for how you can 149 00:08:31,850 --> 00:08:36,140 represent all of today's media and multimedia that we take for granted 150 00:08:36,140 --> 00:08:37,760 and use most every day. 151 00:08:37,760 --> 00:08:40,370 But we'll also focus today, ultimately, on how 152 00:08:40,370 --> 00:08:43,520 to write algorithms, like step-by-step instructions for solving 153 00:08:43,520 --> 00:08:47,375 some problem, specifically, implementing algorithms with code. 154 00:08:47,375 --> 00:08:48,500 And that's what we'll find. 155 00:08:48,500 --> 00:08:50,417 An algorithm is just something you can express 156 00:08:50,417 --> 00:08:54,350 in English or any human language, but code is a translation of that 157 00:08:54,350 --> 00:08:57,260 to, presumably, the 0's and 1's that you've probably heard 158 00:08:57,260 --> 00:08:59,840 is all that computers ultimately speak. 159 00:08:59,840 --> 00:09:02,030 And if you're feeling like that's a lot for today, 160 00:09:02,030 --> 00:09:04,488 if you're feeling like that's a lot for the whole semester, 161 00:09:04,488 --> 00:09:07,190 realize and take comfort in knowing that -thirds of you 162 00:09:07,190 --> 00:09:09,720 have never taken a CS course before. 163 00:09:09,720 --> 00:09:12,140 So even if you think, like I did all those years ago, 164 00:09:12,140 --> 00:09:15,047 that, surely, my friends, the kids I didn't even in the class, 165 00:09:15,047 --> 00:09:16,880 must know more than I, have been programming 166 00:09:16,880 --> 00:09:18,500 since they were six years old. 167 00:09:18,500 --> 00:09:19,880 That's just not the case. 168 00:09:19,880 --> 00:09:21,260 You're in very much good company. 169 00:09:21,260 --> 00:09:24,003 And within the class will you find different tracks, 170 00:09:24,003 --> 00:09:26,420 by way of the homework assignments, called "problem sets," 171 00:09:26,420 --> 00:09:28,003 by way of the sections or recitations. 172 00:09:28,003 --> 00:09:29,962 There will be different tracks for those of you 173 00:09:29,962 --> 00:09:32,610 less comfortable, more comfortable, somewhere in between. 174 00:09:32,610 --> 00:09:34,940 And if you really don't know why you are here today, 175 00:09:34,940 --> 00:09:37,970 we'll even have sections for those least comfortable, where you just 176 00:09:37,970 --> 00:09:41,690 don't necessarily feel ready to dive into CS or maybe STEM, more generally. 177 00:09:41,690 --> 00:09:44,840 But we'll get you there by way of the course's support structure. 178 00:09:44,840 --> 00:09:47,780 And it's very much grounded in this mindset. 179 00:09:47,780 --> 00:09:50,150 What ultimately matters in this class is not so much 180 00:09:50,150 --> 00:09:52,025 where you end up relative to your classmates, 181 00:09:52,025 --> 00:09:55,040 but where you end up relative to yourself, when you began. 182 00:09:55,040 --> 00:09:58,323 So whether you have or have not prior programming or CSS experience, 183 00:09:58,323 --> 00:10:00,740 it's not going to matter when it comes to evaluation, when 184 00:10:00,740 --> 00:10:04,320 it comes to the output, be it a grade, or a satisfactory mark, or the like. 185 00:10:04,320 --> 00:10:06,860 It's going to depend on, really, where you are today, 186 00:10:06,860 --> 00:10:11,960 in this, what we call week zero, versus the very end of the semester, when 187 00:10:11,960 --> 00:10:15,050 you will have built something grand, of your very own, in software. 188 00:10:15,050 --> 00:10:17,270 But CS50 is also characterized, fairly uniquely, 189 00:10:17,270 --> 00:10:19,147 by its community, its culture. 190 00:10:19,147 --> 00:10:21,230 And along the way, you'll see that your experience 191 00:10:21,230 --> 00:10:24,680 is punctuated by a lot of social and academic events alike. 192 00:10:24,680 --> 00:10:27,890 CS50 lunches, most every Friday, we'll gather at a nearby restaurant 193 00:10:27,890 --> 00:10:30,280 called Changsho where we'll have Chinese lunch together. 194 00:10:30,280 --> 00:10:32,030 And as many of you as might want to attend 195 00:10:32,030 --> 00:10:34,988 that week will be able to join us, sit down, and chat casually with me, 196 00:10:34,988 --> 00:10:39,680 the course's teaching staff, friends of ours, alumni from industry, as well. 197 00:10:39,680 --> 00:10:42,630 CS50 Puzzle Day, coming up this weekend, will be an opportunity, 198 00:10:42,630 --> 00:10:46,740 even if you have no prior CS experience, just to solve problems, 199 00:10:46,740 --> 00:10:49,790 not jigsaw puzzles, but puzzles in the logical sense. 200 00:10:49,790 --> 00:10:52,490 We'll hand you a packet of puzzles-- 201 00:10:52,490 --> 00:10:54,230 logic problems, or riddles, or the like-- 202 00:10:54,230 --> 00:10:56,087 that you, as teams, can solve together. 203 00:10:56,087 --> 00:10:57,920 And at the very end, we'll walk you through. 204 00:10:57,920 --> 00:11:01,350 And along the way, there'll be not only these puzzles, but pizza, and prizes, 205 00:11:01,350 --> 00:11:02,960 and so much more, as well. 206 00:11:02,960 --> 00:11:06,350 Towards the end of the semester, we'll have a CS50 Hackathon whereby 207 00:11:06,350 --> 00:11:09,830 we'll get together around 7:00 PM, at the start of reading period, 208 00:11:09,830 --> 00:11:12,740 and we'll finish up around 7:00 AM the next morning. 209 00:11:12,740 --> 00:11:15,080 And it will be this opportunity to really bond 210 00:11:15,080 --> 00:11:18,140 with your classmates, your project partners, if you work in a team, 211 00:11:18,140 --> 00:11:20,510 on your very own final project, which is meant 212 00:11:20,510 --> 00:11:23,750 to be a capstone of the course, something you build, yourselves, 213 00:11:23,750 --> 00:11:25,760 that we don't hand you a specification for. 214 00:11:25,760 --> 00:11:29,090 But it's your final offboarding, so that when you exit CS50, 215 00:11:29,090 --> 00:11:31,340 you don't need CS50 anymore. 216 00:11:31,340 --> 00:11:32,100 You don't need me. 217 00:11:32,100 --> 00:11:33,058 You don't need your TF. 218 00:11:33,058 --> 00:11:35,910 You can actually write code and solve problems on your own. 219 00:11:35,910 --> 00:11:39,740 So this picture here is one of our past photos from earlier in the evening. 220 00:11:39,740 --> 00:11:42,590 Things get a little quieter as we then, around 5:00 AM, 221 00:11:42,590 --> 00:11:46,340 drive anyone who's still awake and energetic to a nearby IHOP 222 00:11:46,340 --> 00:11:48,140 for pancakes, around then. 223 00:11:48,140 --> 00:11:51,710 But here is how most of the evenings tend to end for at least some 224 00:11:51,710 --> 00:11:53,000 of your classmates prior. 225 00:11:53,000 --> 00:11:55,670 But at the very end of the class is the so-called CS50 Fair, 226 00:11:55,670 --> 00:11:59,670 an exhibition of all of your final projects for friends, faculty, 227 00:11:59,670 --> 00:12:01,610 students, and staff across campus, whereby 228 00:12:01,610 --> 00:12:03,440 you'll be invited to a space like this. 229 00:12:03,440 --> 00:12:04,220 Bring your laptop. 230 00:12:04,220 --> 00:12:06,920 Bring your phone, whatever it is you have built and created. 231 00:12:06,920 --> 00:12:09,260 And we'll just show it off for a bit of the afternoon, 232 00:12:09,260 --> 00:12:11,870 complete with music, and friends from industry, 233 00:12:11,870 --> 00:12:16,000 and candy, and all what makes gathering together at term's end fond. 234 00:12:16,000 --> 00:12:17,750 And you'll wear, ultimately, very proudly, 235 00:12:17,750 --> 00:12:21,770 we hope, your very own "I took CS50," stating, very matter of factly, 236 00:12:21,770 --> 00:12:25,790 what I did some years ago; that, indeed, this was a course I, myself, took. 237 00:12:25,790 --> 00:12:29,120 So, today, let's focus, then, on computer science, like what is it. 238 00:12:29,120 --> 00:12:31,790 Well, it's really the study of information. 239 00:12:31,790 --> 00:12:34,910 But, really, it's, more specifically, about solving problems, 240 00:12:34,910 --> 00:12:38,360 using certain ideas and techniques, all of which you'll exit the course with. 241 00:12:38,360 --> 00:12:43,378 So, as such, problem solving is a goal that we'll 242 00:12:43,378 --> 00:12:45,920 approach by way of something called "computational thinking." 243 00:12:45,920 --> 00:12:49,760 So computational thinking, you can oversimplistically think about it 244 00:12:49,760 --> 00:12:51,500 as thinking like a computer. 245 00:12:51,500 --> 00:12:55,410 But it's really the application of ideas that we'll dive into today 246 00:12:55,410 --> 00:12:57,380 and we'll finish some weeks from now, that you 247 00:12:57,380 --> 00:13:01,880 can apply to problems from this field or most any other, but in a computational, 248 00:13:01,880 --> 00:13:04,770 that is, a very methodical, very careful way. 249 00:13:04,770 --> 00:13:07,520 And that's what CS really did for me and does for a lot of people. 250 00:13:07,520 --> 00:13:09,740 It helps clean up your thought processes. 251 00:13:09,740 --> 00:13:12,560 Even if you go off into the real world and do nothing in tech, 252 00:13:12,560 --> 00:13:14,840 you have an ability, after classes like this, 253 00:13:14,840 --> 00:13:18,020 to express yourself a little more correctly, more 254 00:13:18,020 --> 00:13:20,660 precisely and, generally, having better command 255 00:13:20,660 --> 00:13:22,980 of your own ideas and your language. 256 00:13:22,980 --> 00:13:24,410 So what's problem solving? 257 00:13:24,410 --> 00:13:25,790 Let me propose that this is it. 258 00:13:25,790 --> 00:13:29,270 This is as simple as we can make today's goals and the semester's goals. 259 00:13:29,270 --> 00:13:30,960 Problems to be solved look like this. 260 00:13:30,960 --> 00:13:32,960 You've got some input, the problem to be solved. 261 00:13:32,960 --> 00:13:35,750 You've got a goal being the output, like the solution there, too. 262 00:13:35,750 --> 00:13:38,000 And then somewhere in the middle is the secret sauce, 263 00:13:38,000 --> 00:13:40,375 where we'll spend the next several weeks figuring out how 264 00:13:40,375 --> 00:13:42,350 we can convert these inputs to outputs. 265 00:13:42,350 --> 00:13:44,870 But before we can do that, we all just have 266 00:13:44,870 --> 00:13:48,260 to agree on how to represent these inputs and outputs, 267 00:13:48,260 --> 00:13:51,260 whether it's with English or, really, any type of language. 268 00:13:51,260 --> 00:13:54,290 But, as I spoiled earlier, you probably came in here already 269 00:13:54,290 --> 00:13:56,900 with a general sense that, yeah, computers somehow 270 00:13:56,900 --> 00:14:00,823 only speak or know 0's and 1's, the so-called binary system. 271 00:14:00,823 --> 00:14:02,990 But that's just one way of representing information. 272 00:14:02,990 --> 00:14:05,150 Even simpler than binary is unary. 273 00:14:05,150 --> 00:14:10,670 So if you've ever, at this age or any prior age, counted on your fingers, 274 00:14:10,670 --> 00:14:14,480 this is unary notation, whereby each of your digits, your fingers 275 00:14:14,480 --> 00:14:17,000 literally represent some piece of information; 276 00:14:17,000 --> 00:14:19,760 taking attendance, like 1, 2, 3, 4, 5. 277 00:14:19,760 --> 00:14:25,800 But on your one human hand, how high can you count in this unary notation? 278 00:14:25,800 --> 00:14:26,505 AUDIENCE: Five. 279 00:14:26,505 --> 00:14:27,130 AUDIENCE: Five. 280 00:14:27,130 --> 00:14:29,550 DAVID J. MALAN: Five, I'm hearing five. 281 00:14:29,550 --> 00:14:31,890 Six, I heard one six. 282 00:14:31,890 --> 00:14:35,610 But I'm going to go further and say the answer, if you're clever about it, 283 00:14:35,610 --> 00:14:36,500 is actually-- 284 00:14:36,500 --> 00:14:37,132 AUDIENCE: 40? 285 00:14:37,132 --> 00:14:38,340 DAVID J. MALAN: Not quite 40. 286 00:14:38,340 --> 00:14:39,660 You overbid, but-- 287 00:14:39,660 --> 00:14:40,500 AUDIENCE: 31. 288 00:14:40,500 --> 00:14:43,885 DAVID J. MALAN: 31 is as high as I can actually count. 289 00:14:43,885 --> 00:14:46,260 And that's because if I actually-- and if you're thinking 290 00:14:46,260 --> 00:14:49,530 this is weirdly painful now, it will be, but this 291 00:14:49,530 --> 00:14:51,600 is my hand representing the number 0. 292 00:14:51,600 --> 00:14:55,980 Normally, in unary, this is 1, 2, 3, 4, 5, of course, obviously. 293 00:14:55,980 --> 00:14:58,290 But what if I take into account the order in which I'm 294 00:14:58,290 --> 00:14:59,590 putting my fingers up and down? 295 00:14:59,590 --> 00:15:00,840 So maybe this is still 0. 296 00:15:00,840 --> 00:15:02,490 Maybe this is still 1. 297 00:15:02,490 --> 00:15:07,410 But maybe this is now 2, where it's just the single second finger up, 298 00:15:07,410 --> 00:15:08,940 not two of them, total. 299 00:15:08,940 --> 00:15:10,860 Maybe this is now 3. 300 00:15:10,860 --> 00:15:14,730 Maybe this is now-- often offensive, with just the middle finger up. 301 00:15:14,730 --> 00:15:17,250 This is now [LAUGHS] 5. 302 00:15:17,250 --> 00:15:19,260 This is now 6. 303 00:15:19,260 --> 00:15:21,160 This is now 7. 304 00:15:21,160 --> 00:15:24,010 And my hand just hurts too much if I try to count higher than seven. 305 00:15:24,010 --> 00:15:27,640 But, theoretically, because each of my fingers can be down or up 306 00:15:27,640 --> 00:15:32,230 and I've got five of them, that's actually 32 possible permutations, 307 00:15:32,230 --> 00:15:32,890 up and down. 308 00:15:32,890 --> 00:15:33,640 But wait a minute. 309 00:15:33,640 --> 00:15:36,130 We said, 31, but if you start at 0. 310 00:15:36,130 --> 00:15:38,735 You have to subtract 1 from the biggest possible value. 311 00:15:38,735 --> 00:15:41,860 So this is to say you and I have been using unary because it's just simple, 312 00:15:41,860 --> 00:15:43,100 and it gets the job done. 313 00:15:43,100 --> 00:15:46,750 But if we just think about representation a little more cleverly, 314 00:15:46,750 --> 00:15:50,410 we can do exactly what computers do, using not what mathematicians call 315 00:15:50,410 --> 00:15:54,460 "base-1," where the finger is either there or it's not, but base-2. 316 00:15:54,460 --> 00:15:58,390 And in base-2, we just need two digits at our disposal. 317 00:15:58,390 --> 00:16:02,720 And we could call these digits 1 and 2, A and B, black or white. 318 00:16:02,720 --> 00:16:06,370 We just need two words to describe two pieces of information. 319 00:16:06,370 --> 00:16:07,600 Computers keep it simple. 320 00:16:07,600 --> 00:16:10,960 And just like we humans start counting 0, 1, 2, 3 on up, 321 00:16:10,960 --> 00:16:14,230 computers use 0 and 1, and that's it. 322 00:16:14,230 --> 00:16:15,710 But that's by convention. 323 00:16:15,710 --> 00:16:16,940 But why do they do that? 324 00:16:16,940 --> 00:16:21,930 Well, it turns out, when you use base-2, otherwise known as binary, well, 325 00:16:21,930 --> 00:16:24,030 it just maps really readily to the real world. 326 00:16:24,030 --> 00:16:25,947 Because, at the end of the day, what do we all 327 00:16:25,947 --> 00:16:28,740 do, if you've got a laptop, or a phone, or any device? 328 00:16:28,740 --> 00:16:32,310 You plug it into the wall because it needs electricity at some point. 329 00:16:32,310 --> 00:16:35,820 And what if you have electricity or not? 330 00:16:35,820 --> 00:16:38,190 Well, there's your two possible values. 331 00:16:38,190 --> 00:16:39,910 Either it's there, or it's not. 332 00:16:39,910 --> 00:16:42,000 And because computers are electrical devices, 333 00:16:42,000 --> 00:16:43,675 this is why binary is just useful. 334 00:16:43,675 --> 00:16:44,550 It's nice and simple. 335 00:16:44,550 --> 00:16:46,920 Either electricity is there, or it's not. 336 00:16:46,920 --> 00:16:48,810 So when you plug this device in and you've 337 00:16:48,810 --> 00:16:51,060 got all these electrons or whatever flowing, maybe 338 00:16:51,060 --> 00:16:53,250 if we just hang on to some of that electricity, 339 00:16:53,250 --> 00:16:55,230 we can represent what we'll call a 1. 340 00:16:55,230 --> 00:16:58,470 And maybe if we let it dissipate or go away, that's a 0. 341 00:16:58,470 --> 00:17:02,760 So on and off maps very readily to this idea of just 0's and 1's. 342 00:17:02,760 --> 00:17:06,750 And if you've ever thought of this, now, as binary digits-- 343 00:17:06,750 --> 00:17:10,380 "bi" implying 2, 0 and 1-- well, if you've ever heard this term now, 344 00:17:10,380 --> 00:17:12,690 "bit," it just means binary digit. 345 00:17:12,690 --> 00:17:14,688 A single bit is just a 0 or 1. 346 00:17:14,688 --> 00:17:16,980 But we could have called these things anything we want. 347 00:17:16,980 --> 00:17:20,069 Now how does this map to be clear to the real world? 348 00:17:20,069 --> 00:17:23,470 Well, we can't see the tiny little switches inside of our Macs, 349 00:17:23,470 --> 00:17:26,140 PCs, and our phones that are actually turning the electricity on 350 00:17:26,140 --> 00:17:28,480 or off, storing electricity or not. 351 00:17:28,480 --> 00:17:29,920 But they're called transistors. 352 00:17:29,920 --> 00:17:32,470 They've got millions of them in today's hardware. 353 00:17:32,470 --> 00:17:35,317 And they're just on or off, like a switch or a light bulb. 354 00:17:35,317 --> 00:17:37,150 So, for instance, if there's no electricity, 355 00:17:37,150 --> 00:17:40,690 the switch is off, we would call this, by convention, a 0. 356 00:17:40,690 --> 00:17:45,160 If, though, you throw the switch and it actually turns on, we would call this-- 357 00:17:45,160 --> 00:17:45,940 AUDIENCE: On. 358 00:17:45,940 --> 00:17:47,607 DAVID J. MALAN: --an "on," exactly, a 1. 359 00:17:47,607 --> 00:17:48,690 We could have reversed it. 360 00:17:48,690 --> 00:17:51,160 But this is just the way the world decided to standardize. 361 00:17:51,160 --> 00:17:51,910 And that's it. 362 00:17:51,910 --> 00:17:55,780 So you've either got something on or off, a 1 or a 0. 363 00:17:55,780 --> 00:18:00,020 And this, then, is this thing we know now as a binary digit or a bit. 364 00:18:00,020 --> 00:18:04,490 So once we've got these values, what about how-- 365 00:18:04,490 --> 00:18:07,090 how can we go about, perhaps, representing things? 366 00:18:07,090 --> 00:18:08,060 Well, you know what? 367 00:18:08,060 --> 00:18:10,352 It turns out we've got a lot of light bulbs right here. 368 00:18:10,352 --> 00:18:11,260 Let me grab-- thanks. 369 00:18:11,260 --> 00:18:12,010 Excuse me, spot. 370 00:18:12,010 --> 00:18:16,540 Let me grab the little music stand here. 371 00:18:16,540 --> 00:18:18,610 Let me borrow a couple of these bulbs and see 372 00:18:18,610 --> 00:18:22,310 if we can't make clearer than my hand, alone, what's going on here. 373 00:18:22,310 --> 00:18:24,970 So I'm going to go ahead and grab two of these. 374 00:18:24,970 --> 00:18:26,670 And I'll just put them here. 375 00:18:26,670 --> 00:18:28,420 And I can turn these things on or off now. 376 00:18:28,420 --> 00:18:32,560 So if I've got two bits, two switches, two transistors, if you will, well, 377 00:18:32,560 --> 00:18:38,660 if I go ahead and turn on this one, I'm representing what number in binary, 378 00:18:38,660 --> 00:18:39,160 perhaps? 379 00:18:39,160 --> 00:18:39,880 AUDIENCE: 1. 380 00:18:39,880 --> 00:18:41,200 DAVID J. MALAN: So just 1. 381 00:18:41,200 --> 00:18:45,130 Now, if I'm using unary, I would turn this one on and be done with it. 382 00:18:45,130 --> 00:18:46,980 And that's 2, but not in binary. 383 00:18:46,980 --> 00:18:51,350 Binary, it's the permutations, which ones are on and off, that matters. 384 00:18:51,350 --> 00:18:53,790 So what, now, am I representing here, perhaps? 385 00:18:53,790 --> 00:18:54,370 AUDIENCE: 2. 386 00:18:54,370 --> 00:18:55,120 DAVID J. MALAN: 2. 387 00:18:55,120 --> 00:18:58,210 So this is when I put my single pointer finger up. 388 00:18:58,210 --> 00:19:00,430 But then when I did this, in my human hand, 389 00:19:00,430 --> 00:19:03,310 this was like representing the number 3. 390 00:19:03,310 --> 00:19:06,640 How do I represent the number 4. 391 00:19:06,640 --> 00:19:11,000 Yeah, I need another light bulb, so I need more hardware, so to speak. 392 00:19:11,000 --> 00:19:13,000 So if I turn-- 393 00:19:13,000 --> 00:19:19,180 if I leave this one-- if I turn this one on, this one off, this one off, 394 00:19:19,180 --> 00:19:21,380 now I have the number 4. 395 00:19:21,380 --> 00:19:24,593 And someone tell me, saying the words "on" 396 00:19:24,593 --> 00:19:26,510 and "on" and "on," or "on," or "off," or "on," 397 00:19:26,510 --> 00:19:28,850 using combinations of "on," "off" and-- "on" 398 00:19:28,850 --> 00:19:32,832 and "off," how do I represent 5, from your left to your right? 399 00:19:32,832 --> 00:19:33,665 How about over here? 400 00:19:33,665 --> 00:19:34,880 AUDIENCE: On, off, on. 401 00:19:34,880 --> 00:19:36,620 DAVID J. MALAN: "On, off, on," I heard. 402 00:19:36,620 --> 00:19:38,480 And that's exactly right. 403 00:19:38,480 --> 00:19:41,085 And how do I represent, maybe, 6? 404 00:19:41,085 --> 00:19:41,585 Over here? 405 00:19:41,585 --> 00:19:43,010 AUDIENCE: Off, on, on. 406 00:19:43,010 --> 00:19:45,080 DAVID J. MALAN: Off, on, on, not quite. 407 00:19:45,080 --> 00:19:45,995 From left to right? 408 00:19:45,995 --> 00:19:47,390 AUDIENCE: Off-- the other way. 409 00:19:47,390 --> 00:19:47,620 DAVID J. MALAN: The-- 410 00:19:47,620 --> 00:19:49,290 [LAUGHS] OK, so from right to left. 411 00:19:49,290 --> 00:19:50,960 So I think we leave this one on. 412 00:19:50,960 --> 00:19:58,760 This one, I'm going to claim, represents, now, 6 and 7. 413 00:19:58,760 --> 00:19:59,570 AUDIENCE: On, off. 414 00:19:59,570 --> 00:20:02,300 DAVID J. MALAN: I'm just going to-- it's actually going to be "on, on, on." 415 00:20:02,300 --> 00:20:04,737 Now, if you're wondering, where are these people coming up 416 00:20:04,737 --> 00:20:07,070 with these combinations, there's actually a system here. 417 00:20:07,070 --> 00:20:09,770 It's actually hard for me to do it backwards. 418 00:20:09,770 --> 00:20:14,202 But it turns out there's actually a system that's not all that unfamiliar. 419 00:20:14,202 --> 00:20:15,410 In fact, let me propose this. 420 00:20:15,410 --> 00:20:18,770 Let me propose that we consider what you and I all 421 00:20:18,770 --> 00:20:23,100 learned in grade school, which was something like the base-10 system, 10 422 00:20:23,100 --> 00:20:25,770 meaning that you use 10 different digits, not two, 10. 423 00:20:25,770 --> 00:20:30,300 So 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, that's the base-10 system, otherwise known 424 00:20:30,300 --> 00:20:32,370 as decimal, "dec" implying 10. 425 00:20:32,370 --> 00:20:34,140 So that's what you and I use every day. 426 00:20:34,140 --> 00:20:37,140 Well, let's think about how we represent numbers in decimal, 427 00:20:37,140 --> 00:20:38,430 in the normal human way. 428 00:20:38,430 --> 00:20:39,520 Well, here is a number. 429 00:20:39,520 --> 00:20:41,380 It's what number, of course? 430 00:20:41,380 --> 00:20:42,180 AUDIENCE: 123. 431 00:20:42,180 --> 00:20:43,542 DAVID J. MALAN: 123. 432 00:20:43,542 --> 00:20:45,750 So we all just have an intuition for that, obviously. 433 00:20:45,750 --> 00:20:48,420 But it's not necessarily 123. 434 00:20:48,420 --> 00:20:51,640 You're just assigning meaning to the positions of these digits. 435 00:20:51,640 --> 00:20:54,030 This is really the pattern 1-2-3. 436 00:20:54,030 --> 00:20:57,390 But you immediately jump, mathematically, to 123, but why? 437 00:20:57,390 --> 00:21:00,390 Well, odds are, in grade school, you learned that the rightmost digit is 438 00:21:00,390 --> 00:21:02,160 the ones place or the ones column. 439 00:21:02,160 --> 00:21:04,800 This is the tens place or the tens column. 440 00:21:04,800 --> 00:21:06,490 This is the hundreds place. 441 00:21:06,490 --> 00:21:08,230 And so why is this relevant? 442 00:21:08,230 --> 00:21:11,190 Well, this is like doing 100 times 1 plus 10 times 443 00:21:11,190 --> 00:21:16,410 2 plus 1 times 3 or, if we multiply that out, 100 plus 20 plus 3, 444 00:21:16,410 --> 00:21:21,240 ergo, the number, now, that we just take for granted is 123. 445 00:21:21,240 --> 00:21:24,240 But that's in base-10, the so-called decimal system, 446 00:21:24,240 --> 00:21:27,930 whereby each of these digits is in a different column. 447 00:21:27,930 --> 00:21:31,080 And those columns are, again, ones place, tens, hundreds. 448 00:21:31,080 --> 00:21:33,790 If we keep going, thousand, ten thousand, and so forth. 449 00:21:33,790 --> 00:21:35,040 But where did these come from? 450 00:21:35,040 --> 00:21:35,957 Well, here's the base. 451 00:21:35,957 --> 00:21:37,770 If you remember exponents and all of that, 452 00:21:37,770 --> 00:21:41,910 this is just 10 to the 0, 10 to the 1, 10 to the 2, ad infinitum. 453 00:21:41,910 --> 00:21:46,860 And so, now, what if we just changed the base from 10, 0 through 9, 454 00:21:46,860 --> 00:21:48,480 to just two digits, 0 and 1? 455 00:21:48,480 --> 00:21:50,610 Well, now the math is fundamentally the same. 456 00:21:50,610 --> 00:21:52,880 But it's 2 to the 0, 2 to the 1, 2 to the 2, 457 00:21:52,880 --> 00:21:57,030 which gives us the ones place, twos place, and fours place. 458 00:21:57,030 --> 00:21:58,410 Now, why is this relevant? 459 00:21:58,410 --> 00:22:02,790 If you've got three light bulbs or three bits that are off, off, off, 460 00:22:02,790 --> 00:22:03,930 what have I done? 461 00:22:03,930 --> 00:22:07,710 4 times 0 plus 2 times 0 plus 1 times 0 is, obviously, the number 462 00:22:07,710 --> 00:22:09,990 you and I know, in decimal, as 0. 463 00:22:09,990 --> 00:22:12,630 This, though, represents the number you and I know as-- 464 00:22:12,630 --> 00:22:13,230 AUDIENCE: 1 465 00:22:13,230 --> 00:22:14,605 DAVID J. MALAN: This represents-- 466 00:22:14,605 --> 00:22:15,195 AUDIENCE: 2. 467 00:22:15,195 --> 00:22:17,910 DAVID J. MALAN: --3, 4. 468 00:22:17,910 --> 00:22:21,540 And just to be clear, this is why, when I grabbed the additional light bulb, 469 00:22:21,540 --> 00:22:25,170 we claimed that this now was 4. 470 00:22:25,170 --> 00:22:29,430 Because we had "on, off, off," "on, off, off." 471 00:22:29,430 --> 00:22:30,960 This now is 5. 472 00:22:30,960 --> 00:22:32,190 This now is 6. 473 00:22:32,190 --> 00:22:33,240 This now is 7. 474 00:22:33,240 --> 00:22:36,480 And if I wanted to count higher, what would the pattern of 0's and 1's be 475 00:22:36,480 --> 00:22:37,478 for the number 8? 476 00:22:37,478 --> 00:22:38,942 AUDIENCE: 1, 0-- 477 00:22:38,942 --> 00:22:40,410 DAVID J. MALAN: 1, 0, 0, 0. 478 00:22:40,410 --> 00:22:42,330 So we just need more hardware, more bits. 479 00:22:42,330 --> 00:22:45,630 So it wasn't arbitrary, even if it was non-obvious, 480 00:22:45,630 --> 00:22:49,660 what I was actually doing with turning these light bulbs on and off. 481 00:22:49,660 --> 00:22:53,730 Now, it turns out here we are talking about how to represent information, 482 00:22:53,730 --> 00:22:59,490 like numbers, but we could also use bits, 0's and 1's, light bulbs 483 00:22:59,490 --> 00:23:01,590 to represent instructions, as well. 484 00:23:01,590 --> 00:23:04,050 Because, at the end of the day, that's all computers do. 485 00:23:04,050 --> 00:23:07,950 They process data, information of some sort, whether it's files, 486 00:23:07,950 --> 00:23:10,290 or numbers, or images, or videos, or the like. 487 00:23:10,290 --> 00:23:13,290 And you do things with those files. 488 00:23:13,290 --> 00:23:13,985 You open them. 489 00:23:13,985 --> 00:23:14,610 You print them. 490 00:23:14,610 --> 00:23:15,610 You edit them and the like. 491 00:23:15,610 --> 00:23:18,720 So there's this notion of instructions, what the computer can actually do. 492 00:23:18,720 --> 00:23:22,470 And I bet we could come up with some pattern of 0's and 1's 493 00:23:22,470 --> 00:23:26,970 or, equivalently, light bulbs that tell even Spot what to do. 494 00:23:26,970 --> 00:23:30,785 Maybe, go up, or down, or left, or right. 495 00:23:30,785 --> 00:23:33,660 And it could certainly do this autonomously by using various sensors. 496 00:23:33,660 --> 00:23:35,077 We need to keep things safe today. 497 00:23:35,077 --> 00:23:38,248 We're using Wi-Fi in sending Spot these very instructions. 498 00:23:38,248 --> 00:23:41,040 But what's happening, wirelessly, with our friend Andrew, here, is, 499 00:23:41,040 --> 00:23:45,330 essentially, he's sending Spot instructions just encoded, wirelessly, 500 00:23:45,330 --> 00:23:47,610 somehow, as patterns of 0's and 1's. 501 00:23:47,610 --> 00:23:51,390 And the folks at Boston Dynamics, who built this robot, programmed 502 00:23:51,390 --> 00:23:54,330 Spot to recognize certain patterns as meaning "up," 503 00:23:54,330 --> 00:23:57,030 a certain pattern as meaning "down," "left," "right," 504 00:23:57,030 --> 00:23:58,505 and any number of other things. 505 00:23:58,505 --> 00:24:00,630 So, in fact, Spot, come on over here, if you could. 506 00:24:00,630 --> 00:24:01,830 Come on, Spot. 507 00:24:01,830 --> 00:24:03,510 [FOOTSTEPS] 508 00:24:03,510 --> 00:24:05,640 OK. 509 00:24:05,640 --> 00:24:08,400 So Spot, for instance, may very well have a pattern 510 00:24:08,400 --> 00:24:11,190 of 0's and 1's that represents shake. 511 00:24:11,190 --> 00:24:12,720 Shake, Spot. 512 00:24:12,720 --> 00:24:16,330 So he could do that and any number of other movements, as well. 513 00:24:16,330 --> 00:24:19,680 And maybe, especially with sensors here and also a little human help over here, 514 00:24:19,680 --> 00:24:22,540 for today, what if we went ahead and did something-- maybe 515 00:24:22,540 --> 00:24:23,870 ask Spot some questions? 516 00:24:23,870 --> 00:24:25,660 So let's go ahead, and we'll start simple. 517 00:24:25,660 --> 00:24:31,150 Spot, here we have some bits, "off, off, on." 518 00:24:31,150 --> 00:24:34,030 Spot, what [LAUGHS]-- OK. 519 00:24:34,030 --> 00:24:41,260 Spot, what is this representing, "off, off, on"? 520 00:24:41,260 --> 00:24:43,710 [SPOT TAPS STAGE] 521 00:24:43,710 --> 00:24:44,970 Correct? 522 00:24:44,970 --> 00:24:45,900 I think so. 523 00:24:45,900 --> 00:24:46,900 Very horse-like, OK. 524 00:24:46,900 --> 00:24:47,400 Thank you. 525 00:24:47,400 --> 00:24:49,400 All right, so a round of applause for Spot here. 526 00:24:49,400 --> 00:24:50,310 [APPLAUSE] 527 00:24:50,310 --> 00:24:51,450 All right. 528 00:24:51,450 --> 00:24:54,400 So, Spot, what if we [LAUGHS] turn-- 529 00:24:54,400 --> 00:24:54,900 OK. 530 00:24:54,900 --> 00:24:56,160 We'll turn that one off here. 531 00:24:56,160 --> 00:24:57,535 How about if we turn this one on? 532 00:24:57,535 --> 00:24:59,280 So it's "off, on, off." 533 00:24:59,280 --> 00:25:02,470 Spot, what's this number? 534 00:25:02,470 --> 00:25:04,310 [SPOT TAPPING STAGE] 535 00:25:04,310 --> 00:25:05,570 Is that correct? 536 00:25:05,570 --> 00:25:06,150 Nice. 537 00:25:06,150 --> 00:25:06,650 OK. 538 00:25:06,650 --> 00:25:07,655 [APPLAUSE] 539 00:25:07,655 --> 00:25:09,620 [LAUGHS] How about one final flourish? 540 00:25:09,620 --> 00:25:12,440 How about, Spot, instead of "off, on, off," 541 00:25:12,440 --> 00:25:16,280 let's go ahead and do "off, on, on"? 542 00:25:16,280 --> 00:25:20,810 So think, in your mind's eye, what the answer should be. 543 00:25:20,810 --> 00:25:24,104 All right, Spot, "off, on, on." 544 00:25:24,104 --> 00:25:27,420 [SPOT LANDING ON THE STAGE] 545 00:25:27,420 --> 00:25:27,920 546 00:25:27,920 --> 00:25:28,460 OK. 547 00:25:28,460 --> 00:25:30,830 And a round of applause for, Spot, as well. 548 00:25:30,830 --> 00:25:31,816 [LAUGHS] 549 00:25:31,816 --> 00:25:33,790 [APPLAUSE] 550 00:25:33,790 --> 00:25:36,450 So this is to say, no matter how-- 551 00:25:36,450 --> 00:25:37,140 thank you, Spot. 552 00:25:37,140 --> 00:25:40,620 No matter how fancy today's hardware or software is, 553 00:25:40,620 --> 00:25:42,720 it really just boils down to representing 554 00:25:42,720 --> 00:25:44,838 information and instructions. 555 00:25:44,838 --> 00:25:47,130 And computers, and phones, and the like really are just 556 00:25:47,130 --> 00:25:51,460 operating on those same pieces of information, 557 00:25:51,460 --> 00:25:55,240 whether implemented in 0's and 1's or with, really, anything else. 558 00:25:55,240 --> 00:25:55,740 All right. 559 00:25:55,740 --> 00:25:59,880 So, where can we take this, once we have this agreed-upon system 560 00:25:59,880 --> 00:26:03,030 for representing [LAUGHS] information? 561 00:26:03,030 --> 00:26:06,960 Well, it turns out that using three bits, three 0's and 1's, at a time, 562 00:26:06,960 --> 00:26:08,700 isn't actually all that useful. 563 00:26:08,700 --> 00:26:12,240 And you and I, even in conversation, don't often say the word "bit." 564 00:26:12,240 --> 00:26:13,500 We say the word "byte." 565 00:26:13,500 --> 00:26:15,280 And what is a byte, if familiar? 566 00:26:15,280 --> 00:26:15,780 Yeah? 567 00:26:15,780 --> 00:26:16,750 AUDIENCE: It's eight bits. 568 00:26:16,750 --> 00:26:18,417 DAVID J. MALAN: So it's just eight bits. 569 00:26:18,417 --> 00:26:20,200 It's just a more useful unit of measure. 570 00:26:20,200 --> 00:26:22,715 And it happens to be a power of 2, 2 to the third, 571 00:26:22,715 --> 00:26:24,340 which just makes math work out cleanly. 572 00:26:24,340 --> 00:26:27,610 But it's just a convention, to have more interesting units of measure 573 00:26:27,610 --> 00:26:28,540 than individual bits. 574 00:26:28,540 --> 00:26:30,350 So a byte is eight bits. 575 00:26:30,350 --> 00:26:34,690 So, for instance, this represents, using eight bits, eight light bulbs, 576 00:26:34,690 --> 00:26:36,460 the number you and I know is 0. 577 00:26:36,460 --> 00:26:40,960 And this byte of all 1 bits-- 578 00:26:40,960 --> 00:26:46,040 now you've got to do some quick math-- represents what number, instead? 579 00:26:46,040 --> 00:26:48,657 So it's all 1's; eight of them, total. 580 00:26:48,657 --> 00:26:49,990 How about over here, on the end? 581 00:26:49,990 --> 00:26:51,050 AUDIENCE: 255. 582 00:26:51,050 --> 00:26:52,992 DAVID J. MALAN: So it's, indeed, 255. 583 00:26:52,992 --> 00:26:54,700 Now, that's not the kind of math that you 584 00:26:54,700 --> 00:26:57,310 need to do in your head for a class like this, but you could. 585 00:26:57,310 --> 00:27:04,690 This is the ones place, twos, fours, eight, 16, 32, 64, 128. 586 00:27:04,690 --> 00:27:08,800 And because they're all 1, you just have to add up all of those columns' values. 587 00:27:08,800 --> 00:27:10,570 And you get 255. 588 00:27:10,570 --> 00:27:13,690 But a little mental trick, too, is that, if you've got eight bits 589 00:27:13,690 --> 00:27:17,270 and each of them can be two possible values, 0 or 1, 590 00:27:17,270 --> 00:27:21,740 that's like 2 possibilities here times 2 times 2 times 2 times 2, eight times. 591 00:27:21,740 --> 00:27:25,310 So that's 2 to the eighth, so that is maybe a little easier to do. 592 00:27:25,310 --> 00:27:26,720 That's 256. 593 00:27:26,720 --> 00:27:29,780 Or easier, in the sense that you get used to seeing these numbers in CS. 594 00:27:29,780 --> 00:27:31,220 That's 256. 595 00:27:31,220 --> 00:27:32,030 But wait a minute. 596 00:27:32,030 --> 00:27:35,300 How do I reconcile this with your 255? 597 00:27:35,300 --> 00:27:36,650 Because you start at 0. 598 00:27:36,650 --> 00:27:41,120 So you lose one on the high end because we started counting and representing 599 00:27:41,120 --> 00:27:42,830 the number, like 0. 600 00:27:42,830 --> 00:27:43,760 All right. 601 00:27:43,760 --> 00:27:47,570 Questions on how we've represented just numbers or, for instance, 602 00:27:47,570 --> 00:27:51,600 instructions to Spot, thus far? 603 00:27:51,600 --> 00:27:57,410 Any questions on binary, unary, or the like? 604 00:27:57,410 --> 00:27:58,010 No? 605 00:27:58,010 --> 00:28:01,137 All right, so seeing none, let's let things escalate a bit. 606 00:28:01,137 --> 00:28:03,470 So how do you represent letters because, obviously, this 607 00:28:03,470 --> 00:28:05,262 makes our devices more useful, whether it's 608 00:28:05,262 --> 00:28:07,020 in English or any other human language. 609 00:28:07,020 --> 00:28:10,740 How could we go about representing the letter A, for instance? 610 00:28:10,740 --> 00:28:13,370 If, at the end of the day, all our computers, 611 00:28:13,370 --> 00:28:17,390 all our phones have access to is electricity; or, equivalently, 612 00:28:17,390 --> 00:28:20,570 switches; or, metaphorically, tiny little light bulbs 613 00:28:20,570 --> 00:28:23,750 inside of them that can be on and off-- that's it. 614 00:28:23,750 --> 00:28:26,990 There's no more building blocks to give you. 615 00:28:26,990 --> 00:28:30,530 How could we represent something like the letter A? 616 00:28:30,530 --> 00:28:32,000 Yeah, how about here? 617 00:28:32,000 --> 00:28:32,812 Yeah? 618 00:28:32,812 --> 00:28:34,312 AUDIENCE: You could assign a number. 619 00:28:34,312 --> 00:28:35,343 DAVID J. MALAN: Perfect. 620 00:28:35,343 --> 00:28:37,260 So we could just assign every letter a number. 621 00:28:37,260 --> 00:28:38,677 And we could do this super simply. 622 00:28:38,677 --> 00:28:42,660 Maybe 0 is A, and 1 is B. Or maybe 1 is A, 623 00:28:42,660 --> 00:28:46,110 and 2 is B. It doesn't really matter, so long as we all agree and we all 624 00:28:46,110 --> 00:28:48,660 use the same types of computers, in some sense, ultimately. 625 00:28:48,660 --> 00:28:51,730 Well, for various reasons, the humans that designed this system, 626 00:28:51,730 --> 00:28:53,160 they went with the number 65. 627 00:28:53,160 --> 00:28:57,540 So, nowadays, anytime your computer is showing you the capital letter 628 00:28:57,540 --> 00:29:00,690 A on the screen, underneath the hood, so to speak, 629 00:29:00,690 --> 00:29:06,780 it's actually storing a pattern of 0's and 1's that represents the number 65. 630 00:29:06,780 --> 00:29:09,930 And it tends to use seven bits or, typically, eight bits, total, 631 00:29:09,930 --> 00:29:12,790 even if it doesn't need all of those bits in total. 632 00:29:12,790 --> 00:29:14,980 So how do we get there? 633 00:29:14,980 --> 00:29:17,490 Well, here, for instance, is that same pattern. 634 00:29:17,490 --> 00:29:19,980 Here is that pattern of bits that represents 65. 635 00:29:19,980 --> 00:29:20,520 And why? 636 00:29:20,520 --> 00:29:22,200 Well, quick check here. 637 00:29:22,200 --> 00:29:29,160 This is the ones place, twos, fours, eights, 16, 32, 64's place. 638 00:29:29,160 --> 00:29:32,640 OK, so 64 plus 1 gives me 65. 639 00:29:32,640 --> 00:29:36,830 So that is to say here's how a computer, using some light switches, so to speak, 640 00:29:36,830 --> 00:29:38,620 would represent the number 65. 641 00:29:38,620 --> 00:29:41,540 And our Macs, our PCs, our phones just all know this. 642 00:29:41,540 --> 00:29:44,410 So whenever they see that in their memory, so to speak, 643 00:29:44,410 --> 00:29:47,560 they show a capital letter A on the screen. 644 00:29:47,560 --> 00:29:48,520 So that's it. 645 00:29:48,520 --> 00:29:51,250 That's the system known as ASCII, the American Standard 646 00:29:51,250 --> 00:29:52,840 Code for Information Interchange. 647 00:29:52,840 --> 00:29:57,340 And the A is actually operative there because we're only talking, thus far, 648 00:29:57,340 --> 00:29:59,500 about English letters in our alphabet. 649 00:29:59,500 --> 00:30:02,530 And, in fact, I claimed, a moment ago, that we only use 650 00:30:02,530 --> 00:30:06,250 seven, maybe eight bits to represent letters of an alphabet. 651 00:30:06,250 --> 00:30:08,410 So, just to come back to you, if I may, how many 652 00:30:08,410 --> 00:30:10,900 possible letters of the alphabet could-- how 653 00:30:10,900 --> 00:30:14,350 many possible letters of any alphabet could we represent with eight bits? 654 00:30:14,350 --> 00:30:15,310 AUDIENCE: 256. 655 00:30:15,310 --> 00:30:18,400 DAVID J. MALAN: 256, the numbers 0 through 255. 656 00:30:18,400 --> 00:30:20,650 Now, that's more than enough for English because we've 657 00:30:20,650 --> 00:30:23,498 got A through Z, uppercase, lowercase, a bunch of numbers, 658 00:30:23,498 --> 00:30:24,790 a bunch of punctuation symbols. 659 00:30:24,790 --> 00:30:28,660 But in a lot of languages, with accented characters, a lot of Asian characters, 660 00:30:28,660 --> 00:30:32,230 this is not nearly enough memory or bits with which 661 00:30:32,230 --> 00:30:34,717 to represent all of those possible values. 662 00:30:34,717 --> 00:30:36,550 So we need to do a little better than ASCII, 663 00:30:36,550 --> 00:30:39,200 but we can build on top of what they did years ago. 664 00:30:39,200 --> 00:30:41,080 So here is a chart of ASCII codes. 665 00:30:41,080 --> 00:30:44,270 It's just a bunch of columns showing us the mapping between letters 666 00:30:44,270 --> 00:30:44,770 and numbers. 667 00:30:44,770 --> 00:30:49,420 So, for instance, up here is the capital letter A, 65; capital B, 66; 668 00:30:49,420 --> 00:30:52,060 capital C, 67; dot, dot, dot. 669 00:30:52,060 --> 00:30:56,333 72 is H. 73 is I and so forth. 670 00:30:56,333 --> 00:30:58,750 There's some weird things over here, like special symbols, 671 00:30:58,750 --> 00:31:00,125 that we'll learn about over time. 672 00:31:00,125 --> 00:31:02,230 But there's a mapping between every English letter 673 00:31:02,230 --> 00:31:04,810 of the alphabet and some number, just as you'd propose, 674 00:31:04,810 --> 00:31:06,710 both for uppercase and lowercase. 675 00:31:06,710 --> 00:31:10,580 So, for instance, if we highlight just a few of these for now 676 00:31:10,580 --> 00:31:14,998 and I say that I've just received a text message or an email that, 677 00:31:14,998 --> 00:31:17,290 underneath the hood, so to speak, if I have the ability 678 00:31:17,290 --> 00:31:22,930 to look at what switches are on and off, I received this message here. 679 00:31:22,930 --> 00:31:26,020 Well, first-- and this is not what CS is about, but just fun fact. 680 00:31:26,020 --> 00:31:29,470 Does anyone know what number this would represent in decimal, 681 00:31:29,470 --> 00:31:34,565 if this is the binary pattern, like ones place, twos place? 682 00:31:34,565 --> 00:31:35,420 AUDIENCE: 72? 683 00:31:35,420 --> 00:31:37,080 DAVID J. MALAN: 72 is correct. 684 00:31:37,080 --> 00:31:39,600 And again, not, intellectually, all that interesting 685 00:31:39,600 --> 00:31:41,780 and this is not the kind of math that we spend all day as CS-- 686 00:31:41,780 --> 00:31:42,905 a computer scientist doing. 687 00:31:42,905 --> 00:31:45,380 But it's just following the same darn pattern, which 688 00:31:45,380 --> 00:31:47,780 is to say it might look cryptic, but, conceptually, 689 00:31:47,780 --> 00:31:50,542 intellectually, it ultimately is exactly as we did before. 690 00:31:50,542 --> 00:31:52,250 So, yes, I'll spoil the rest of the math. 691 00:31:52,250 --> 00:31:54,860 It's 72, 73, 33. 692 00:31:54,860 --> 00:31:58,370 Now, anyone remember, in your mind's eye, what message we just spelled? 693 00:31:58,370 --> 00:31:59,180 AUDIENCE: Hi. 694 00:31:59,180 --> 00:31:59,810 AUDIENCE: Hi. 695 00:31:59,810 --> 00:32:01,520 DAVID J. MALAN: Yeah, so it is, in fact, "Hi!" 696 00:32:01,520 --> 00:32:03,270 Though, no one really said that excitedly. 697 00:32:03,270 --> 00:32:04,580 What's the 33, if you noticed? 698 00:32:04,580 --> 00:32:05,600 AUDIENCE: Exclamation point. 699 00:32:05,600 --> 00:32:06,770 DAVID J. MALAN: OK, so a lot of people noticed. 700 00:32:06,770 --> 00:32:08,630 Yes, it's an exclamation point. 701 00:32:08,630 --> 00:32:11,300 And that's, indeed, noticeable right here. 702 00:32:11,300 --> 00:32:13,063 33 is the exclamation point. 703 00:32:13,063 --> 00:32:15,480 And that's just something, eventually, that might sink in. 704 00:32:15,480 --> 00:32:18,350 But, for the most part, if you remember capital A is 65, 705 00:32:18,350 --> 00:32:22,100 you can figure out at least 25 other answers to these kinds of questions 706 00:32:22,100 --> 00:32:24,060 because they're all contiguous like that. 707 00:32:24,060 --> 00:32:25,740 So there's the exclamation point. 708 00:32:25,740 --> 00:32:30,350 But at the end of the day, we might just have this mapping known as ASCII. 709 00:32:30,350 --> 00:32:33,000 And it's how our phones, and computers, and devices, more 710 00:32:33,000 --> 00:32:35,310 generally, actually store information. 711 00:32:35,310 --> 00:32:37,050 So we thought we'd make-- 712 00:32:37,050 --> 00:32:38,970 maybe take a little pressure off of me here. 713 00:32:38,970 --> 00:32:41,550 And could we maybe flip things around? 714 00:32:41,550 --> 00:32:44,160 How about we try applying this newfound knowledge-- 715 00:32:44,160 --> 00:32:48,430 if it's, indeed, new to you-- with seven volunteers, seven bits, if we could? 716 00:32:48,430 --> 00:32:48,930 OK. 717 00:32:48,930 --> 00:32:49,847 I saw your hand first. 718 00:32:49,847 --> 00:32:50,640 Come on down. 719 00:32:50,640 --> 00:32:52,650 Maybe your hand, there. 720 00:32:52,650 --> 00:32:54,870 OK, three, come on down over here. 721 00:32:54,870 --> 00:32:56,940 How about four and five? 722 00:32:56,940 --> 00:32:57,810 Yep, come on down. 723 00:32:57,810 --> 00:32:59,018 Yep, in the black shirt, yep. 724 00:32:59,018 --> 00:33:00,393 How about let me go farther back? 725 00:33:00,393 --> 00:33:01,890 How about in the green, over there? 726 00:33:01,890 --> 00:33:03,460 And how about you, seven, over here? 727 00:33:03,460 --> 00:33:03,960 All right. 728 00:33:03,960 --> 00:33:04,650 Come on down. 729 00:33:04,650 --> 00:33:05,790 [CHATTER] 730 00:33:05,790 --> 00:33:08,400 Come on down. 731 00:33:08,400 --> 00:33:10,600 So a round of applause for our brave volunteers. 732 00:33:10,600 --> 00:33:12,740 [APPLAUSE] 733 00:33:12,740 --> 00:33:13,850 All right. 734 00:33:13,850 --> 00:33:17,060 So if you'd like to stand, roughly, side by side, here in the middle 735 00:33:17,060 --> 00:33:17,830 of the stage. 736 00:33:17,830 --> 00:33:20,430 737 00:33:20,430 --> 00:33:22,530 First of all, thank you. 738 00:33:22,530 --> 00:33:23,030 Let's see. 739 00:33:23,030 --> 00:33:25,250 1, 2, 3, 4, 5, 6, 7, perfect. 740 00:33:25,250 --> 00:33:25,880 OK. 741 00:33:25,880 --> 00:33:29,900 And let's go all the way over to this place, here. 742 00:33:29,900 --> 00:33:32,600 If you would like to introduce yourself to the class. 743 00:33:32,600 --> 00:33:34,418 RACHEL RICHEY: I'm Rachel Richey. 744 00:33:34,418 --> 00:33:35,210 DAVID J. MALAN: OK. 745 00:33:35,210 --> 00:33:36,128 And what year? 746 00:33:36,128 --> 00:33:36,920 Anything about you? 747 00:33:36,920 --> 00:33:38,915 RACHEL RICHEY: Oh, first year, concentrating in CS. 748 00:33:38,915 --> 00:33:39,707 DAVID J. MALAN: OK. 749 00:33:39,707 --> 00:33:40,670 Welcome to the stage. 750 00:33:40,670 --> 00:33:41,210 Next. 751 00:33:41,210 --> 00:33:42,080 SPEAKER: Hi. 752 00:33:42,080 --> 00:33:46,190 I'm [? Kang. ?] Also a first-year concentrating in CS. 753 00:33:46,190 --> 00:33:47,390 SPEAKER: Hello. 754 00:33:47,390 --> 00:33:52,665 My name is [? Lam. ?] I'm a [INAUDIBLE] student from education department. 755 00:33:52,665 --> 00:33:53,540 DAVID J. MALAN: Nice. 756 00:33:53,540 --> 00:33:53,810 OK. 757 00:33:53,810 --> 00:33:54,368 Next. 758 00:33:54,368 --> 00:33:55,160 JORDAN MITTLER: Hi. 759 00:33:55,160 --> 00:33:59,120 I'm Jordan Mittler, concentrating in economics and maybe some CS. 760 00:33:59,120 --> 00:34:00,110 SPEAKER: So, hi. 761 00:34:00,110 --> 00:34:02,645 I'm [? Natalia. ?] First year, and I want to do CS. 762 00:34:02,645 --> 00:34:03,435 SPEAKER: Hi. 763 00:34:03,435 --> 00:34:05,810 I'm [? Khadija. ?] I'm a first-year, and I want to do CS. 764 00:34:05,810 --> 00:34:07,080 DAVID J. MALAN: [LAUGHS]. 765 00:34:07,080 --> 00:34:08,030 SPEAKER: Hello. 766 00:34:08,030 --> 00:34:11,418 I'm [? Caleb. ?] And, once again, first year, concentrating in CS. 767 00:34:11,418 --> 00:34:12,210 DAVID J. MALAN: OK. 768 00:34:12,210 --> 00:34:12,710 Wonderful. 769 00:34:12,710 --> 00:34:13,770 A pattern, yes. 770 00:34:13,770 --> 00:34:14,340 Thank you. 771 00:34:14,340 --> 00:34:14,880 Thank you. 772 00:34:14,880 --> 00:34:15,969 [APPLAUSE] 773 00:34:15,969 --> 00:34:20,010 So, if you haven't guessed already, each of these volunteers 774 00:34:20,010 --> 00:34:23,429 is going to represent a bit, from left to right, or right to left, 775 00:34:23,429 --> 00:34:24,010 in this case. 776 00:34:24,010 --> 00:34:24,750 So let's see. 777 00:34:24,750 --> 00:34:27,719 If you want to represent-- how about the twos place? 778 00:34:27,719 --> 00:34:37,350 How about the fours place, the eighths place, 16ths place, 32's, 64, and 128? 779 00:34:37,350 --> 00:34:39,060 Although, wait a-- I think I screwed up. 780 00:34:39,060 --> 00:34:40,889 We needed one-- eighth volunteer. 781 00:34:40,889 --> 00:34:42,974 I think you know-- well, I think-- 782 00:34:42,974 --> 00:34:45,330 [CLEARS THROAT] Spot? 783 00:34:45,330 --> 00:34:46,108 OK. 784 00:34:46,108 --> 00:34:46,650 Come on over. 785 00:34:46,650 --> 00:34:49,567 If you guys could step forward a little bit, and then scooch this way, 786 00:34:49,567 --> 00:34:51,090 just to give Spot some room. 787 00:34:51,090 --> 00:34:52,650 [FOOTSTEPS] 788 00:34:52,650 --> 00:34:55,239 So Spot will represent the ones place. 789 00:34:55,239 --> 00:34:58,440 Now, what our volunteers have on the back of their sheets of paper 790 00:34:58,440 --> 00:34:59,670 are little instructions. 791 00:34:59,670 --> 00:35:05,460 We're going to spell out a three-letter word in English by using three bytes, 792 00:35:05,460 --> 00:35:08,170 from left to right, because now we have eight volunteers. 793 00:35:08,170 --> 00:35:10,503 I'm going to propose that you raise your hand, if you're 794 00:35:10,503 --> 00:35:12,185 supposed to represent a 1. 795 00:35:12,185 --> 00:35:14,310 Or you just stand there, without raising your hand, 796 00:35:14,310 --> 00:35:15,780 if you're meant to represent a 0. 797 00:35:15,780 --> 00:35:18,450 And what we'll have the audience do is do the quick math 798 00:35:18,450 --> 00:35:22,170 to figure out-- one, two, three-- each letter, what number is it. 799 00:35:22,170 --> 00:35:23,430 What letter is it? 800 00:35:23,430 --> 00:35:26,370 And we'll see what word that we have finally spelled. 801 00:35:26,370 --> 00:35:26,880 All right. 802 00:35:26,880 --> 00:35:28,410 So, in round one-- 803 00:35:28,410 --> 00:35:31,410 you have instructions on your back of your sheet that will tell you to-- 804 00:35:31,410 --> 00:35:32,580 what your number is. 805 00:35:32,580 --> 00:35:33,660 If you're 0, stand there. 806 00:35:33,660 --> 00:35:35,010 If you're a 1, raise your hand. 807 00:35:35,010 --> 00:35:37,700 808 00:35:37,700 --> 00:35:40,060 [PAPER RUSTLING] 809 00:35:40,060 --> 00:35:43,420 What number do these guys seem to be representing? 810 00:35:43,420 --> 00:35:44,560 AUDIENCE: 68. 811 00:35:44,560 --> 00:35:46,360 DAVID J. MALAN: 66, I think. 812 00:35:46,360 --> 00:35:49,495 64 plus 2, so 66, which is the letter-- 813 00:35:49,495 --> 00:35:50,260 AUDIENCE: B. 814 00:35:50,260 --> 00:35:52,930 DAVID J. MALAN: OK, so, B. OK, so, B. All right. 815 00:35:52,930 --> 00:35:54,470 Hands down. 816 00:35:54,470 --> 00:35:57,565 Second letter is going to be spelled how? 817 00:35:57,565 --> 00:36:01,160 818 00:36:01,160 --> 00:36:02,202 [SPOT LANDS ON THE STAGE] 819 00:36:02,202 --> 00:36:02,827 AUDIENCE: Whoa. 820 00:36:02,827 --> 00:36:03,530 AUDIENCE: Whoa. 821 00:36:03,530 --> 00:36:04,829 AUDIENCE: Whoa. 822 00:36:04,829 --> 00:36:07,570 DAVID J. MALAN: [LAUGHS] All right. 823 00:36:07,570 --> 00:36:09,670 What are we spelling now? 824 00:36:09,670 --> 00:36:11,635 [INDISTINCT CHATTER] 825 00:36:11,635 --> 00:36:15,580 I think-- psst, yep, OK. 826 00:36:15,580 --> 00:36:17,081 Yeah, I think you're one. 827 00:36:17,081 --> 00:36:19,490 [LAUGHTER] 828 00:36:19,490 --> 00:36:20,980 OK. 829 00:36:20,980 --> 00:36:23,430 Now what number are we spelling? 830 00:36:23,430 --> 00:36:24,370 AUDIENCE: 79 831 00:36:24,370 --> 00:36:26,770 DAVID J. MALAN: 79, I heard, which is the letter? 832 00:36:26,770 --> 00:36:27,383 AUDIENCE: O. 833 00:36:27,383 --> 00:36:28,300 DAVID J. MALAN: O. OK. 834 00:36:28,300 --> 00:36:29,320 So hands down. 835 00:36:29,320 --> 00:36:30,100 Thank you, Spot. 836 00:36:30,100 --> 00:36:31,460 One final flourish. 837 00:36:31,460 --> 00:36:33,250 So we've spelled B-O-- 838 00:36:33,250 --> 00:36:34,855 third letter, go ahead. 839 00:36:34,855 --> 00:36:37,942 840 00:36:37,942 --> 00:36:40,230 [SPOT LANDS ON THE STAGE] 841 00:36:40,230 --> 00:36:42,885 What number, now, is this? 842 00:36:42,885 --> 00:36:43,815 AUDIENCE: 87. 843 00:36:43,815 --> 00:36:44,460 AUDIENCE: 87. 844 00:36:44,460 --> 00:36:45,460 DAVID J. MALAN: I heard it here, 80-- 845 00:36:45,460 --> 00:36:46,320 AUDIENCE: Seven. 846 00:36:46,320 --> 00:36:46,875 DAVID J. MALAN: --seven, which is? 847 00:36:46,875 --> 00:36:47,505 AUDIENCE: W. 848 00:36:47,505 --> 00:36:49,620 DAVID J. MALAN: W, which, of course, spells "bow." 849 00:36:49,620 --> 00:36:53,437 So if our volunteers could take a bow, Spot included. 850 00:36:53,437 --> 00:36:56,636 [APPLAUSE] 851 00:36:56,636 --> 00:36:58,010 852 00:36:58,010 --> 00:37:01,540 So this will make more sense in week one, 853 00:37:01,540 --> 00:37:04,750 when we have an assignment involving a certain someone from the Nintendo 854 00:37:04,750 --> 00:37:04,900 World. 855 00:37:04,900 --> 00:37:06,760 But we have a lovely parting gift for each of you. 856 00:37:06,760 --> 00:37:07,510 SPEAKER: Thank you. 857 00:37:07,510 --> 00:37:07,630 [LAUGHS] 858 00:37:07,630 --> 00:37:08,180 DAVID J. MALAN: Thank you for volunteering. 859 00:37:08,180 --> 00:37:08,980 SPEAKER: Thanks. 860 00:37:08,980 --> 00:37:11,897 DAVID J. MALAN: You might need to share it with the folks next to you. 861 00:37:11,897 --> 00:37:15,106 [CHATTER] 862 00:37:15,106 --> 00:37:18,600 863 00:37:18,600 --> 00:37:19,470 Oop, here we go. 864 00:37:19,470 --> 00:37:19,970 There we go. 865 00:37:19,970 --> 00:37:20,360 Thank you-- 866 00:37:20,360 --> 00:37:21,080 SPEAKER: Thank you. 867 00:37:21,080 --> 00:37:21,380 RACHEL RICHEY: Thank you. 868 00:37:21,380 --> 00:37:21,560 DAVID J. MALAN: --so much. 869 00:37:21,560 --> 00:37:23,250 One more round of applause, if we could, for our volunteers. 870 00:37:23,250 --> 00:37:23,810 Thank you. 871 00:37:23,810 --> 00:37:24,734 [APPLAUSE] 872 00:37:24,734 --> 00:37:26,120 Did you lose something? 873 00:37:26,120 --> 00:37:27,490 OK. 874 00:37:27,490 --> 00:37:28,030 All right. 875 00:37:28,030 --> 00:37:31,190 So, [LAUGHS] Spot's had it. 876 00:37:31,190 --> 00:37:34,060 So let's see, then, if we've solved, now, 877 00:37:34,060 --> 00:37:36,640 the problem of representing English letters of the alphabet, 878 00:37:36,640 --> 00:37:39,850 being able to spell out words like "bow," B-O-W. What if we actually do 879 00:37:39,850 --> 00:37:41,210 have accented characters? 880 00:37:41,210 --> 00:37:43,883 What if we do have other glyphs that we want to represent? 881 00:37:43,883 --> 00:37:47,050 Well, here, of course, is a standard US English keyboard, which a lot of you 882 00:37:47,050 --> 00:37:47,650 might have. 883 00:37:47,650 --> 00:37:50,260 But there's also characters that you can type much more 884 00:37:50,260 --> 00:37:52,930 easily if you have a foreign keyboard, relative to the US, 885 00:37:52,930 --> 00:37:55,780 or with certain keystrokes on your own Mac, PC, and phone. 886 00:37:55,780 --> 00:37:59,230 But, nowadays, too, there's this menu that, probably, you've 887 00:37:59,230 --> 00:38:03,400 used in the past hour or two to actually send some emoji. 888 00:38:03,400 --> 00:38:06,040 An emoji, even though they look like pictures 889 00:38:06,040 --> 00:38:08,080 and they actually are pictures on the screen, 890 00:38:08,080 --> 00:38:13,120 they're, technically, just characters, characters of an emoji alphabet 891 00:38:13,120 --> 00:38:16,330 that happened to use a certain pattern of 0's and 1's to represent 892 00:38:16,330 --> 00:38:19,880 each of these faces, each of these people, and places, and things. 893 00:38:19,880 --> 00:38:22,540 And it turns out that one of the reasons that we have just 894 00:38:22,540 --> 00:38:29,240 so many [LAUGHS] such characters nowadays is because we now 895 00:38:29,240 --> 00:38:31,370 use Unicode instead of ASCII. 896 00:38:31,370 --> 00:38:34,370 So Unicode is a superset, so to speak, of ASCII, 897 00:38:34,370 --> 00:38:38,030 which is to say that we, humans, realized, some time ago, that just 898 00:38:38,030 --> 00:38:40,370 using eight bits to represent letters of the alphabet 899 00:38:40,370 --> 00:38:43,070 certainly isn't very good when we want to represent 900 00:38:43,070 --> 00:38:44,960 other, non-English languages. 901 00:38:44,960 --> 00:38:47,240 So Unicode doesn't just use eight bits. 902 00:38:47,240 --> 00:38:52,520 It sometimes uses 16 bits per character, sometimes 24 bits per character, 903 00:38:52,520 --> 00:38:55,610 and sometimes even 32 bits per character. 904 00:38:55,610 --> 00:38:56,690 Now, why those numbers? 905 00:38:56,690 --> 00:39:00,680 That's just one byte, two bytes, three bytes, or four bytes. 906 00:39:00,680 --> 00:39:02,132 And that gives us-- 907 00:39:02,132 --> 00:39:02,840 does anyone know? 908 00:39:02,840 --> 00:39:06,380 That gives us the ability to represent as many as 4 909 00:39:06,380 --> 00:39:08,630 billion possible characters. 910 00:39:08,630 --> 00:39:12,150 Because if the longest one is 32 bits, that's 2 to the 32, 911 00:39:12,150 --> 00:39:15,090 which, if you do out the math, trust me, is roughly 4 billion. 912 00:39:15,090 --> 00:39:16,430 So that's a lot of characters. 913 00:39:16,430 --> 00:39:19,040 And we've got a lot of room, then, for these emoji. 914 00:39:19,040 --> 00:39:22,130 But it's not just about having fun, pictorially, on the screen. 915 00:39:22,130 --> 00:39:27,830 Unicode's mission really is to represent and to preserve all human languages 916 00:39:27,830 --> 00:39:31,530 digitally, both past, present, and future. 917 00:39:31,530 --> 00:39:35,420 So it is really about capturing the entirety of human knowledge, 918 00:39:35,420 --> 00:39:37,430 as we've expressed it in language, but also 919 00:39:37,430 --> 00:39:42,020 giving this newfound ability that's been used centuries ago, too-- in writings, 920 00:39:42,020 --> 00:39:44,300 on walls, and the like-- pictograms via which 921 00:39:44,300 --> 00:39:46,640 we can still communicate, even independently 922 00:39:46,640 --> 00:39:48,030 of our own human language. 923 00:39:48,030 --> 00:39:51,320 So we'll reduce it, today, to just patterns of 0's and 1's, but 924 00:39:51,320 --> 00:39:56,190 the problem being solved is much greater and well-beyond CS, itself, there. 925 00:39:56,190 --> 00:39:58,610 So here is a pattern of 0's and 1's using 926 00:39:58,610 --> 00:40:04,310 Unicode, so more than eight bits, that represents a very popular emoji, which 927 00:40:04,310 --> 00:40:06,090 might be a bit of a hint. 928 00:40:06,090 --> 00:40:08,870 This is the most popular emoji, as of last year, at least, 929 00:40:08,870 --> 00:40:10,330 statistically, internationally. 930 00:40:10,330 --> 00:40:13,078 [INTERPOSING VOICES] 931 00:40:13,078 --> 00:40:14,370 DAVID J. MALAN: Does this help? 932 00:40:14,370 --> 00:40:16,520 It's, roughly, this number here. 933 00:40:16,520 --> 00:40:17,240 No? 934 00:40:17,240 --> 00:40:19,080 It's this one here. 935 00:40:19,080 --> 00:40:23,360 So this is the most popular emoji, by most measures, as of last year. 936 00:40:23,360 --> 00:40:25,170 But it doesn't always look like this. 937 00:40:25,170 --> 00:40:28,190 Those of you who have a Mac or an iPhone recognize this symbol, perhaps, 938 00:40:28,190 --> 00:40:28,690 immediately. 939 00:40:28,690 --> 00:40:31,100 Those of you with Android devices or other platforms 940 00:40:31,100 --> 00:40:35,310 might notice that it's the same idea, but it's a little bit different. 941 00:40:35,310 --> 00:40:38,660 And this is because, too, emojis, at the end of the day, 942 00:40:38,660 --> 00:40:41,420 just represent character, but those characters can be drawn, 943 00:40:41,420 --> 00:40:43,070 can be painted in different ways. 944 00:40:43,070 --> 00:40:46,130 And reasonable people will interpret differently 945 00:40:46,130 --> 00:40:49,880 this emoji, whose official name is "face with tears of joy." 946 00:40:49,880 --> 00:40:52,130 And, indeed, Google interprets it a little differently 947 00:40:52,130 --> 00:40:55,813 from Apple, versus Microsoft, versus Meta, versus other companies, as well. 948 00:40:55,813 --> 00:40:57,980 So you can almost think of those different companies 949 00:40:57,980 --> 00:41:00,230 as having different fonts for emoji. 950 00:41:00,230 --> 00:41:04,160 And that really starts to connect things to the world of text and characters. 951 00:41:04,160 --> 00:41:05,720 So, just so you've seen it. 952 00:41:05,720 --> 00:41:07,110 More on this, another time. 953 00:41:07,110 --> 00:41:10,980 It turns out that emoji and, really, characters, in general, 954 00:41:10,980 --> 00:41:13,430 we don't use binary 0's and 1's to represent them 955 00:41:13,430 --> 00:41:15,740 because no one, myself included, is going to recognize what's what. 956 00:41:15,740 --> 00:41:16,520 It's just too much math. 957 00:41:16,520 --> 00:41:17,480 It's not interesting. 958 00:41:17,480 --> 00:41:19,880 And even decimal numbers-- that was 4 billion or some-- 959 00:41:19,880 --> 00:41:22,260 I don't remember which number is which. 960 00:41:22,260 --> 00:41:24,410 So we represent things a little more compactly. 961 00:41:24,410 --> 00:41:26,510 And this, too, admittedly, still looks cryptic, 962 00:41:26,510 --> 00:41:30,770 but this is a Unicode code point that uses another system, mathematically, 963 00:41:30,770 --> 00:41:33,470 called base-16 or hexadecimal. 964 00:41:33,470 --> 00:41:34,670 More on that, another time. 965 00:41:34,670 --> 00:41:38,090 But it's just a way of representing numbers even more succinctly, 966 00:41:38,090 --> 00:41:41,270 writing less on the screen, because you're using not just 0 967 00:41:41,270 --> 00:41:42,590 through 9, as in decimal. 968 00:41:42,590 --> 00:41:46,010 But you're using A through F, as well, so a few letters 969 00:41:46,010 --> 00:41:47,670 of the English alphabet come into play. 970 00:41:47,670 --> 00:41:49,700 But, for now, that's just a little easier 971 00:41:49,700 --> 00:41:53,750 to remember, too, for people who care, that that is the number that 972 00:41:53,750 --> 00:41:55,880 represents "face with tears of joy." 973 00:41:55,880 --> 00:41:58,010 But what if we want a customized emoji? 974 00:41:58,010 --> 00:41:59,780 And this, increasingly, is the case. 975 00:41:59,780 --> 00:42:01,910 Here, for instance, are the five skin tones 976 00:42:01,910 --> 00:42:04,760 that phones, and laptops, and desktops, nowadays, support. 977 00:42:04,760 --> 00:42:07,802 It's based on something called the "Fitzpatrick scale," which essentially 978 00:42:07,802 --> 00:42:10,460 categorizes human skin tone into six or, in this case, five 979 00:42:10,460 --> 00:42:12,560 different categories, from lighter to darker. 980 00:42:12,560 --> 00:42:17,480 But this suggests that, wow, if we want to represent people 981 00:42:17,480 --> 00:42:22,040 with five different skin tones, like this, that could significantly 982 00:42:22,040 --> 00:42:25,130 increase how many unique patterns of 0's and 1's we 983 00:42:25,130 --> 00:42:26,890 need for every possible face. 984 00:42:26,890 --> 00:42:29,540 But if we think about it from an engineering perspective, 985 00:42:29,540 --> 00:42:33,068 we can actually just think of skin tone as modifying some default 986 00:42:33,068 --> 00:42:34,360 color, for better or for worse. 987 00:42:34,360 --> 00:42:37,450 And yellow is the de facto default, Simpson style. 988 00:42:37,450 --> 00:42:41,350 But to modify it to look more genuinely human-like, from lighter to darker, 989 00:42:41,350 --> 00:42:43,990 well, maybe we just use the same pattern of bits 990 00:42:43,990 --> 00:42:47,720 to represent a human thumb, for instance, thumbs up or thumbs down. 991 00:42:47,720 --> 00:42:51,210 And we just, then, modify that character to be displayed with a different skin 992 00:42:51,210 --> 00:42:51,710 tone. 993 00:42:51,710 --> 00:42:53,950 So, for instance, here, then, is the "thumbs up" 994 00:42:53,950 --> 00:42:55,750 that you might use on various platforms. 995 00:42:55,750 --> 00:42:59,200 And let me just stipulate that this is the Unicode code point. 996 00:42:59,200 --> 00:43:01,870 That is the number that Macs, PCs, and phones 997 00:43:01,870 --> 00:43:05,960 use underneath the hood to represent the default yellow "thumbs up." 998 00:43:05,960 --> 00:43:08,770 But if you want to give it a medium skin tone, 999 00:43:08,770 --> 00:43:12,370 you still use that same number, that same pattern of 0's and 1's, 1000 00:43:12,370 --> 00:43:13,930 or switches, underneath the hood. 1001 00:43:13,930 --> 00:43:17,620 But you use a few more switches that the computer or phone 1002 00:43:17,620 --> 00:43:20,800 will interpret as, "Oh, you don't want to see the default in yellow 1003 00:43:20,800 --> 00:43:23,890 because of this second number that's in the computer's memory somewhere. 1004 00:43:23,890 --> 00:43:27,170 You want me to adjust it to be the medium skin tone or any 1005 00:43:27,170 --> 00:43:29,010 of the other values, instead." 1006 00:43:29,010 --> 00:43:31,580 So that's the engineering solution to this problem 1007 00:43:31,580 --> 00:43:35,078 of just trying to represent different ranges of emoji here. 1008 00:43:35,078 --> 00:43:36,620 Well, what about something like this? 1009 00:43:36,620 --> 00:43:38,480 There's a lot more combinatorics, nowadays, 1010 00:43:38,480 --> 00:43:40,522 on your keyboard for relationships, for instance. 1011 00:43:40,522 --> 00:43:43,620 So here is a "couple with heart" here. 1012 00:43:43,620 --> 00:43:46,520 So the couple, here, of course, is represented with, apparently, 1013 00:43:46,520 --> 00:43:47,600 this number here. 1014 00:43:47,600 --> 00:43:48,255 But that's it. 1015 00:43:48,255 --> 00:43:50,630 But if you want to be more specific-- like man and woman, 1016 00:43:50,630 --> 00:43:53,240 or man-man, woman-woman-- it's the same idea, 1017 00:43:53,240 --> 00:43:56,630 but we just need to express ourselves a little-- with a little 1018 00:43:56,630 --> 00:43:57,600 more information. 1019 00:43:57,600 --> 00:44:00,560 So, for instance, the way the Unicode folks came up with, 1020 00:44:00,560 --> 00:44:03,830 years ago, to represent, for instance, a woman with a heart and a man, 1021 00:44:03,830 --> 00:44:06,480 from left to right, would be using these values. 1022 00:44:06,480 --> 00:44:08,900 So things just escalated quickly, but only 1023 00:44:08,900 --> 00:44:12,560 in the sense that we're using more bits, more 0's and 1's, to represent, 1024 00:44:12,560 --> 00:44:15,470 more expressively, this particular combination. 1025 00:44:15,470 --> 00:44:18,050 So this happens to be the number in Unicode 1026 00:44:18,050 --> 00:44:19,790 that represents the woman at left. 1027 00:44:19,790 --> 00:44:22,430 This is the number that represents the man at right. 1028 00:44:22,430 --> 00:44:25,160 And this is the pair of numbers that represents 1029 00:44:25,160 --> 00:44:29,550 the heart in the middle, sometimes red, sometimes pink, displayed here as pink. 1030 00:44:29,550 --> 00:44:32,510 But if we want to change the combination, for instance, to be, 1031 00:44:32,510 --> 00:44:33,920 say, woman-- 1032 00:44:33,920 --> 00:44:36,320 if we want to change the combination to be woman-woman, 1033 00:44:36,320 --> 00:44:39,200 notice that, now, the left and the rightmost numbers match. 1034 00:44:39,200 --> 00:44:42,290 Or if we flip it back to man-man, it's just using different numbers 1035 00:44:42,290 --> 00:44:43,790 on the tail end again. 1036 00:44:43,790 --> 00:44:48,380 And meanwhile, if I rewind, there's these two identical values here. 1037 00:44:48,380 --> 00:44:51,680 These are called zero-width joiners or ZWNJ characters. 1038 00:44:51,680 --> 00:44:55,460 It just is a special number that humans reserve to say, 1039 00:44:55,460 --> 00:45:00,210 glue the emoji at the left to the emoji on the right and so forth. 1040 00:45:00,210 --> 00:45:02,370 So it connects ideas in this way. 1041 00:45:02,370 --> 00:45:04,490 So there's actually a lot of emojis, nowadays, 1042 00:45:04,490 --> 00:45:07,370 that are a combination of different things. 1043 00:45:07,370 --> 00:45:09,650 "Heart on fire" is one that's, technically, 1044 00:45:09,650 --> 00:45:13,190 the combination of a heart emoji, the fire emoji, 1045 00:45:13,190 --> 00:45:16,110 joined together, numerically, in this way. 1046 00:45:16,110 --> 00:45:18,290 So computer scientists who come up with these things 1047 00:45:18,290 --> 00:45:21,290 are just reducing things to representations. 1048 00:45:21,290 --> 00:45:23,430 All we have at our disposal are 0's and 1's. 1049 00:45:23,430 --> 00:45:25,250 So we all just need to agree, ultimately-- 1050 00:45:25,250 --> 00:45:28,760 whether we're Google, Microsoft, or the like-- how we're going to standardize 1051 00:45:28,760 --> 00:45:31,030 these kinds of things as information. 1052 00:45:31,030 --> 00:45:36,520 Questions, then, on how characters are represented in a computer, 1053 00:45:36,520 --> 00:45:38,260 be it English or any other language? 1054 00:45:38,260 --> 00:45:38,760 Yeah. 1055 00:45:38,760 --> 00:45:40,630 AUDIENCE: How is the plus a number? 1056 00:45:40,630 --> 00:45:41,963 DAVID J. MALAN: How is the what? 1057 00:45:41,963 --> 00:45:43,930 AUDIENCE: The plus, the U+. 1058 00:45:43,930 --> 00:45:46,600 DAVID J. MALAN: Oh, the U+ is just a convention, really. 1059 00:45:46,600 --> 00:45:49,820 So U+ represents a special Unicode character, 1060 00:45:49,820 --> 00:45:51,790 which is a U with a plus in the middle. 1061 00:45:51,790 --> 00:45:54,590 And this is just the convention for saying, 1062 00:45:54,590 --> 00:45:58,600 hey, everyone, here comes a number that represents a Unicode code point. 1063 00:45:58,600 --> 00:46:00,070 The U and the 1 have no-- sorry. 1064 00:46:00,070 --> 00:46:02,278 The U and the plus have no mathematical significance. 1065 00:46:02,278 --> 00:46:05,470 It's just a visual clue to folks. 1066 00:46:05,470 --> 00:46:10,460 Other questions on representing text in this way? 1067 00:46:10,460 --> 00:46:10,960 All right. 1068 00:46:10,960 --> 00:46:12,240 So what about colors? 1069 00:46:12,240 --> 00:46:13,990 We've already started looking at pictures. 1070 00:46:13,990 --> 00:46:17,032 Well, how are those pictures, be it emojis or anything else, represented? 1071 00:46:17,032 --> 00:46:19,870 One of the most common ways is just with RGB-- 1072 00:46:19,870 --> 00:46:20,950 red, green, and blue. 1073 00:46:20,950 --> 00:46:24,700 It turns out that if we just keep track of how much red should 1074 00:46:24,700 --> 00:46:27,880 be on the screen, and how much green, and how much blue, combined together, 1075 00:46:27,880 --> 00:46:29,890 that gives us every color of the rainbow, 1076 00:46:29,890 --> 00:46:32,120 from white to black and everything in between. 1077 00:46:32,120 --> 00:46:35,620 So how do we represent an amount of red, and green, and blue? 1078 00:46:35,620 --> 00:46:37,690 Well, frankly, just with three different numbers. 1079 00:46:37,690 --> 00:46:40,030 And this is how computers typically represent colors. 1080 00:46:40,030 --> 00:46:43,220 Every one of the dots on your computer screen or your phone screen 1081 00:46:43,220 --> 00:46:44,390 is called a pixel. 1082 00:46:44,390 --> 00:46:50,130 And every single dot underneath the hood has three numbers associated with it, 1083 00:46:50,130 --> 00:46:53,000 so three numbers, three numbers, three numbers for every little dot. 1084 00:46:53,000 --> 00:46:56,420 And those three numbers, together, say how much red, green, and blue 1085 00:46:56,420 --> 00:46:59,040 should the device display at that location. 1086 00:46:59,040 --> 00:47:02,390 So, for instance, if you had a dot on your screen 1087 00:47:02,390 --> 00:47:07,520 that said, "use this much red, this much green this much blue," because each 1088 00:47:07,520 --> 00:47:11,820 of these numbers, I'll tell you, are one byte or eight bits, 1089 00:47:11,820 --> 00:47:15,710 which means the total possible values is 0 to 255-- 1090 00:47:15,710 --> 00:47:19,070 let me just ballpark that the 72, it feels like a medium amount of red 1091 00:47:19,070 --> 00:47:21,350 because it's in between 0 and 255. 1092 00:47:21,350 --> 00:47:25,590 73 is a medium amount of green, and 33 of blue is just a little bit. 1093 00:47:25,590 --> 00:47:29,480 So if you combine a medium amount of red, green, and a little bit of blue, 1094 00:47:29,480 --> 00:47:32,840 anyone want to guess what color of the rainbow this is? 1095 00:47:32,840 --> 00:47:33,507 AUDIENCE: Brown. 1096 00:47:33,507 --> 00:47:34,423 DAVID J. MALAN: Sorry? 1097 00:47:34,423 --> 00:47:35,190 AUDIENCE: Brown. 1098 00:47:35,190 --> 00:47:36,470 DAVID J. MALAN: Brown? 1099 00:47:36,470 --> 00:47:37,228 So, close. 1100 00:47:37,228 --> 00:47:39,020 It's a little more yellow than it is brown. 1101 00:47:39,020 --> 00:47:41,920 But if we combine them, it looks a little something like this. 1102 00:47:41,920 --> 00:47:43,887 This is just CS trivia, not something that even 1103 00:47:43,887 --> 00:47:46,970 I would be able to eyeball, unless I came up with that particular example. 1104 00:47:46,970 --> 00:47:48,607 But wait a minute. 1105 00:47:48,607 --> 00:47:49,940 We've seen these numbers before. 1106 00:47:49,940 --> 00:47:51,768 72, 73, 33 represented what-- 1107 00:47:51,768 --> 00:47:52,310 AUDIENCE: Hi! 1108 00:47:52,310 --> 00:47:53,370 DAVID J. MALAN: --a few minutes ago? 1109 00:47:53,370 --> 00:47:55,787 So it meant "Hi!" but here I am, claiming, no, no, no, no, 1110 00:47:55,787 --> 00:47:57,140 that means yellow. 1111 00:47:57,140 --> 00:47:58,890 How do you reconcile this? 1112 00:47:58,890 --> 00:48:01,550 Well, at the end of the day, this is all we have, 1113 00:48:01,550 --> 00:48:04,310 0's and 1's, whether you think of them as numbers, 1114 00:48:04,310 --> 00:48:06,620 or letters, or even colors now. 1115 00:48:06,620 --> 00:48:08,400 But it depends on the context. 1116 00:48:08,400 --> 00:48:11,390 So if you've received a text message or an email, 1117 00:48:11,390 --> 00:48:13,850 odds are the pattern of 0's and 1's that the computer 1118 00:48:13,850 --> 00:48:17,300 is showing you are going to be interpreted as text because that's 1119 00:48:17,300 --> 00:48:19,940 the whole point of a text message or an email. 1120 00:48:19,940 --> 00:48:23,930 If, though, you opened up MacOS's or iOS's or Windows's or Android's 1121 00:48:23,930 --> 00:48:27,230 calculator app, the same pattern of 0's and 1's might 1122 00:48:27,230 --> 00:48:30,650 be interpreted as numbers for some addition, or subtraction, or whatever. 1123 00:48:30,650 --> 00:48:33,780 If you open the same pattern of 0's and 1's in Photoshop, 1124 00:48:33,780 --> 00:48:37,110 like a graphics program, they're going to be interpreted, in that context, 1125 00:48:37,110 --> 00:48:37,950 as colors. 1126 00:48:37,950 --> 00:48:39,098 So context matters. 1127 00:48:39,098 --> 00:48:40,890 And, indeed, as soon as next week, when you 1128 00:48:40,890 --> 00:48:43,080 start writing code in that language called C, 1129 00:48:43,080 --> 00:48:47,550 the onus will be on you, the programmer, to tell the computer, interpret 1130 00:48:47,550 --> 00:48:52,593 the following sequence of bits as a number, or a letter, or something else. 1131 00:48:52,593 --> 00:48:55,260 And you won't have to even worry about what the 0's and 1's are, 1132 00:48:55,260 --> 00:48:58,380 but you need to give the computer a hint as to what type of file 1133 00:48:58,380 --> 00:49:00,730 or piece of data you're representing. 1134 00:49:00,730 --> 00:49:01,890 So that gives us bits. 1135 00:49:01,890 --> 00:49:05,640 And you can actually see these dots, these pixels on the screen. 1136 00:49:05,640 --> 00:49:07,380 Let me zoom in, zoom in. 1137 00:49:07,380 --> 00:49:10,470 And here we have it, just with this emoji, which, at the end of the day, 1138 00:49:10,470 --> 00:49:13,380 is a picture that someone at Apple, in this case, drew. 1139 00:49:13,380 --> 00:49:16,440 And you can see-- if you really zoom in, or take your phone or TV 1140 00:49:16,440 --> 00:49:19,470 and really put it close to your face, you'll see all of these dots, 1141 00:49:19,470 --> 00:49:20,700 depending on the hardware. 1142 00:49:20,700 --> 00:49:23,250 And each of these dots, these squares, is 1143 00:49:23,250 --> 00:49:28,350 storing 24 bits or three bytes, 24 bits, 24 bits, 24 bits. 1144 00:49:28,350 --> 00:49:31,200 And that's whey, dot, dot, dot, if you've 1145 00:49:31,200 --> 00:49:35,730 got a photograph, for instance, that's three megabytes, which 1146 00:49:35,730 --> 00:49:42,030 is 3 million bytes, well, odds are there's 1 million pixels therein 1147 00:49:42,030 --> 00:49:45,240 because you're using three bytes per pixel 1148 00:49:45,240 --> 00:49:46,708 to represent each of those colors. 1149 00:49:46,708 --> 00:49:48,750 That's a bit of an oversimplification, but that's 1150 00:49:48,750 --> 00:49:51,840 why images and photos are getting bigger and bigger nowadays. 1151 00:49:51,840 --> 00:49:56,110 Because we're throwing even more pixels into the file. 1152 00:49:56,110 --> 00:49:56,610 Music-- 1153 00:49:56,610 --> 00:49:57,330 [MUSIC PLAYING] 1154 00:49:57,330 --> 00:49:59,880 --how could you represent music, digitally, 1155 00:49:59,880 --> 00:50:03,920 using just 0's and 1's, or numbers, really? 1156 00:50:03,920 --> 00:50:07,710 Any instinct, whether a musician or not? 1157 00:50:07,710 --> 00:50:08,743 Yeah. 1158 00:50:08,743 --> 00:50:11,060 AUDIENCE: The notes could be represented by a number. 1159 00:50:11,060 --> 00:50:13,768 DAVID J. MALAN: Yeah, so we can just represent notes by a number. 1160 00:50:13,768 --> 00:50:17,660 So A is some number, and B. And maybe sharp or flat is some other number. 1161 00:50:17,660 --> 00:50:21,610 But note might not be quite enough for some-- 1162 00:50:21,610 --> 00:50:22,110 yeah? 1163 00:50:22,110 --> 00:50:22,876 AUDIENCE: [INAUDIBLE]. 1164 00:50:22,876 --> 00:50:23,834 DAVID J. MALAN: Ah, OK. 1165 00:50:23,834 --> 00:50:26,470 So one note-- one number to represent the note, itself, 1166 00:50:26,470 --> 00:50:30,820 the sound or the pitch; one other number to represent the duration. 1167 00:50:30,820 --> 00:50:35,000 In the context of piano, how long is the human holding the key down? 1168 00:50:35,000 --> 00:50:37,330 And maybe I can think of a third, the loudness. 1169 00:50:37,330 --> 00:50:39,457 How hard has the person played that note? 1170 00:50:39,457 --> 00:50:41,290 So, minimally, with three numbers, you could 1171 00:50:41,290 --> 00:50:43,492 imagine representing music, as well. 1172 00:50:43,492 --> 00:50:45,700 And, indeed, that's very well might be what computers 1173 00:50:45,700 --> 00:50:47,720 are doing when you listen to sound. 1174 00:50:47,720 --> 00:50:48,610 What about video? 1175 00:50:48,610 --> 00:50:51,760 How could you represent videos, as well? 1176 00:50:51,760 --> 00:50:52,270 Yeah? 1177 00:50:52,270 --> 00:50:53,460 AUDIENCE: Through many images. 1178 00:50:53,460 --> 00:50:54,790 DAVID J. MALAN: Yeah, many images. 1179 00:50:54,790 --> 00:50:57,750 So if you've ever produced a film or looked at some of the fine print, 1180 00:50:57,750 --> 00:51:02,070 30 frames per second, FPS, or 29 frames per second 1181 00:51:02,070 --> 00:51:04,560 is just how many pictures are flying across the screen. 1182 00:51:04,560 --> 00:51:06,810 But that's really all a video file is on a computer, 1183 00:51:06,810 --> 00:51:10,470 lots of pictures moving so quickly in front of us that you and I, our brains, 1184 00:51:10,470 --> 00:51:12,930 interpolate that as being actual motion. 1185 00:51:12,930 --> 00:51:15,720 And, in fact, from yesteryear, motion pictures, 1186 00:51:15,720 --> 00:51:18,570 it's like pictures that are giving the illusion of motion, 1187 00:51:18,570 --> 00:51:21,910 even though there's only 30 or so of them flying across the screen. 1188 00:51:21,910 --> 00:51:24,870 So we have a way, now, to represent information, both as 1189 00:51:24,870 --> 00:51:29,250 input and output, whether it's numbers, letters, images, anything else. 1190 00:51:29,250 --> 00:51:32,200 Let's now focus on what's inside of that black box, 1191 00:51:32,200 --> 00:51:36,360 so to speak, wherein we have algorithms, step-by-step instructions 1192 00:51:36,360 --> 00:51:38,430 for solving some problem. 1193 00:51:38,430 --> 00:51:41,760 Now, what do I mean by "algorithms" or "step-by-step instructions"? 1194 00:51:41,760 --> 00:51:44,815 Well, maybe, if we were to turn this into code-- 1195 00:51:44,815 --> 00:51:47,190 and that's how we'll connect the dots, ultimately, today. 1196 00:51:47,190 --> 00:51:51,480 Code is just the implementation, in computers, of algorithms. 1197 00:51:51,480 --> 00:51:53,920 An algorithm can be something we do in the physical world. 1198 00:51:53,920 --> 00:51:58,180 Code is how we implement that exact same idea, in the context of a computer, 1199 00:51:58,180 --> 00:51:58,810 instead. 1200 00:51:58,810 --> 00:52:02,152 And here, for instance, is a very common application inside of a computer, 1201 00:52:02,152 --> 00:52:02,860 for your context. 1202 00:52:02,860 --> 00:52:04,900 This is the iOS version of the icon. 1203 00:52:04,900 --> 00:52:06,963 And, typically, if you click on that icon, 1204 00:52:06,963 --> 00:52:09,130 you'll see something like all of your contacts here, 1205 00:52:09,130 --> 00:52:12,250 typically, alphabetical, by first name or last name. 1206 00:52:12,250 --> 00:52:17,103 And your phone or your computer lets you often search for someone's name 1207 00:52:17,103 --> 00:52:17,770 at the very top. 1208 00:52:17,770 --> 00:52:20,620 And it will autocomplete, and it'll be pretty darn fast. 1209 00:52:20,620 --> 00:52:23,470 But it'll be pretty darn fast because the programmers who 1210 00:52:23,470 --> 00:52:28,210 implemented that application are looking for someone quickly for you. 1211 00:52:28,210 --> 00:52:33,400 Now, I can do this old school style, whereby we have one of these things 1212 00:52:33,400 --> 00:52:35,840 from yesteryear, an actual phone book. 1213 00:52:35,840 --> 00:52:39,160 So, in a physical phone book like this, you might have 1,000 pages. 1214 00:52:39,160 --> 00:52:42,440 And on every page are a bunch of names and a bunch of numbers. 1215 00:52:42,440 --> 00:52:45,490 And as I flip through this, I could look for someone specific. 1216 00:52:45,490 --> 00:52:49,010 So suppose I want to call John Harvard, who's-- the first name, of course, 1217 00:52:49,010 --> 00:52:52,720 starts with a J. Well, I could just turn, page by page, 1218 00:52:52,720 --> 00:52:54,590 looking for John Harvard. 1219 00:52:54,590 --> 00:52:57,000 And if he's not there, I keep turning and turning. 1220 00:52:57,000 --> 00:52:58,000 So this is an algorithm. 1221 00:52:58,000 --> 00:53:00,790 I'm stepping through the phone book, one page at a time. 1222 00:53:00,790 --> 00:53:04,510 Is it correct, this algorithm, assuming I'm looking down? 1223 00:53:04,510 --> 00:53:05,470 So, yeah. 1224 00:53:05,470 --> 00:53:07,930 I mean, it's stupidly slow because why am 1225 00:53:07,930 --> 00:53:10,585 I wasting my time with the A's, and the B's, and the so forth? 1226 00:53:10,585 --> 00:53:12,460 I could probably take bigger bites out of it. 1227 00:53:12,460 --> 00:53:13,210 But it is correct. 1228 00:53:13,210 --> 00:53:16,293 And that's going to be one of the goals of writing code, is to, of course, 1229 00:53:16,293 --> 00:53:18,100 solve the problem you care about correctly. 1230 00:53:18,100 --> 00:53:20,470 So correctness goes without saying, or else what's 1231 00:53:20,470 --> 00:53:23,080 the point of writing the code or solving-- or implementing 1232 00:53:23,080 --> 00:53:23,800 the algorithm? 1233 00:53:23,800 --> 00:53:24,040 All right. 1234 00:53:24,040 --> 00:53:25,623 Well, let me at least speed things up. 1235 00:53:25,623 --> 00:53:29,380 So, instead of one page at a time, so, two, four, six, eight-- 1236 00:53:29,380 --> 00:53:33,420 no, ignore that-- 10, 12, 14, 16, and so forth. 1237 00:53:33,420 --> 00:53:35,920 It's a little hard to do, physically, but it sounded faster. 1238 00:53:35,920 --> 00:53:38,815 It was twice as fast, theoretically, but is it correct? 1239 00:53:38,815 --> 00:53:39,505 AUDIENCE: No. 1240 00:53:39,505 --> 00:53:40,480 DAVID J. MALAN: So, no. 1241 00:53:40,480 --> 00:53:41,210 Why? 1242 00:53:41,210 --> 00:53:41,710 Yeah? 1243 00:53:41,710 --> 00:53:43,180 AUDIENCE: Yeah, you might [INAUDIBLE]. 1244 00:53:43,180 --> 00:53:46,263 DAVID J. MALAN: Yeah, I might miss John Harvard because, just by accident, 1245 00:53:46,263 --> 00:53:48,490 he might get sandwiched between two pages. 1246 00:53:48,490 --> 00:53:52,210 But do I have to throw the algorithm out altogether? 1247 00:53:52,210 --> 00:53:53,260 Probably not. 1248 00:53:53,260 --> 00:53:56,073 Once I reach the K section, which is past the J section, 1249 00:53:56,073 --> 00:53:58,990 I could double back at least one page, at least, [PATS TELEPHONE BOOK] 1250 00:53:58,990 --> 00:54:01,540 and just make sure I didn't blow past him completely. 1251 00:54:01,540 --> 00:54:04,450 So that is twice as fast, because I'm going two pages 1252 00:54:04,450 --> 00:54:05,922 at a time, plus one extra step. 1253 00:54:05,922 --> 00:54:07,130 So it's still an improvement. 1254 00:54:07,130 --> 00:54:08,922 So the first algorithm, worst case, if it's 1255 00:54:08,922 --> 00:54:10,900 not John, but someone whose name starts with Z, 1256 00:54:10,900 --> 00:54:12,860 that might take me a full 1,000 steps. 1257 00:54:12,860 --> 00:54:16,210 The second algorithm is just 500 steps because I'm 1258 00:54:16,210 --> 00:54:19,660 going two pages at a time plus one, in case I have to double back, 1259 00:54:19,660 --> 00:54:20,990 but that's in the worst case. 1260 00:54:20,990 --> 00:54:26,080 But most of us in the-- in yesteryear, and what Apple, and Google, and others 1261 00:54:26,080 --> 00:54:29,440 are actually doing is, in software or here, physically, 1262 00:54:29,440 --> 00:54:31,540 we're typically going, roughly, to the middle. 1263 00:54:31,540 --> 00:54:34,360 Especially if there's no cheat sheet on the side, like A through Z, 1264 00:54:34,360 --> 00:54:36,235 I'm just going to go to, roughly, the middle. 1265 00:54:36,235 --> 00:54:38,920 And, oh, here I am, not surprisingly, in the M section. 1266 00:54:38,920 --> 00:54:40,360 But what do I now know. 1267 00:54:40,360 --> 00:54:43,660 If this is the M section, where is John Harvard? 1268 00:54:43,660 --> 00:54:46,130 So, clearly, to the left, alphabetically. 1269 00:54:46,130 --> 00:54:49,660 And so here is where we can take a much bigger bite out of the problem. 1270 00:54:49,660 --> 00:54:52,480 We can really divide and conquer this problem 1271 00:54:52,480 --> 00:54:56,080 by tearing [TEARS BOOK] the problem in half, throwing half of it 1272 00:54:56,080 --> 00:55:01,240 away, 500 pages away, leaving me with a smaller problem, 1273 00:55:01,240 --> 00:55:04,370 half as big, that I can really just now repeat. 1274 00:55:04,370 --> 00:55:07,150 So I go, roughly, here, and now I'm in the E section. 1275 00:55:07,150 --> 00:55:09,102 So I went a little too far back. 1276 00:55:09,102 --> 00:55:10,060 But what do I now know? 1277 00:55:10,060 --> 00:55:11,680 If this is the E pages, where's John? 1278 00:55:11,680 --> 00:55:12,460 AUDIENCE: To the right. 1279 00:55:12,460 --> 00:55:13,690 DAVID J. MALAN: So now he's to the right. 1280 00:55:13,690 --> 00:55:15,815 So I can-- again, hopefully, he's not on that page. 1281 00:55:15,815 --> 00:55:20,380 I can tear the problem in half again, throw that 250 pages away. 1282 00:55:20,380 --> 00:55:23,530 And now I've gone from 1,000 to 500 to 250 pages. 1283 00:55:23,530 --> 00:55:26,470 Now I'm moving because the first algorithm was one page at a time, 1284 00:55:26,470 --> 00:55:27,280 second was two. 1285 00:55:27,280 --> 00:55:29,373 This is hundreds of pages at a time. 1286 00:55:29,373 --> 00:55:31,540 And if I go, roughly, again, to the middle; roughly, 1287 00:55:31,540 --> 00:55:33,790 to the middle; roughly, to the middle, hopefully, I'll 1288 00:55:33,790 --> 00:55:36,350 find John Harvard on one final page. 1289 00:55:36,350 --> 00:55:39,140 Can only do this once, but one final page. 1290 00:55:39,140 --> 00:55:42,010 So that invites the question, I would think, 1291 00:55:42,010 --> 00:55:44,680 if the phone book does have 1,000 or so pages, 1292 00:55:44,680 --> 00:55:50,210 how many times can I divide the problem in half to get down to one last page? 1293 00:55:50,210 --> 00:55:51,580 So it's, roughly, 10. 1294 00:55:51,580 --> 00:55:56,203 And the quick math is 1,000 goes to 500 to 250 to 125 to 67 something. 1295 00:55:56,203 --> 00:55:58,370 So we have to deal with rounding issues, eventually. 1296 00:55:58,370 --> 00:56:01,640 But assuming we work out the math, it's, roughly, 10 page tears. 1297 00:56:01,640 --> 00:56:07,580 And that's crazy faster than 1,000 pages and still faster than 500 pages. 1298 00:56:07,580 --> 00:56:09,350 So it's fundamentally better. 1299 00:56:09,350 --> 00:56:13,792 And, indeed, if I finally get to that final page, in the software world, 1300 00:56:13,792 --> 00:56:16,250 you'd see something like this, John Harvard and his number, 1301 00:56:16,250 --> 00:56:17,810 which you're welcome to call or text. 1302 00:56:17,810 --> 00:56:22,850 But that's how we now have our answer, much like the single page there. 1303 00:56:22,850 --> 00:56:27,090 But let's consider just how efficient that actually is. 1304 00:56:27,090 --> 00:56:30,560 So here's a very rough, broad-- with broad strokes, a chart. 1305 00:56:30,560 --> 00:56:31,998 So here's an xy plot. 1306 00:56:31,998 --> 00:56:34,790 So here, on the horizontal, is going to be the size of the problem. 1307 00:56:34,790 --> 00:56:38,360 And, by that, I mean, how many pages are we trying to go through? 1308 00:56:38,360 --> 00:56:39,890 This would be zero pages. 1309 00:56:39,890 --> 00:56:41,480 This would be a lot of pages. 1310 00:56:41,480 --> 00:56:43,610 How much time does it take to solve the problem? 1311 00:56:43,610 --> 00:56:46,100 How long does it take to find John Harvard or anyone else? 1312 00:56:46,100 --> 00:56:47,540 This means no time. 1313 00:56:47,540 --> 00:56:48,960 This means a lot of time. 1314 00:56:48,960 --> 00:56:51,110 So what's the relationship among these algorithms? 1315 00:56:51,110 --> 00:56:53,490 Well, the first one is actually just a straight line. 1316 00:56:53,490 --> 00:56:57,330 If there's n pages in the phone book, well, I 1317 00:56:57,330 --> 00:57:00,060 claim that it's a one-to-one relationship. 1318 00:57:00,060 --> 00:57:04,290 Because if Verizon or the phone company adds another page next year, 1319 00:57:04,290 --> 00:57:06,900 that just means I might have one more step next year, 1320 00:57:06,900 --> 00:57:09,990 as well, to find John Harvard or anyone else. 1321 00:57:09,990 --> 00:57:12,930 But the second algorithm, it's also a straight line, 1322 00:57:12,930 --> 00:57:15,295 but it's lower, even though it might not look obvious. 1323 00:57:15,295 --> 00:57:16,420 And what do I mean by that? 1324 00:57:16,420 --> 00:57:18,253 Well, let me just draw some temporary lines. 1325 00:57:18,253 --> 00:57:20,610 If this is how many pages are in the phone book-- dot, 1326 00:57:20,610 --> 00:57:24,090 dot, dot-- notice that it takes this much time, on the red line, 1327 00:57:24,090 --> 00:57:25,360 to solve the problem. 1328 00:57:25,360 --> 00:57:28,530 But if I, instead, use the second algorithm, 1329 00:57:28,530 --> 00:57:30,507 it takes me half as much time. 1330 00:57:30,507 --> 00:57:32,340 So, even though they're both straight lines, 1331 00:57:32,340 --> 00:57:34,923 one is strictly lower than the other, which means it's faster. 1332 00:57:34,923 --> 00:57:35,640 It's better. 1333 00:57:35,640 --> 00:57:38,310 But the third algorithm is a fundamentally different shape, 1334 00:57:38,310 --> 00:57:40,090 and it looks a little something like this. 1335 00:57:40,090 --> 00:57:42,370 And it looks like it's going to flatten, flatten, flatten out, 1336 00:57:42,370 --> 00:57:43,260 but it never does. 1337 00:57:43,260 --> 00:57:46,170 It just rises ever so slowly. 1338 00:57:46,170 --> 00:57:49,290 And what this means is that if maybe Cambridge and Allston, here 1339 00:57:49,290 --> 00:57:53,030 in Massachusetts, merge next year, so we go from 1,000 page phone book 1340 00:57:53,030 --> 00:57:58,100 to a 2,000 page phone book, that means, if we're here this year, 1341 00:57:58,100 --> 00:57:59,660 we're over here next year. 1342 00:57:59,660 --> 00:58:01,190 It's not all that much higher. 1343 00:58:01,190 --> 00:58:04,320 But it would be much higher if we were using the first two algorithms. 1344 00:58:04,320 --> 00:58:04,820 Why? 1345 00:58:04,820 --> 00:58:07,880 It'd be an extra 1,000 steps to find someone in that combined phone 1346 00:58:07,880 --> 00:58:09,890 book or maybe another 500 steps. 1347 00:58:09,890 --> 00:58:13,520 But, to be clear, if we're using my third and final algorithm, 1348 00:58:13,520 --> 00:58:15,620 how many more steps will it take me next year, 1349 00:58:15,620 --> 00:58:20,930 when Cambridge and Allston merge into one 2,000-page phone book? 1350 00:58:20,930 --> 00:58:22,800 Just one more step, no big deal. 1351 00:58:22,800 --> 00:58:24,400 It's one more page tear. 1352 00:58:24,400 --> 00:58:26,900 And this is what we mean, ultimately, about not just writing 1353 00:58:26,900 --> 00:58:29,720 code or implementing algorithms that are correct, but, now, 1354 00:58:29,720 --> 00:58:33,070 that are well-designed or efficient, specifically. 1355 00:58:33,070 --> 00:58:35,570 And this is what makes someone a better programmer, perhaps, 1356 00:58:35,570 --> 00:58:38,237 than someone else, or a better problem-solver than someone else, 1357 00:58:38,237 --> 00:58:40,130 is acquiring, over time, these skills. 1358 00:58:40,130 --> 00:58:43,280 So that, sure, you could solve the problem quickly and dirtily, 1359 00:58:43,280 --> 00:58:45,560 so to speak, but if you're going to have a lot of data 1360 00:58:45,560 --> 00:58:49,492 eventually, be it in your phone book or maybe your Google website index, 1361 00:58:49,492 --> 00:58:51,200 if you're searching the web, you're going 1362 00:58:51,200 --> 00:58:54,540 to want to try to think about how to design algorithms that look like this. 1363 00:58:54,540 --> 00:58:56,370 Mathematically, this is called a logarithm. 1364 00:58:56,370 --> 00:58:59,495 And it's log base 2 because I'm halving, halving, halving, again and again. 1365 00:58:59,495 --> 00:59:03,120 But, for now, just know that it's a fundamentally faster and different 1366 00:59:03,120 --> 00:59:03,820 shape. 1367 00:59:03,820 --> 00:59:06,330 So, among our goals in CS50, ultimately, is not just 1368 00:59:06,330 --> 00:59:12,270 to write and solve problems correctly, but, ultimately, ever more efficiently, 1369 00:59:12,270 --> 00:59:13,600 as well. 1370 00:59:13,600 --> 00:59:20,110 Any questions, then, on these ideas of efficiency and design? 1371 00:59:20,110 --> 00:59:21,480 Any questions here? 1372 00:59:21,480 --> 00:59:22,080 Yeah, in back? 1373 00:59:22,080 --> 00:59:23,480 AUDIENCE: [INAUDIBLE]. 1374 00:59:23,480 --> 00:59:24,170 DAVID J. MALAN: A good question. 1375 00:59:24,170 --> 00:59:27,462 Just to repeat it, can a graph like this capture the accuracy of the algorithm? 1376 00:59:27,462 --> 00:59:28,640 Short answer, no. 1377 00:59:28,640 --> 00:59:31,460 For instance, if I drew a straight line that 1378 00:59:31,460 --> 00:59:35,570 is super low on this graph, which would imply that the algorithm takes 1379 00:59:35,570 --> 00:59:38,240 the same amount of time, no matter how many pages there are, 1380 00:59:38,240 --> 00:59:41,480 my algorithm might actually be to just pull a random page from the phone 1381 00:59:41,480 --> 00:59:43,230 book, one step, and say, here it is. 1382 00:59:43,230 --> 00:59:45,230 But that's not necessarily going to be accurate, 1383 00:59:45,230 --> 00:59:47,010 unless I get really, really lucky. 1384 00:59:47,010 --> 00:59:49,820 So the graph really only speaks to efficiency 1385 00:59:49,820 --> 00:59:52,880 and the design of the algorithm, not the correctness of it. 1386 00:59:52,880 --> 00:59:57,170 To analyze the correctness, you need to use another mechanism altogether, 1387 00:59:57,170 --> 00:59:58,280 namely, logic. 1388 00:59:58,280 --> 01:00:02,120 Other questions now, on efficiency, in this way? 1389 01:00:02,120 --> 01:00:02,940 No? 1390 01:00:02,940 --> 01:00:03,440 All right. 1391 01:00:03,440 --> 01:00:08,090 So, with that in mind, let's begin to translate this to some actual code. 1392 01:00:08,090 --> 01:00:11,630 And, in fact, before we look at, today, one actual programming language, 1393 01:00:11,630 --> 01:00:14,720 albeit a graphical one, let's consider something called pseudocode. 1394 01:00:14,720 --> 01:00:16,497 So pseudocode has no formal meaning. 1395 01:00:16,497 --> 01:00:19,580 Generally, you write it in English or whatever your own human language is. 1396 01:00:19,580 --> 01:00:25,600 But you write your thoughts down tersely, succinct, but precisely. 1397 01:00:25,600 --> 01:00:28,570 You try to really convey your thoughts, not with a wave of the hand, 1398 01:00:28,570 --> 01:00:31,510 metaphorically, but step by step, precisely. 1399 01:00:31,510 --> 01:00:32,650 So what do I mean by this? 1400 01:00:32,650 --> 01:00:35,380 Here might be some representative pseudocode 1401 01:00:35,380 --> 01:00:39,337 via which I describe that third and final algorithm in a way 1402 01:00:39,337 --> 01:00:41,920 that I could hand it to you and you could do the same at home. 1403 01:00:41,920 --> 01:00:45,425 Or I could hand it to someone at Google, and they could implement it in Android. 1404 01:00:45,425 --> 01:00:48,550 Or I could hand it to someone at Apple, and they could implement it in iOS. 1405 01:00:48,550 --> 01:00:51,280 So, step one, I claimed, was "Pick up phone book." 1406 01:00:51,280 --> 01:00:54,430 Step two was "Open to the middle of the phone book." 1407 01:00:54,430 --> 01:00:57,145 Step three, "Look at the page," as I did. 1408 01:00:57,145 --> 01:00:59,020 And now things get a little more interesting. 1409 01:00:59,020 --> 01:01:03,760 Step four, "If person is on page," I have to make a decision. 1410 01:01:03,760 --> 01:01:07,810 Presumably, what should I do if John Harvard is on the page I'm looking at? 1411 01:01:07,810 --> 01:01:12,050 So stop and probably make the call, or email, or whatever the goal might be. 1412 01:01:12,050 --> 01:01:15,430 And so I'm going to actually indent this, visually, by a few spaces, 1413 01:01:15,430 --> 01:01:19,900 just to make clear that you should only do line five if the answer to line four 1414 01:01:19,900 --> 01:01:21,130 is yes. 1415 01:01:21,130 --> 01:01:22,360 Otherwise, you don't bother. 1416 01:01:22,360 --> 01:01:26,640 The next thing I'm going to do, line six, is consider another possibility. 1417 01:01:26,640 --> 01:01:28,980 "If the person I'm looking for is earlier 1418 01:01:28,980 --> 01:01:30,805 in the book," what do I want to do? 1419 01:01:30,805 --> 01:01:31,680 Well, I could write-- 1420 01:01:31,680 --> 01:01:33,388 I could describe this in a bunch of ways. 1421 01:01:33,388 --> 01:01:35,190 I'm going to do this tersely, as follows. 1422 01:01:35,190 --> 01:01:38,910 "Open to the middle of the left half of the book, 1423 01:01:38,910 --> 01:01:41,610 so it's open to the middle of the left half of the book. 1424 01:01:41,610 --> 01:01:43,320 And then, what am I going to do? 1425 01:01:43,320 --> 01:01:46,630 Well, I've just divided the problem into something smaller. 1426 01:01:46,630 --> 01:01:48,580 But it's fundamentally the same problem. 1427 01:01:48,580 --> 01:01:51,100 It's just a fewer number of pages. 1428 01:01:51,100 --> 01:01:54,017 So I'm just going to go back to line three and do it again 1429 01:01:54,017 --> 01:01:56,850 because the problem is just getting smaller and smaller, presumably. 1430 01:01:56,850 --> 01:01:59,520 Else, if the person I'm looking for is later in the book, 1431 01:01:59,520 --> 01:02:02,760 open to the middle of the right half of the book, 1432 01:02:02,760 --> 01:02:04,950 and, also, "Go back to line 3." 1433 01:02:04,950 --> 01:02:08,160 But there's a fourth possibility and its failure 1434 01:02:08,160 --> 01:02:11,580 to realize, sometimes, that there's other possible outcomes that 1435 01:02:11,580 --> 01:02:14,400 make computers crash, or spinning beach balls, or the like, 1436 01:02:14,400 --> 01:02:17,130 if a programmer doesn't anticipate some situation. 1437 01:02:17,130 --> 01:02:20,538 What's the fourth possible situation, when looking for John Harvard? 1438 01:02:20,538 --> 01:02:22,080 AUDIENCE: If they're not in the book. 1439 01:02:22,080 --> 01:02:24,205 DAVID J. MALAN: If they're not in the book, at all. 1440 01:02:24,205 --> 01:02:27,450 And, indeed, I might get to the very last page and John Harvard's not even 1441 01:02:27,450 --> 01:02:28,200 on that one. 1442 01:02:28,200 --> 01:02:33,450 I'd better handle that and say, else, as a catchall, just quit altogether. 1443 01:02:33,450 --> 01:02:35,610 And, truly, often, in your Macs, PCs, phones, 1444 01:02:35,610 --> 01:02:38,310 when they freeze, or, again, spinning beach ball, or the like, 1445 01:02:38,310 --> 01:02:39,660 and just weird things happen, that's just 1446 01:02:39,660 --> 01:02:41,220 because some human made a dumb mistake. 1447 01:02:41,220 --> 01:02:44,430 And they didn't realize that you could somehow get your phone or your laptop 1448 01:02:44,430 --> 01:02:47,070 into a configuration that they didn't anticipate. 1449 01:02:47,070 --> 01:02:48,870 So we're going to try to handle that here. 1450 01:02:48,870 --> 01:02:50,880 Now this is just one way of writing pseudocode. 1451 01:02:50,880 --> 01:02:52,230 There's no one way to do this. 1452 01:02:52,230 --> 01:02:55,500 All of us in this room could come up with slightly different pseudocode. 1453 01:02:55,500 --> 01:02:59,190 But I think you'll find characteristic are certain building 1454 01:02:59,190 --> 01:03:02,130 blocks in all of our answers. 1455 01:03:02,130 --> 01:03:04,590 Here, in yellow, are what, as of today, we're 1456 01:03:04,590 --> 01:03:07,540 going to start calling "functions," technically speaking. 1457 01:03:07,540 --> 01:03:10,800 These are like actions or verbs that literally, in this case, tell me 1458 01:03:10,800 --> 01:03:11,700 what to do. 1459 01:03:11,700 --> 01:03:15,150 Next, we're going to have these things, conditionals, 1460 01:03:15,150 --> 01:03:20,525 forks in the road, so to speak, that take me down this path or another, 1461 01:03:20,525 --> 01:03:21,150 metaphorically. 1462 01:03:21,150 --> 01:03:22,933 So I do this thing or something else. 1463 01:03:22,933 --> 01:03:25,350 But how do I decide if I want to go this way, or this way, 1464 01:03:25,350 --> 01:03:26,620 or this way, or this way? 1465 01:03:26,620 --> 01:03:27,780 I need to ask a question. 1466 01:03:27,780 --> 01:03:30,000 And in programming, we'll typically use what 1467 01:03:30,000 --> 01:03:33,240 are called Boolean expressions, named after a mathematician, Boole. 1468 01:03:33,240 --> 01:03:36,090 And a Boolean expression is essentially just a question 1469 01:03:36,090 --> 01:03:42,300 with a yes/no answer, a true or false answer, a 1 or 0 answer. 1470 01:03:42,300 --> 01:03:45,520 It doesn't matter how you think about it, but it's got two possible answers. 1471 01:03:45,520 --> 01:03:49,228 And so you can think of these as being expressions with question marks, 1472 01:03:49,228 --> 01:03:50,520 even though I didn't draw such. 1473 01:03:50,520 --> 01:03:54,270 Person on page, person earlier in book, person later in book, 1474 01:03:54,270 --> 01:03:55,590 those are Boolean expressions. 1475 01:03:55,590 --> 01:04:00,400 And they tell me whether I should go down one fork in the road or another. 1476 01:04:00,400 --> 01:04:03,600 And, lastly, there's this, "Go back to line 3," in two different places. 1477 01:04:03,600 --> 01:04:06,630 That represents what we call a "loop," some kind of cycle that's 1478 01:04:06,630 --> 01:04:08,370 doing something again and again. 1479 01:04:08,370 --> 01:04:10,733 Now these are just a few building blocks here-- 1480 01:04:10,733 --> 01:04:12,900 functions, conditionals, Boolean expressions, loops. 1481 01:04:12,900 --> 01:04:15,210 But you'll find that they're characteristic of so 1482 01:04:15,210 --> 01:04:18,380 many different languages, one of which we'll look at today, another of which 1483 01:04:18,380 --> 01:04:19,380 we'll look at next week. 1484 01:04:19,380 --> 01:04:23,130 And those include, indeed, C, and Python, and other languages still. 1485 01:04:23,130 --> 01:04:25,350 And so this is why we focus on these basics 1486 01:04:25,350 --> 01:04:27,480 and fundamentals in these early days because we're 1487 01:04:27,480 --> 01:04:29,080 going to see them again and again. 1488 01:04:29,080 --> 01:04:31,800 So even if you feel like that fire hose is hitting you sometime, 1489 01:04:31,800 --> 01:04:34,320 we'll give you, today, ultimately, more visuals 1490 01:04:34,320 --> 01:04:38,730 by which you can hang onto, so as to actually write code, ultimately, 1491 01:04:38,730 --> 01:04:41,490 in different languages and solve all sorts of problems. 1492 01:04:41,490 --> 01:04:46,050 Now, we'd be remiss in not bringing up what's behind characters like Spot, 1493 01:04:46,050 --> 01:04:48,570 and ChatGPT, and other software, artificial intelligence. 1494 01:04:48,570 --> 01:04:51,430 And it turns out, to get to the point of AI, 1495 01:04:51,430 --> 01:04:54,150 we're actually going to need more building blocks than just 1496 01:04:54,150 --> 01:04:56,125 functions, and loops, and conditionals. 1497 01:04:56,125 --> 01:04:57,750 It's not going to be quite that simple. 1498 01:04:57,750 --> 01:04:59,200 But this has been a lot, so far. 1499 01:04:59,200 --> 01:05:01,530 Let's go ahead, here, and take a five-minute break. 1500 01:05:01,530 --> 01:05:03,990 And when we resume, we'll take a look not only at AI, 1501 01:05:03,990 --> 01:05:06,630 but also a specific language called Scratch. 1502 01:05:06,630 --> 01:05:09,870 So no cake, just yet, but we'll come back in five. 1503 01:05:09,870 --> 01:05:14,820 Before we dive back in, I just wanted to call out a special guest 1504 01:05:14,820 --> 01:05:16,980 that we have here today, beyond Spot, someone 1505 01:05:16,980 --> 01:05:19,050 who's come from even farther away. 1506 01:05:19,050 --> 01:05:22,560 And, in fact, if any of you have taken CS50x, the OpenCourseWare version 1507 01:05:22,560 --> 01:05:25,270 of the class, or dabbled in it over the past few years 1508 01:05:25,270 --> 01:05:27,490 in some of CS50's online social communities, 1509 01:05:27,490 --> 01:05:29,710 you might have had your questions answered 1510 01:05:29,710 --> 01:05:31,810 by a certain human from New Zealand. 1511 01:05:31,810 --> 01:05:35,890 And she's come all this way, today, to spend this lecture with us. 1512 01:05:35,890 --> 01:05:38,350 This is CS50's own Brenda Anderson. 1513 01:05:38,350 --> 01:05:41,920 If you might come up for acknowledgment from all of us here. 1514 01:05:41,920 --> 01:05:45,052 [APPLAUSE] 1515 01:05:45,052 --> 01:05:47,440 1516 01:05:47,440 --> 01:05:50,170 It's not much, but just a little token of our thanks. 1517 01:05:50,170 --> 01:05:53,830 Brenda has helped, truly, thousands of students online 1518 01:05:53,830 --> 01:05:55,370 for the past many years. 1519 01:05:55,370 --> 01:05:58,780 And, in fact, her own daughter has been the artist 1520 01:05:58,780 --> 01:06:03,615 behind the duck that's about to loom large in CS50 this year and beyond. 1521 01:06:03,615 --> 01:06:04,615 So, thank you to Brenda. 1522 01:06:04,615 --> 01:06:07,936 [APPLAUSE] 1523 01:06:07,936 --> 01:06:11,410 1524 01:06:11,410 --> 01:06:12,400 All right. 1525 01:06:12,400 --> 01:06:16,690 So it's hard to escape a discussion of artificial intelligence, nowadays, 1526 01:06:16,690 --> 01:06:18,790 but we thought we'd use this as an opportunity 1527 01:06:18,790 --> 01:06:20,260 to connect some of these dots. 1528 01:06:20,260 --> 01:06:22,460 Because, indeed, over the course of the semester, 1529 01:06:22,460 --> 01:06:25,990 we'll be-- not only be talking about artificial intelligence or AI, 1530 01:06:25,990 --> 01:06:28,900 but really using it all the more constructively 1531 01:06:28,900 --> 01:06:31,570 to help you solve problems, help you get unblocked 1532 01:06:31,570 --> 01:06:35,680 when you hit a wall, cognitively or syntactically, when writing code. 1533 01:06:35,680 --> 01:06:39,430 And, indeed, it's no accident that we have this duck here, 1534 01:06:39,430 --> 01:06:42,370 looming large, which is really the embodiment of the sort of AI 1535 01:06:42,370 --> 01:06:45,200 that you'll experience within CS50, itself, this year. 1536 01:06:45,200 --> 01:06:48,220 So let's talk about the so-called chatbots that 1537 01:06:48,220 --> 01:06:50,500 inspired some of those headlines with which we began 1538 01:06:50,500 --> 01:06:52,780 class, that weren't quite on the nose. 1539 01:06:52,780 --> 01:06:54,880 So the class will still be taught by us humans, 1540 01:06:54,880 --> 01:06:59,170 but helped by this CS50 duck, a chatbot of sorts. 1541 01:06:59,170 --> 01:07:00,590 Now what do I mean by this? 1542 01:07:00,590 --> 01:07:04,090 Well, it turns out that, when it comes to implementing something 1543 01:07:04,090 --> 01:07:06,730 like an artificial intelligence, we don't quite 1544 01:07:06,730 --> 01:07:10,550 have all of the building blocks yet, certainly after just today's week zero, 1545 01:07:10,550 --> 01:07:12,000 to implement something like that. 1546 01:07:12,000 --> 01:07:14,960 But I think we can skate in that direction, intellectually. 1547 01:07:14,960 --> 01:07:19,670 So, for instance, if we were to take a stab at implementing our own chatbot-- 1548 01:07:19,670 --> 01:07:22,883 some interactive text-based program that talks to us, 1549 01:07:22,883 --> 01:07:24,800 and answers questions, and the like-- we could 1550 01:07:24,800 --> 01:07:28,850 try borrowing some of today's ideas already, those functions, conditionals, 1551 01:07:28,850 --> 01:07:30,007 loops, and more. 1552 01:07:30,007 --> 01:07:31,590 And I could write something like this. 1553 01:07:31,590 --> 01:07:34,370 If I am writing code or pseudocode for a chatbot, 1554 01:07:34,370 --> 01:07:37,170 I could program the chatbot to do something like this. 1555 01:07:37,170 --> 01:07:39,230 If the student says, hello, to the chatbot, 1556 01:07:39,230 --> 01:07:41,840 then the chatbot should say, hello, back. 1557 01:07:41,840 --> 01:07:44,900 Else, if the student says, goodbye, well, the chatbot 1558 01:07:44,900 --> 01:07:46,580 should say, goodbye, back. 1559 01:07:46,580 --> 01:07:51,800 Else, if the student asks how you are, the chat bot should say that it's well. 1560 01:07:51,800 --> 01:07:54,020 But things get a little harder when you start 1561 01:07:54,020 --> 01:07:57,470 asking more interesting questions, like, else, 1562 01:07:57,470 --> 01:08:00,990 if the student asks why 111 in binary is 7 in decimal. 1563 01:08:00,990 --> 01:08:03,980 Now, you could imagine that we just have a conditional, 1564 01:08:03,980 --> 01:08:08,570 with this Boolean expression, that programs the chatbot to just give you 1565 01:08:08,570 --> 01:08:12,230 the answer and explain, in an English sentence, why that, in fact, is. 1566 01:08:12,230 --> 01:08:20,750 But what if you, the student, asks why 110 is 6 in decimal or why 010 is 2? 1567 01:08:20,750 --> 01:08:24,229 I mean, you can just imagine the explosion in the amount of code 1568 01:08:24,229 --> 01:08:28,370 that we would have to write to just anticipate every darn question that you 1569 01:08:28,370 --> 01:08:31,375 might ask about today and every other class, not to mention all 1570 01:08:31,375 --> 01:08:32,750 of the knowledge in the universe. 1571 01:08:32,750 --> 01:08:36,649 So, surely, there are other ways to implement algorithms 1572 01:08:36,649 --> 01:08:39,319 that allow something like a chatbot or AI, 1573 01:08:39,319 --> 01:08:43,700 more generally, to be fed input, still, like all of the internet, all 1574 01:08:43,700 --> 01:08:46,760 of the worldwide web, all of the pages and textual content therein, 1575 01:08:46,760 --> 01:08:51,050 but to let it just figure out how to answer our questions based 1576 01:08:51,050 --> 01:08:54,330 on those kinds of inputs, assuming the inputs, themselves, are accurate. 1577 01:08:54,330 --> 01:08:56,510 So "large language models" is a term you might 1578 01:08:56,510 --> 01:08:59,720 have heard bandied about over the past several months, or LLMs. 1579 01:08:59,720 --> 01:09:04,729 And a large language model really is an implementation, in software, 1580 01:09:04,729 --> 01:09:09,630 of code that actually takes, as input, lots and lots of language-- 1581 01:09:09,630 --> 01:09:13,310 like the text of lots and lots of web pages, dictionaries, encyclopedias, 1582 01:09:13,310 --> 01:09:14,779 Wikipedias, and the like-- 1583 01:09:14,779 --> 01:09:19,729 and infers, from the patterns of English words or any human language, 1584 01:09:19,729 --> 01:09:22,907 what a typical human might actually say when asked a question. 1585 01:09:22,907 --> 01:09:24,740 And some of these questions are easy, right? 1586 01:09:24,740 --> 01:09:28,165 Probably, on the internet, alone, not to mention everyday life, if someone 1587 01:09:28,165 --> 01:09:29,540 extends their hand and says, "Hi. 1588 01:09:29,540 --> 01:09:33,000 How are you," odds are, with 90% probability, you're going to say, 1589 01:09:33,000 --> 01:09:33,500 "Good. 1590 01:09:33,500 --> 01:09:34,000 Thanks. 1591 01:09:34,000 --> 01:09:34,700 How are you?" 1592 01:09:34,700 --> 01:09:37,250 So I bet we could write software that just 1593 01:09:37,250 --> 01:09:41,569 infers what it should say, probabilistically, statistically, based 1594 01:09:41,569 --> 01:09:43,069 on those kinds of patterns online. 1595 01:09:43,069 --> 01:09:45,442 And that's, indeed, where the world is starting 1596 01:09:45,442 --> 01:09:47,359 to go, when it comes to the most sophisticated 1597 01:09:47,359 --> 01:09:49,151 of algorithms, where you and I, the humans, 1598 01:09:49,151 --> 01:09:51,979 we don't try to anticipate every possible input. 1599 01:09:51,979 --> 01:09:54,620 Rather, we give it a more general purpose 1600 01:09:54,620 --> 01:09:58,277 input, like all human knowledge, and ideally just let it figure things out. 1601 01:09:58,277 --> 01:09:59,610 Now, we're not quite there, yet. 1602 01:09:59,610 --> 01:10:02,000 And odds are you've heard of hallucinations or just mistakes 1603 01:10:02,000 --> 01:10:03,680 that these large language models make. 1604 01:10:03,680 --> 01:10:05,005 But their inputs are imperfect. 1605 01:10:05,005 --> 01:10:07,130 And sometimes there's a bit of randomness sprinkled 1606 01:10:07,130 --> 01:10:10,088 in because you don't want the thing to always say the exact same thing. 1607 01:10:10,088 --> 01:10:14,250 Even you and I might say, "Eh, I'm not that great today" 10% of the time. 1608 01:10:14,250 --> 01:10:16,730 So you need to perturb the output in some way. 1609 01:10:16,730 --> 01:10:20,630 But within CS50 and within this world of large language models, 1610 01:10:20,630 --> 01:10:24,630 we do have these tools like ChatGPT, and Bing, chat, and others. 1611 01:10:24,630 --> 01:10:26,810 And we'll stipulate that, for CS50's purposes, 1612 01:10:26,810 --> 01:10:28,910 the direction we're going this year is that this 1613 01:10:28,910 --> 01:10:30,710 is what's in the syllabus, dot, dot, dot; 1614 01:10:30,710 --> 01:10:32,840 that it will not be allowed, it will be considered 1615 01:10:32,840 --> 01:10:37,348 not reasonable to use AI-based software, other than CS50's own. 1616 01:10:37,348 --> 01:10:39,140 So the goal here is not to simply take away 1617 01:10:39,140 --> 01:10:43,250 tools that are clearly inevitable, in my view, and clearly helpful 1618 01:10:43,250 --> 01:10:44,720 and productivity savers. 1619 01:10:44,720 --> 01:10:48,440 But we'd like there to be some guardrails, intellectually, on just how 1620 01:10:48,440 --> 01:10:49,653 helpful these chatbots are. 1621 01:10:49,653 --> 01:10:52,070 Because as you've probably seen, if you ask it a question, 1622 01:10:52,070 --> 01:10:54,560 these chatbots are already pretty good at not just helping 1623 01:10:54,560 --> 01:10:56,310 you finish your current thought, but it'll 1624 01:10:56,310 --> 01:10:59,900 hand you your second and your third thought and do the assignment for you. 1625 01:10:59,900 --> 01:11:02,660 But I think, through prompting, so to speak, 1626 01:11:02,660 --> 01:11:04,850 we'll be able to coax some of our own tools, 1627 01:11:04,850 --> 01:11:07,100 being computer scientists, ourself, in a direction 1628 01:11:07,100 --> 01:11:10,200 that you actually find to be the right balance, akin to having 1629 01:11:10,200 --> 01:11:14,310 a good tutor by your side 24/7, who doesn't just hand you answers, 1630 01:11:14,310 --> 01:11:16,223 but, indeed, tries to lead you to the same. 1631 01:11:16,223 --> 01:11:18,390 So you actually get something out of the experience, 1632 01:11:18,390 --> 01:11:20,520 and, ideally, three-plus months from now, 1633 01:11:20,520 --> 01:11:22,380 those training wheels can come off, too. 1634 01:11:22,380 --> 01:11:24,880 And you're able to still stand on your own. 1635 01:11:24,880 --> 01:11:28,770 So it will be reasonable to use CS50's own AI-based software which 1636 01:11:28,770 --> 01:11:33,210 will actually take the form of a CS50 duck, which is actually available now-- 1637 01:11:33,210 --> 01:11:37,170 and we'll use it throughout the term-- at CS50.ai, a web-based application 1638 01:11:37,170 --> 01:11:39,450 that's quite similar to ChatGPT, but that 1639 01:11:39,450 --> 01:11:44,010 has the personality of a CS50 teaching fellow or TF, or teaching assistant, 1640 01:11:44,010 --> 01:11:47,220 TA, that also happens to think of itself as a duck. 1641 01:11:47,220 --> 01:11:49,860 And for reasons we'll get to in a couple of weeks time, 1642 01:11:49,860 --> 01:11:54,105 but rubber ducks, in particular, are a thing in programming. 1643 01:11:54,105 --> 01:11:56,730 But more on that, before long, as you can even see from the one 1644 01:11:56,730 --> 01:11:58,350 there on my desk. 1645 01:11:58,350 --> 01:12:01,110 With that said, too, well, I'm going to call out CS50's own Brenda 1646 01:12:01,110 --> 01:12:05,485 Anderson, whose daughter, Sophie, kindly not only created 1647 01:12:05,485 --> 01:12:07,860 the first incarnation, digitally, of this duck, but also, 1648 01:12:07,860 --> 01:12:11,560 most recently, once it actually did more than quack a random number 1649 01:12:11,560 --> 01:12:13,540 of times in response to questions, has now 1650 01:12:13,540 --> 01:12:15,320 been virtually brought to life, too. 1651 01:12:15,320 --> 01:12:18,760 So, all that and more, over the coming weeks, but you'll find, ultimately, 1652 01:12:18,760 --> 01:12:23,590 that the goal is to really bring to life the availability of an AI-based tutor 1653 01:12:23,590 --> 01:12:26,650 that you have access to, a friend in your-- 1654 01:12:26,650 --> 01:12:30,340 next to you, that will help guide you through a lot of the course's 1655 01:12:30,340 --> 01:12:31,660 challenges along the way. 1656 01:12:31,660 --> 01:12:33,310 And we actually rolled it out this past summer, 1657 01:12:33,310 --> 01:12:35,950 already, with some of your predecessors, through the Harvard Summer School. 1658 01:12:35,950 --> 01:12:38,200 One student wrote, at summer's end, that this duck 1659 01:12:38,200 --> 01:12:40,180 "felt like having a personal tutor-- 1660 01:12:40,180 --> 01:12:44,110 I love how AI bots will answer questions without ego and without judgment 1661 01:12:44,110 --> 01:12:47,110 generally entertaining even the stupidest of questions 1662 01:12:47,110 --> 01:12:49,360 without treating them like they're stupid. 1663 01:12:49,360 --> 01:12:53,140 It has, as one could expect, an inhuman level of patience." 1664 01:12:53,140 --> 01:12:56,410 So there's actually something really there because as many teachers 1665 01:12:56,410 --> 01:12:57,520 as there are in CS50-- 1666 01:12:57,520 --> 01:13:00,730 myself, the course's preceptors, teaching fellows, teaching assistants, 1667 01:13:00,730 --> 01:13:03,490 and course assistants-- there's only so many of us. 1668 01:13:03,490 --> 01:13:05,650 And we're only awake so many hours of the day. 1669 01:13:05,650 --> 01:13:08,620 And I think you'll find, too, that we're on the cusp of something 1670 01:13:08,620 --> 01:13:11,080 pretty remarkable, in the coming years, where 1671 01:13:11,080 --> 01:13:14,380 it's going to get a lot more enabling, now, to learn material 1672 01:13:14,380 --> 01:13:18,110 not only within the confines of a class, but on your own, ultimately, as well. 1673 01:13:18,110 --> 01:13:22,270 And as one other student put it, at summer's end, with respect to the duck, 1674 01:13:22,270 --> 01:13:23,680 "Love love loved the duck. 1675 01:13:23,680 --> 01:13:24,490 We're friends now." 1676 01:13:24,490 --> 01:13:25,720 So that, too, awaits. 1677 01:13:25,720 --> 01:13:28,840 But, first, we're going to need to start with the basics. 1678 01:13:28,840 --> 01:13:30,820 And we started today by talking about binary. 1679 01:13:30,820 --> 01:13:32,710 And darn it, here it is again. 1680 01:13:32,710 --> 01:13:37,060 So we can't actually get to the point of using, or solving, or implementing AI 1681 01:13:37,060 --> 01:13:38,590 until we understand this. 1682 01:13:38,590 --> 01:13:42,590 And odds are most of you won't know, at a glance, what this piece of software 1683 01:13:42,590 --> 01:13:43,090 does. 1684 01:13:43,090 --> 01:13:46,600 But these are the 0's and 1's that represent, perhaps, 1685 01:13:46,600 --> 01:13:50,650 the first program that any programmer writes, which is now a clue to some 1686 01:13:50,650 --> 01:13:52,700 of you who have dabbled in code before. 1687 01:13:52,700 --> 01:13:56,470 What does this pattern of 0's and 1's tell a typical computer to do? 1688 01:13:56,470 --> 01:13:57,348 Might someone guess? 1689 01:13:57,348 --> 01:13:58,390 AUDIENCE: "Hello, world." 1690 01:13:58,390 --> 01:14:00,760 DAVID J. MALAN: It's going to have it say, "hello, world," 1691 01:14:00,760 --> 01:14:02,927 which is one of the very first programmer-- programs 1692 01:14:02,927 --> 01:14:04,420 that most any programmer writes. 1693 01:14:04,420 --> 01:14:06,790 Should you be able to recognize these 0's and 1's? 1694 01:14:06,790 --> 01:14:08,260 Do I recognize these 0's and 1's? 1695 01:14:08,260 --> 01:14:09,040 No, not at all. 1696 01:14:09,040 --> 01:14:11,120 I just happen to know that they are the same. 1697 01:14:11,120 --> 01:14:12,700 And that was a leading question. 1698 01:14:12,700 --> 01:14:17,050 But they are representing data and instructions, ultimately, 1699 01:14:17,050 --> 01:14:22,360 data like H-E-L-L-O, comma, W-O-R-L-D and an instruction like, 1700 01:14:22,360 --> 01:14:24,910 "Print that data to the screen." 1701 01:14:24,910 --> 01:14:26,920 As for what these patterns of 0's and 1's are, 1702 01:14:26,920 --> 01:14:30,250 this is not something that a computer scientist or programmer worries about. 1703 01:14:30,250 --> 01:14:34,240 We just stipulate that, OK, someone, somewhere knows how to do this. 1704 01:14:34,240 --> 01:14:36,400 And it's probably someone like Intel, who makes 1705 01:14:36,400 --> 01:14:37,960 the hardware inside of the computers. 1706 01:14:37,960 --> 01:14:41,470 But you and I, starting now, already, in week zero, 1707 01:14:41,470 --> 01:14:44,950 can start to view binary more abstractly. 1708 01:14:44,950 --> 01:14:46,660 We don't care about the 0's and 1's. 1709 01:14:46,660 --> 01:14:49,090 We only care that you can use 0's and 1's 1710 01:14:49,090 --> 01:14:52,420 to represent more useful quantities, like numbers, 1711 01:14:52,420 --> 01:14:54,260 and letters, colors, and more. 1712 01:14:54,260 --> 01:14:57,040 So this, next week, is going to be the code we actually 1713 01:14:57,040 --> 01:14:58,330 start writing at a keyboard. 1714 01:14:58,330 --> 01:15:01,538 And this is that language called C. It's the same language I, myself, learned 1715 01:15:01,538 --> 01:15:05,140 years ago, when taking CS50, when all we learned at the time was C. 1716 01:15:05,140 --> 01:15:07,770 But this, too, has some crypticness to it. 1717 01:15:07,770 --> 01:15:11,020 And if you've never programmed before, you can probably wrap your mind around, 1718 01:15:11,020 --> 01:15:14,190 OK, I'm guessing the "printf" prints out the "hello, world." 1719 01:15:14,190 --> 01:15:16,920 But what's with the semicolon, the quotes, the backslash, 1720 01:15:16,920 --> 01:15:21,030 and the curly braces, the #include, and all of this stupid syntax? 1721 01:15:21,030 --> 01:15:23,970 A lot of this, in the beginning of any class, is really a distraction. 1722 01:15:23,970 --> 01:15:25,890 It is not intellectually interesting. 1723 01:15:25,890 --> 01:15:29,230 But it's the stupid kind of stuff that's going to trip you up quite often. 1724 01:15:29,230 --> 01:15:31,500 And so, today, what we'll do is focus not 1725 01:15:31,500 --> 01:15:35,100 on syntax, characters on the keyboard, but ideas 1726 01:15:35,100 --> 01:15:37,170 because what really matters in this program 1727 01:15:37,170 --> 01:15:40,900 is that "printf" is a function here for our purposes. 1728 01:15:40,900 --> 01:15:43,980 And that function is to display information on the screen. 1729 01:15:43,980 --> 01:15:46,860 Everything else, as we'll soon see, has value 1730 01:15:46,860 --> 01:15:50,435 and will be understood by you, before long, but for now, it's a distraction. 1731 01:15:50,435 --> 01:15:52,200 Let's focus on those building blocks. 1732 01:15:52,200 --> 01:15:54,940 When it comes time to write code, though, for the curious, 1733 01:15:54,940 --> 01:15:56,815 especially if you've programmed before, we'll 1734 01:15:56,815 --> 01:15:58,890 use a very popular free and open-source tool 1735 01:15:58,890 --> 01:16:01,260 called Visual Studio Code, or VS Code. 1736 01:16:01,260 --> 01:16:06,000 We'll use a cloud-based version of it that we pre-install everything 1737 01:16:06,000 --> 01:16:08,070 you need in the cloud for you so you don't 1738 01:16:08,070 --> 01:16:10,980 have to deal with headaches like getting your Mac or PC to work. 1739 01:16:10,980 --> 01:16:13,920 You'll use instead this URL, cs50.dev, but more 1740 01:16:13,920 --> 01:16:15,870 on that in next week, week one. 1741 01:16:15,870 --> 01:16:19,650 For now, we'll use another cloud-based editor called Scratch. 1742 01:16:19,650 --> 01:16:21,960 And odds are some number of you use this probably 1743 01:16:21,960 --> 01:16:23,970 as early as like middle school or the like. 1744 01:16:23,970 --> 01:16:27,300 And that was fine to create your own animations, games, 1745 01:16:27,300 --> 01:16:28,650 interactive art, or the like. 1746 01:16:28,650 --> 01:16:30,600 But we'll use it today for just a bit. 1747 01:16:30,600 --> 01:16:32,670 And we'll use it in the course's first homework, 1748 01:16:32,670 --> 01:16:36,870 AKA problem set 0, to explore now some of these same ideas. 1749 01:16:36,870 --> 01:16:39,720 And among the goals today for the remainder of today 1750 01:16:39,720 --> 01:16:42,920 is not to focus so much on Scratch and the particulars 1751 01:16:42,920 --> 01:16:44,670 because this is not a language that you're 1752 01:16:44,670 --> 01:16:50,280 going to use often but to give you very visual representations of ideas 1753 01:16:50,280 --> 01:16:53,790 so that when things do escalate next week to C, to the more cryptic, 1754 01:16:53,790 --> 01:16:57,840 it's the same ideas just typed out instead of dragged and dropped. 1755 01:16:57,840 --> 01:16:59,460 So by that, I mean this. 1756 01:16:59,460 --> 01:17:03,270 I'm going to go ahead and share in just a moment the user interface of Scratch. 1757 01:17:03,270 --> 01:17:05,370 But what's nice about Scratch is that this 1758 01:17:05,370 --> 01:17:08,400 is how we're going to implement that same program today. 1759 01:17:08,400 --> 01:17:11,200 These are two blocks or puzzle pieces on the screen, 1760 01:17:11,200 --> 01:17:15,670 and they've been interconnected to tell the computer to say "hello, world" 1761 01:17:15,670 --> 01:17:16,570 on the screen. 1762 01:17:16,570 --> 01:17:18,490 The user interface that we're about to use 1763 01:17:18,490 --> 01:17:20,652 will look generally something like this. 1764 01:17:20,652 --> 01:17:22,360 It's a web-based editor that you can also 1765 01:17:22,360 --> 01:17:24,160 download it locally to use offline. 1766 01:17:24,160 --> 01:17:28,120 And you'll see that at the left here are a whole bunch of puzzle pieces 1767 01:17:28,120 --> 01:17:29,020 or blocks. 1768 01:17:29,020 --> 01:17:31,630 They're categorized by color, and the blue ones 1769 01:17:31,630 --> 01:17:33,980 tend to relate to motion, for instance. 1770 01:17:33,980 --> 01:17:35,950 The purple ones represent looks. 1771 01:17:35,950 --> 01:17:37,750 The pink one represents sounds. 1772 01:17:37,750 --> 01:17:40,180 The yellow one represents events. 1773 01:17:40,180 --> 01:17:41,230 More on that soon. 1774 01:17:41,230 --> 01:17:43,270 The orange ones represent control, and then 1775 01:17:43,270 --> 01:17:46,390 there's operators, variables, my blocks, and even some extensions 1776 01:17:46,390 --> 01:17:47,690 we can install as well. 1777 01:17:47,690 --> 01:17:51,820 So it just categorizes things visually and colorfully so that you 1778 01:17:51,820 --> 01:17:53,470 can find what you're looking for. 1779 01:17:53,470 --> 01:17:56,740 But we're going to use these puzzle pieces to drag and drop them 1780 01:17:56,740 --> 01:17:58,300 onto this area here. 1781 01:17:58,300 --> 01:18:02,030 And we're going to connect them when we want them to do something. 1782 01:18:02,030 --> 01:18:02,890 What can they do? 1783 01:18:02,890 --> 01:18:06,010 Well, by default, Scratch comes with this cat here, otherwise known 1784 01:18:06,010 --> 01:18:09,760 as a sprite, which is a character in a game or in a graphics context. 1785 01:18:09,760 --> 01:18:12,310 And this cat lives in this two-dimensional world in which 1786 01:18:12,310 --> 01:18:14,050 the cat can go up, down, left, right. 1787 01:18:14,050 --> 01:18:16,330 And you can actually change the cat's costume 1788 01:18:16,330 --> 01:18:18,730 to be a dog, a bird, or anything else. 1789 01:18:18,730 --> 01:18:23,260 It really is more of an idea than it is a specific animal in this case. 1790 01:18:23,260 --> 01:18:26,950 But the world that Scratch lives in looks a little something like this. 1791 01:18:26,950 --> 01:18:29,860 It's like a Cartesian plane with x-coordinates and y-coordinates. 1792 01:18:29,860 --> 01:18:32,050 And the numbers don't so much matter fundamentally, 1793 01:18:32,050 --> 01:18:35,390 except that when you want the cat or any character to go up, 1794 01:18:35,390 --> 01:18:37,300 down, left, or right by some amount, it's 1795 01:18:37,300 --> 01:18:42,985 useful to know, for instance, that 0, 0 is the middle, 0 comma 0 for x comma y. 1796 01:18:42,985 --> 01:18:45,550 All the way up is a y value of 180. 1797 01:18:45,550 --> 01:18:47,470 All the way down is -180. 1798 01:18:47,470 --> 01:18:50,170 All the way to the left is -240. 1799 01:18:50,170 --> 01:18:52,030 All the way to the right is 240. 1800 01:18:52,030 --> 01:18:54,655 And generally, you're not going to have to worry about numbers. 1801 01:18:54,655 --> 01:18:58,030 You're going to use these relatively-- go right, go left, go up, or down. 1802 01:18:58,030 --> 01:19:01,970 But that's just the world that Scratch itself lives in here. 1803 01:19:01,970 --> 01:19:03,730 So let's go about using Scratch here. 1804 01:19:03,730 --> 01:19:06,880 I'm going to change over to my cloud-based editor 1805 01:19:06,880 --> 01:19:10,120 here, where I've gone to scratch.mit.edu. 1806 01:19:10,120 --> 01:19:12,520 And I've clicked Create in order to create a project. 1807 01:19:12,520 --> 01:19:14,822 And that gives me this blank canvas here. 1808 01:19:14,822 --> 01:19:17,530 And I'm going to do these somewhat quickly because I kind of know 1809 01:19:17,530 --> 01:19:18,440 what I'm looking for. 1810 01:19:18,440 --> 01:19:21,400 But part of the process with problem set zero is going to be clicking, 1811 01:19:21,400 --> 01:19:23,410 and dragging, and sort of scrolling around 1812 01:19:23,410 --> 01:19:25,390 to see what building blocks exist. 1813 01:19:25,390 --> 01:19:29,020 But I know under Events there's this puzzle piece here 1814 01:19:29,020 --> 01:19:30,910 when green flag clicked. 1815 01:19:30,910 --> 01:19:32,110 Why is that germane? 1816 01:19:32,110 --> 01:19:35,720 Well, if I zoom out, and go back to Scratch's world at the right here, 1817 01:19:35,720 --> 01:19:37,720 notice that above Scratch's world there's 1818 01:19:37,720 --> 01:19:40,870 a green flag, which is going to mean go, and a red stop sign, which, 1819 01:19:40,870 --> 01:19:42,290 of course, is going to mean stop. 1820 01:19:42,290 --> 01:19:46,780 So if I drag this puzzle piece anywhere into the middle, 1821 01:19:46,780 --> 01:19:49,180 it's just going to plop where I put it. 1822 01:19:49,180 --> 01:19:53,380 But what that means semantically is when someone clicks that green flag, 1823 01:19:53,380 --> 01:19:56,440 I want Scratch the cat to do this other thing. 1824 01:19:56,440 --> 01:19:57,970 Well, what do I want it to do? 1825 01:19:57,970 --> 01:19:59,560 Well, let me go under Looks. 1826 01:19:59,560 --> 01:20:04,090 And looks here in purple have some puzzle pieces like this. 1827 01:20:04,090 --> 01:20:06,490 Well, I can say hello for some number of seconds, 1828 01:20:06,490 --> 01:20:08,620 or I can just go ahead and say hello. 1829 01:20:08,620 --> 01:20:09,430 So let's do that. 1830 01:20:09,430 --> 01:20:11,650 I'm going to drag this say block. 1831 01:20:11,650 --> 01:20:13,630 And notice that as soon as I get close enough, 1832 01:20:13,630 --> 01:20:15,562 it's going to magnetically want to connect. 1833 01:20:15,562 --> 01:20:17,770 So I can let go, and they snap together automatically 1834 01:20:17,770 --> 01:20:19,103 because they're the right shape. 1835 01:20:19,103 --> 01:20:21,100 I don't have to say hello, exclamation point. 1836 01:20:21,100 --> 01:20:23,920 I can change it to the more canonical, hello comma world. 1837 01:20:23,920 --> 01:20:26,440 So anything in this white oval is editable 1838 01:20:26,440 --> 01:20:28,870 that you can change as just text there. 1839 01:20:28,870 --> 01:20:31,960 If I now zoom out, let me go ahead and click the green flag. 1840 01:20:31,960 --> 01:20:36,556 And voila-- this should be my first program in Scratch. 1841 01:20:36,556 --> 01:20:37,430 Hello, world. 1842 01:20:37,430 --> 01:20:39,410 Without any of the distractions of syntax 1843 01:20:39,410 --> 01:20:42,420 or weird characters on the screen, it's just done what I want it to do. 1844 01:20:42,420 --> 01:20:42,920 All right. 1845 01:20:42,920 --> 01:20:44,462 Let me go ahead and click Stop there. 1846 01:20:44,462 --> 01:20:47,240 And let me make it a little more connected 1847 01:20:47,240 --> 01:20:48,750 to what we've discussed thus far. 1848 01:20:48,750 --> 01:20:51,380 So this puzzle piece here, say hello, world, 1849 01:20:51,380 --> 01:20:56,370 represents what type of building block using the vocabulary of today? 1850 01:20:56,370 --> 01:20:57,420 So it's a function. 1851 01:20:57,420 --> 01:21:00,048 So these purple blocks are functions, say, hello, world. 1852 01:21:00,048 --> 01:21:02,090 And let me give you another piece of terminology. 1853 01:21:02,090 --> 01:21:04,910 These white ovals that take textual input-- 1854 01:21:04,910 --> 01:21:08,210 in general, those are called parameters or arguments. 1855 01:21:08,210 --> 01:21:11,610 And they customize the behavior of a function. 1856 01:21:11,610 --> 01:21:14,180 So a parameter or an argument customizes, 1857 01:21:14,180 --> 01:21:17,810 modifies the default behavior of a function, like in this case, say. 1858 01:21:17,810 --> 01:21:20,990 Similarly, in the C code from earlier that we'll see next week, 1859 01:21:20,990 --> 01:21:27,350 the printf function took a quoted phrase like, hello, world, similarly as input. 1860 01:21:27,350 --> 01:21:29,970 But more on that in the future. 1861 01:21:29,970 --> 01:21:32,810 So how does this connect to the mental model we presented earlier? 1862 01:21:32,810 --> 01:21:37,140 Well, here's problem-solving as I described it earlier, inputs to outputs 1863 01:21:37,140 --> 01:21:39,090 with algorithms or code in the middle. 1864 01:21:39,090 --> 01:21:43,710 Well, what we've got here really is an input of, hello, world, the white oval. 1865 01:21:43,710 --> 01:21:48,600 The function or algorithm that it's going into as input is the say block. 1866 01:21:48,600 --> 01:21:51,960 And what is the output of using this say block, the say function? 1867 01:21:51,960 --> 01:21:55,650 It's the visual effect of having the cat have the little speech bubble appear 1868 01:21:55,650 --> 01:21:58,060 above its head, saying, hello, world. 1869 01:21:58,060 --> 01:22:00,900 So everything we do, in fact, can be mapped back 1870 01:22:00,900 --> 01:22:04,590 to that very simple idea of inputs and outputs. 1871 01:22:04,590 --> 01:22:06,840 Well, let's make it a little more interesting, though. 1872 01:22:06,840 --> 01:22:09,430 It's a little boring to just say "hello, world" all the time. 1873 01:22:09,430 --> 01:22:11,500 Let me go ahead and drag this away. 1874 01:22:11,500 --> 01:22:15,180 And if you just drag it to the left and let go, it gets automatically deleted. 1875 01:22:15,180 --> 01:22:18,580 Let me go under Sensing in light blue here. 1876 01:22:18,580 --> 01:22:20,850 And you'll see there's a bunch of blocks, one of which 1877 01:22:20,850 --> 01:22:24,180 is an ask block, an ask function, which is going to prompt 1878 01:22:24,180 --> 01:22:26,170 the human, me, for some input. 1879 01:22:26,170 --> 01:22:29,700 So let me go ahead and drag that over here, and it snaps together. 1880 01:22:29,700 --> 01:22:32,190 I could change the question, but I'm OK with that question. 1881 01:22:32,190 --> 01:22:33,670 We'll use what's your name. 1882 01:22:33,670 --> 01:22:36,900 But notice that this block, ask, is a little special. 1883 01:22:36,900 --> 01:22:40,240 It is not just going to display like a speech bubble on the screen. 1884 01:22:40,240 --> 01:22:42,510 It's actually going to return a value, and this is 1885 01:22:42,510 --> 01:22:44,250 another term of art today and onward. 1886 01:22:44,250 --> 01:22:48,492 A return value is some value that can be handed back to you conceptually 1887 01:22:48,492 --> 01:22:50,700 from a function so that you can do something with it. 1888 01:22:50,700 --> 01:22:55,025 It's as though the ask function asks someone for their name, 1889 01:22:55,025 --> 01:22:57,900 writes it down on a piece of paper, and hands you the piece of paper. 1890 01:22:57,900 --> 01:23:00,150 You can do anything now that you want with that name. 1891 01:23:00,150 --> 01:23:03,810 And here is how you access the name in this special block called 1892 01:23:03,810 --> 01:23:07,330 answer, which, again, will start calling a return value. 1893 01:23:07,330 --> 01:23:10,770 So if I want to say "hello" to someone specific, I'm going to do this. 1894 01:23:10,770 --> 01:23:11,800 Let me zoom out. 1895 01:23:11,800 --> 01:23:15,510 Let me go back to Looks, and let me go back to Say. 1896 01:23:15,510 --> 01:23:19,890 And I'm going to change the say block here to "hello, comma." 1897 01:23:19,890 --> 01:23:21,270 Then I'm going to zoom out. 1898 01:23:21,270 --> 01:23:23,700 Well, I need two inputs, I think. 1899 01:23:23,700 --> 01:23:26,640 So I'm going to grab another say block, and I'm going to put it below. 1900 01:23:26,640 --> 01:23:29,160 And I could just type "David," but this is 1901 01:23:29,160 --> 01:23:31,660 going to defeat the whole point of asking me for the name. 1902 01:23:31,660 --> 01:23:32,610 And it will only work for me. 1903 01:23:32,610 --> 01:23:33,790 So I don't want to do that. 1904 01:23:33,790 --> 01:23:38,520 So let me go back to Sensing, and notice the shape is important here. 1905 01:23:38,520 --> 01:23:41,130 Even if it's not quite the same size, the shape matters. 1906 01:23:41,130 --> 01:23:45,690 And I can actually drag this and change the input of this say function 1907 01:23:45,690 --> 01:23:48,870 to be whatever that return value is, that piece of paper 1908 01:23:48,870 --> 01:23:50,430 that has the person's name on it. 1909 01:23:50,430 --> 01:23:53,550 And it grows to fill, but now we have a program 1910 01:23:53,550 --> 01:23:57,240 that I think when I click the green flag-- watch-- is going to prompt me. 1911 01:23:57,240 --> 01:23:58,367 What's your name? 1912 01:23:58,367 --> 01:23:59,950 And now I have room to type down here. 1913 01:23:59,950 --> 01:24:02,370 So I'm going to type D-A-V-I-D. I'm going to hit Enter, 1914 01:24:02,370 --> 01:24:04,000 and it should say "hello, Dave." 1915 01:24:04,000 --> 01:24:04,500 Wait. 1916 01:24:04,500 --> 01:24:06,110 Hmm. 1917 01:24:06,110 --> 01:24:07,050 Huh. 1918 01:24:07,050 --> 01:24:09,990 Maybe it was-- didn't work. 1919 01:24:09,990 --> 01:24:11,160 D-A-V-I-D. Here we go. 1920 01:24:11,160 --> 01:24:12,165 Hello, David. 1921 01:24:12,165 --> 01:24:13,530 Hmm. 1922 01:24:13,530 --> 01:24:19,210 It's missing the hello, but I'm quite sure we have a hello right there. 1923 01:24:19,210 --> 01:24:22,170 So what explains this bug or mistake? 1924 01:24:22,170 --> 01:24:23,117 Yeah. 1925 01:24:23,117 --> 01:24:26,596 AUDIENCE: [INAUDIBLE]. 1926 01:24:26,596 --> 01:24:29,090 So they overlap. 1927 01:24:29,090 --> 01:24:30,800 DAVID J. MALAN: Exactly. 1928 01:24:30,800 --> 01:24:33,710 Put another way, my Mac, my PC, it's just so darn 1929 01:24:33,710 --> 01:24:36,320 fast that it did exactly what it was supposed to. 1930 01:24:36,320 --> 01:24:40,580 But it said "hello, David" so fast that we didn't even see, we being the human, 1931 01:24:40,580 --> 01:24:42,795 the slowest part of the puzzle, see the actual hello. 1932 01:24:42,795 --> 01:24:45,170 So there's a few different ways to fix this, as you know. 1933 01:24:45,170 --> 01:24:48,660 We could have it say "hello" for some number of seconds. 1934 01:24:48,660 --> 01:24:49,910 So I could kind of do that. 1935 01:24:49,910 --> 01:24:50,660 So let me do this. 1936 01:24:50,660 --> 01:24:53,210 I can decouple these by just dragging and letting it go 1937 01:24:53,210 --> 01:24:55,220 so that they're magnetically far apart. 1938 01:24:55,220 --> 01:24:58,610 Let me go ahead and drag this one, say hello for two seconds. 1939 01:24:58,610 --> 01:25:02,030 I'm going to change the grammar here to be hello comma again. 1940 01:25:02,030 --> 01:25:05,120 I'm going to go ahead and disconnect these two. 1941 01:25:05,120 --> 01:25:08,160 I'm going to throw away the old one that I don't want to use. 1942 01:25:08,160 --> 01:25:11,460 And I'm going to reconnect this so that now-- 1943 01:25:11,460 --> 01:25:11,960 OK. 1944 01:25:11,960 --> 01:25:14,960 It's going to say hello for two seconds and then my name, hopefully. 1945 01:25:14,960 --> 01:25:17,180 So let me click Stop and Start. 1946 01:25:17,180 --> 01:25:20,970 D-A-V-I-D. Enter. 1947 01:25:20,970 --> 01:25:21,540 OK. 1948 01:25:21,540 --> 01:25:25,577 So it's better, but it's kind of poorly implemented. 1949 01:25:25,577 --> 01:25:26,160 Like, come on. 1950 01:25:26,160 --> 01:25:27,785 I just wanted to say hello comma David. 1951 01:25:27,785 --> 01:25:28,785 Why is that hard? 1952 01:25:28,785 --> 01:25:31,410 Well, maybe we can actually combine these a little differently. 1953 01:25:31,410 --> 01:25:32,610 And let me propose this. 1954 01:25:32,610 --> 01:25:35,760 Let me actually get rid of these blocks again. 1955 01:25:35,760 --> 01:25:38,430 And let me go ahead and just say one thing. 1956 01:25:38,430 --> 01:25:43,650 But can I somehow combine this to say hello comma David all in one breath? 1957 01:25:43,650 --> 01:25:46,348 Well, it turns out if I go under Operators, 1958 01:25:46,348 --> 01:25:49,140 I know from having played with this before that there's this puzzle 1959 01:25:49,140 --> 01:25:51,030 piece down here called join. 1960 01:25:51,030 --> 01:25:52,463 It's an oval. 1961 01:25:52,463 --> 01:25:54,630 It's a little big, but, again, it will grow to fill. 1962 01:25:54,630 --> 01:25:57,338 And by default, it wants to join two words, "apple" and "banana." 1963 01:25:57,338 --> 01:25:59,830 But those are just placeholders. 1964 01:25:59,830 --> 01:26:03,990 So let me go ahead and drag this over the default hello. 1965 01:26:03,990 --> 01:26:08,700 Let me change "apple" to hello comma space and then banana. 1966 01:26:08,700 --> 01:26:10,230 Let me go back to Sensing. 1967 01:26:10,230 --> 01:26:13,630 Let me grab answer and drag and drop that. 1968 01:26:13,630 --> 01:26:16,740 So now notice that I'm kind of layering my ideas. 1969 01:26:16,740 --> 01:26:20,980 And put another way, the output of this join block 1970 01:26:20,980 --> 01:26:22,980 is presumably going to join two things together, 1971 01:26:22,980 --> 01:26:25,110 apple and banana or hello comma David. 1972 01:26:25,110 --> 01:26:29,460 And then the output of join is going to become the input to say. 1973 01:26:29,460 --> 01:26:31,900 So aesthetically, it just looks better. 1974 01:26:31,900 --> 01:26:33,790 It's still correct, but it's just better. 1975 01:26:33,790 --> 01:26:36,840 So if I type "David," and hit Enter, hello, David. 1976 01:26:36,840 --> 01:26:38,820 This is what a normal program would presumably 1977 01:26:38,820 --> 01:26:42,390 do, not show you part of the phrase and then the rest of the phrase. 1978 01:26:42,390 --> 01:26:44,230 Like, it's just better in this way. 1979 01:26:44,230 --> 01:26:48,480 So let's connect this now to this same puzzle piece and this methodology. 1980 01:26:48,480 --> 01:26:50,610 So here's that same puzzle piece, ask. 1981 01:26:50,610 --> 01:26:53,520 How do we fit it into this input and output flow with algorithms? 1982 01:26:53,520 --> 01:26:57,120 Well, the input to that puzzle piece is something like, what's your name, 1983 01:26:57,120 --> 01:26:58,200 question mark. 1984 01:26:58,200 --> 01:27:01,680 Then the algorithm or the code implementation thereof 1985 01:27:01,680 --> 01:27:06,240 is this ask block and wait so the human has a moment to type their response in. 1986 01:27:06,240 --> 01:27:09,548 The output of that function recall is a return value. 1987 01:27:09,548 --> 01:27:12,840 You don't see anything on the screen by default because we've not used say yet, 1988 01:27:12,840 --> 01:27:14,860 but we get this return value. 1989 01:27:14,860 --> 01:27:18,120 And let me scooch everything over now so that we can now 1990 01:27:18,120 --> 01:27:20,110 join those inputs together. 1991 01:27:20,110 --> 01:27:21,610 So here's this puzzle piece. 1992 01:27:21,610 --> 01:27:24,940 Let me go ahead and propose that the inputs now to the join block 1993 01:27:24,940 --> 01:27:30,100 are two arguments or two parameters, so to speak, hello and answer. 1994 01:27:30,100 --> 01:27:32,740 They go into that join puzzle piece, whose purpose in life 1995 01:27:32,740 --> 01:27:36,040 is to return one joined version thereof. 1996 01:27:36,040 --> 01:27:38,470 Let me slide this all over logically now so 1997 01:27:38,470 --> 01:27:42,850 that now that output becomes the input to the say block 1998 01:27:42,850 --> 01:27:46,330 and now is why the cat has the speech bubble saying all at once, 1999 01:27:46,330 --> 01:27:47,740 hello comma David. 2000 01:27:47,740 --> 01:27:51,620 So what we've done here is kind of composed the output 2001 01:27:51,620 --> 01:27:54,017 and from one function into the input of another. 2002 01:27:54,017 --> 01:27:56,350 And you can think of this in a couple of different ways, 2003 01:27:56,350 --> 01:27:58,150 left to right, as I did there, or kind of 2004 01:27:58,150 --> 01:28:00,740 like stacking these things on top of one another. 2005 01:28:00,740 --> 01:28:02,860 But at the end of the day, even as programming 2006 01:28:02,860 --> 01:28:07,510 gets more and more powerful for us, it's just inputs and outputs, inputs 2007 01:28:07,510 --> 01:28:08,320 and outputs. 2008 01:28:08,320 --> 01:28:11,230 And thankfully, with built-in functionality from our friends 2009 01:28:11,230 --> 01:28:14,680 at MIT who designed Scratch, I can even do something playful like this. 2010 01:28:14,680 --> 01:28:16,990 I can go to that Extensions button at the bottom. 2011 01:28:16,990 --> 01:28:20,260 And there's a lot of fancy things I can add here, like text-to-speech. 2012 01:28:20,260 --> 01:28:22,680 So let me go ahead and choose text-to-speech. 2013 01:28:22,680 --> 01:28:28,050 And let me go ahead here and change the say block in purple. 2014 01:28:28,050 --> 01:28:30,450 Let me get rid of the say block, and let me borrow this. 2015 01:28:30,450 --> 01:28:33,300 Let me get the speak block like this. 2016 01:28:33,300 --> 01:28:35,250 And now let me drag and drop this oval. 2017 01:28:35,250 --> 01:28:36,470 It's going to grow to fill. 2018 01:28:36,470 --> 01:28:38,970 And I think it's just about to be a little more interesting. 2019 01:28:38,970 --> 01:28:42,090 Let me click Play now, and hopefully this isn't too loud. 2020 01:28:42,090 --> 01:28:44,280 D-A-V-I-D. Enter. 2021 01:28:44,280 --> 01:28:45,948 SPEAKER: Hello, David. 2022 01:28:45,948 --> 01:28:46,740 DAVID J. MALAN: OK. 2023 01:28:46,740 --> 01:28:47,730 [APPLAUSE] 2024 01:28:47,730 --> 01:28:50,350 Thank you. 2025 01:28:50,350 --> 01:28:50,980 Thank you. 2026 01:28:50,980 --> 01:28:51,835 That's a low bar. 2027 01:28:51,835 --> 01:28:54,550 [CHUCKLES] Let me go ahead and set the voice too. 2028 01:28:54,550 --> 01:28:56,830 And you might now remember how we began class, where 2029 01:28:56,830 --> 01:28:59,080 we had a robotic, computerized voice. 2030 01:28:59,080 --> 01:29:03,168 Well, we didn't use Scratch at the time, but we could change this in Scratch 2031 01:29:03,168 --> 01:29:04,460 alone to be a little different. 2032 01:29:04,460 --> 01:29:05,890 So D-A-V-I-D. 2033 01:29:05,890 --> 01:29:07,028 SPEAKER: Hello, David. 2034 01:29:07,028 --> 01:29:07,820 DAVID J. MALAN: OK. 2035 01:29:07,820 --> 01:29:10,070 Little creepy, but we can play all day long with that. 2036 01:29:10,070 --> 01:29:12,125 But the point is that these functions are just 2037 01:29:12,125 --> 01:29:13,750 now doing something a little different. 2038 01:29:13,750 --> 01:29:15,792 But it's just these inputs and outputs. 2039 01:29:15,792 --> 01:29:17,500 Well, let's make the cat more like a cat. 2040 01:29:17,500 --> 01:29:20,590 Let me go ahead and throw away all of this asking question stuff. 2041 01:29:20,590 --> 01:29:23,350 Let me go up to Sound, and let me go ahead 2042 01:29:23,350 --> 01:29:26,260 and drag the play sound meow until done. 2043 01:29:26,260 --> 01:29:27,910 And here too it comes with meow. 2044 01:29:27,910 --> 01:29:31,697 You can add your own sounds as well. 2045 01:29:31,697 --> 01:29:34,030 But I'm just going to use the default meow and here too. 2046 01:29:34,030 --> 01:29:35,447 Hopefully, this won't be too loud. 2047 01:29:35,447 --> 01:29:37,360 Let's make the cat meow by clicking Play. 2048 01:29:37,360 --> 01:29:39,530 [MEOWING] 2049 01:29:39,530 --> 01:29:40,030 OK. 2050 01:29:40,030 --> 01:29:42,200 It's a little piercing, but it's cute. 2051 01:29:42,200 --> 01:29:45,490 And if I want the cat to meow twice, I could just play the game twice. 2052 01:29:45,490 --> 01:29:48,410 [MEOWING] 2053 01:29:48,410 --> 01:29:48,910 All right. 2054 01:29:48,910 --> 01:29:52,360 But it would be nice to just get it to meow automatically two, or three, 2055 01:29:52,360 --> 01:29:53,240 or more times. 2056 01:29:53,240 --> 01:29:54,760 So you know what I could do? 2057 01:29:54,760 --> 01:29:56,820 I could just drag a second one of these. 2058 01:29:56,820 --> 01:29:57,820 Actually, you know what? 2059 01:29:57,820 --> 01:30:00,790 I could even just right-click or Control-click and duplicate them. 2060 01:30:00,790 --> 01:30:02,110 But I'll just keep dragging and dropping. 2061 01:30:02,110 --> 01:30:03,670 There's different ways to solve problems. 2062 01:30:03,670 --> 01:30:04,780 And now let me click Play. 2063 01:30:04,780 --> 01:30:07,370 [MEOWING] 2064 01:30:07,370 --> 01:30:07,870 OK. 2065 01:30:07,870 --> 01:30:09,940 Cat does not sound particularly happy. 2066 01:30:09,940 --> 01:30:12,320 So we could go under-- 2067 01:30:12,320 --> 01:30:13,690 how about Control? 2068 01:30:13,690 --> 01:30:15,220 We could wait one second. 2069 01:30:15,220 --> 01:30:18,740 Now, there's no room, but it will sort of expand to give room for me. 2070 01:30:18,740 --> 01:30:19,900 So let me try this. 2071 01:30:19,900 --> 01:30:22,540 And now it's going to wait one second in between meows. 2072 01:30:22,540 --> 01:30:25,828 [MEOWING] 2073 01:30:25,828 --> 01:30:26,820 2074 01:30:26,820 --> 01:30:27,330 OK. 2075 01:30:27,330 --> 01:30:28,830 Let me stipulate that is correct. 2076 01:30:28,830 --> 01:30:32,190 If my goal is to get the cat to meow three times, it meowed three times. 2077 01:30:32,190 --> 01:30:36,640 But per our discussion earlier of algorithms and the design thereof, 2078 01:30:36,640 --> 01:30:38,770 this is not the best design. 2079 01:30:38,770 --> 01:30:39,760 [MEOWING] 2080 01:30:39,760 --> 01:30:40,260 OK? 2081 01:30:40,260 --> 01:30:40,500 [LAUGHTER] 2082 01:30:40,500 --> 01:30:42,000 Thank you for playing along at home. 2083 01:30:42,000 --> 01:30:43,350 Yeah. 2084 01:30:43,350 --> 01:30:47,050 In what sense is this arguably not well-designed? 2085 01:30:47,050 --> 01:30:47,550 Yeah. 2086 01:30:47,550 --> 01:30:48,930 AUDIENCE: You repeated yourself. 2087 01:30:48,930 --> 01:30:51,600 DAVID J. MALAN: I repeated myself, which actually in programming 2088 01:30:51,600 --> 01:30:53,440 tends not to be a good thing. 2089 01:30:53,440 --> 01:30:54,510 Now, it was easy. 2090 01:30:54,510 --> 01:30:57,510 I almost resorted to copy-paste, which saves me time upfront. 2091 01:30:57,510 --> 01:30:59,400 But just imagine a contrived scenario. 2092 01:30:59,400 --> 01:31:02,350 Now, what if I want it to wait like two seconds in between? 2093 01:31:02,350 --> 01:31:02,850 All right. 2094 01:31:02,850 --> 01:31:03,940 It's not that big a deal. 2095 01:31:03,940 --> 01:31:05,640 I change it here, and I change it here. 2096 01:31:05,640 --> 01:31:07,913 But what if the program is meant to meow 10 times? 2097 01:31:07,913 --> 01:31:10,830 Then I have to change it here, and here, and here, and here, and here. 2098 01:31:10,830 --> 01:31:12,570 And eventually I'm going to screw up. 2099 01:31:12,570 --> 01:31:13,470 Humans are fallible. 2100 01:31:13,470 --> 01:31:14,970 I'm going to overlook one of them. 2101 01:31:14,970 --> 01:31:16,260 One time, it's going to be one second. 2102 01:31:16,260 --> 01:31:18,910 Another is going to be two, and just stupid things will happen. 2103 01:31:18,910 --> 01:31:23,050 You're setting yourself up for failure if you design things poorly. 2104 01:31:23,050 --> 01:31:26,440 And so I would propose that we use another type of building block 2105 01:31:26,440 --> 01:31:27,730 to solve this instead. 2106 01:31:27,730 --> 01:31:28,555 Yeah. 2107 01:31:28,555 --> 01:31:28,810 AUDIENCE: [INAUDIBLE] 2108 01:31:28,810 --> 01:31:29,685 DAVID J. MALAN: Yeah. 2109 01:31:29,685 --> 01:31:32,950 So we could use a loop and just write minimal code 2110 01:31:32,950 --> 01:31:35,240 but to accomplish even more functionality. 2111 01:31:35,240 --> 01:31:37,390 So let me throw away most of these blocks. 2112 01:31:37,390 --> 01:31:40,990 And let's go and grab this repeat block, which we haven't used yet, 2113 01:31:40,990 --> 01:31:42,042 but it's right there. 2114 01:31:42,042 --> 01:31:43,750 And as the name suggests, this will allow 2115 01:31:43,750 --> 01:31:45,850 me to repeat something some number of times. 2116 01:31:45,850 --> 01:31:48,280 Let me put these two puzzle pieces inside. 2117 01:31:48,280 --> 01:31:49,330 It'll grow to fill. 2118 01:31:49,330 --> 01:31:51,370 Let me reconnect it to the green flag. 2119 01:31:51,370 --> 01:31:53,470 I'll change the default 10 to a 3. 2120 01:31:53,470 --> 01:31:54,265 And now-- 2121 01:31:54,265 --> 01:31:57,526 [MEOWING] 2122 01:31:57,526 --> 01:31:58,940 2123 01:31:58,940 --> 01:32:02,290 It's just sort of better because if now you want it to meow more times, 2124 01:32:02,290 --> 01:32:03,290 you change it one place. 2125 01:32:03,290 --> 01:32:05,623 If you want it to slow down, you change it in one place. 2126 01:32:05,623 --> 01:32:07,280 There's no room for error. 2127 01:32:07,280 --> 01:32:09,920 And that's generally a good thing. 2128 01:32:09,920 --> 01:32:10,670 But this is silly. 2129 01:32:10,670 --> 01:32:12,350 Like, Scratch comes with a cat. 2130 01:32:12,350 --> 01:32:15,590 Why didn't MIT give us a puzzle piece called "meow?" 2131 01:32:15,590 --> 01:32:18,460 Like, why am I implementing the idea of meowing myself? 2132 01:32:18,460 --> 01:32:19,460 Like, that took me what? 2133 01:32:19,460 --> 01:32:21,410 1, 2, 3, 4 puzzle pieces. 2134 01:32:21,410 --> 01:32:24,080 Why isn't there just one puzzle piece that meows for me? 2135 01:32:24,080 --> 01:32:28,430 This too we can do in code, be it in Scratch, or C, or other languages too. 2136 01:32:28,430 --> 01:32:32,660 I'm going to go down to these pink my blocks here, 2137 01:32:32,660 --> 01:32:35,027 where I can create my own puzzle piece. 2138 01:32:35,027 --> 01:32:36,860 And I'm going to call this literally "meow." 2139 01:32:36,860 --> 01:32:39,150 And I'm going to go ahead and just click OK. 2140 01:32:39,150 --> 01:32:42,242 And notice that it's given me this new type of start connector. 2141 01:32:42,242 --> 01:32:44,450 It's a start puzzle piece that nothing goes above it. 2142 01:32:44,450 --> 01:32:46,430 But you can put anything you want below it. 2143 01:32:46,430 --> 01:32:48,170 And I'm going to go ahead and cheat here. 2144 01:32:48,170 --> 01:32:51,390 I'm just going to grab my existing code, so to speak. 2145 01:32:51,390 --> 01:32:53,810 This is code I'm writing, even though it's puzzle pieces. 2146 01:32:53,810 --> 01:32:57,380 And now let me just claim, and I'll move this aside. 2147 01:32:57,380 --> 01:33:00,690 Here is now an implementation of my own function, 2148 01:33:00,690 --> 01:33:03,510 my own block called "meow," whose purpose in life 2149 01:33:03,510 --> 01:33:06,180 is to meow until done and then wait one second. 2150 01:33:06,180 --> 01:33:10,350 But what's powerful now is notice at top left, now that I've made the block, 2151 01:33:10,350 --> 01:33:12,910 I can use it any number of times. 2152 01:33:12,910 --> 01:33:17,520 So I can grab this meow block, drag it over here, and you know what? 2153 01:33:17,520 --> 01:33:21,590 Now that "meow" exists as an idea, I can abstract that away. 2154 01:33:21,590 --> 01:33:24,090 And I'm just going to arbitrarily drag it way to the bottom. 2155 01:33:24,090 --> 01:33:24,990 I'm not deleting it. 2156 01:33:24,990 --> 01:33:27,270 I'm just putting it out of sight, out of mind so 2157 01:33:27,270 --> 01:33:28,890 that we can focus now on this idea. 2158 01:33:28,890 --> 01:33:31,410 And I claim that this implementation of meowing 2159 01:33:31,410 --> 01:33:35,010 is sort of better because it's more compact, it does what it says, 2160 01:33:35,010 --> 01:33:38,520 and I don't care about the implementation details of "meow." 2161 01:33:38,520 --> 01:33:41,640 So this idea of abstraction, something we're going to use frequently. 2162 01:33:41,640 --> 01:33:44,767 To abstract something away is to simplify. 2163 01:33:44,767 --> 01:33:47,100 Don't think about the underlying implementation details. 2164 01:33:47,100 --> 01:33:50,130 Just care about what it does or what it's called. 2165 01:33:50,130 --> 01:33:52,590 Someone has to care about the implementation details, 2166 01:33:52,590 --> 01:33:54,330 like me 30 seconds ago. 2167 01:33:54,330 --> 01:33:56,430 But here on out, I don't need to care. 2168 01:33:56,430 --> 01:33:59,690 And so in fact, you and I are using the abstraction 2169 01:33:59,690 --> 01:34:02,940 that is Scratch because I don't know how to put a speech bubble on the screen. 2170 01:34:02,940 --> 01:34:04,773 I don't know how to create that sound, meow. 2171 01:34:04,773 --> 01:34:07,380 MIT did that, and they abstracted those pieces 2172 01:34:07,380 --> 01:34:10,440 of functionality away already for us by just giving us 2173 01:34:10,440 --> 01:34:12,280 these puzzle pieces we see here. 2174 01:34:12,280 --> 01:34:14,445 So the code will work the exact same. 2175 01:34:14,445 --> 01:34:17,330 [MEOWING] 2176 01:34:17,330 --> 01:34:21,640 But it's sort of better designed now because now I've 2177 01:34:21,640 --> 01:34:23,470 abstracted away the idea of meowing. 2178 01:34:23,470 --> 01:34:25,690 But I bet I can improve this further. 2179 01:34:25,690 --> 01:34:28,390 Can I get rid of the repeat block altogether? 2180 01:34:28,390 --> 01:34:31,510 And let me just tell the meow block how many times to meow. 2181 01:34:31,510 --> 01:34:35,170 Well, let me go down to the bottom and look at the implementation details. 2182 01:34:35,170 --> 01:34:37,270 I'm going to right-click or Control-click on this, 2183 01:34:37,270 --> 01:34:38,210 and I'm going to edit it. 2184 01:34:38,210 --> 01:34:39,290 So I'm going to make a change. 2185 01:34:39,290 --> 01:34:42,290 And I didn't do this before, but I'm going to call it "meow," as before. 2186 01:34:42,290 --> 01:34:43,780 I'm going to add an input. 2187 01:34:43,780 --> 01:34:46,240 And just so I know what it says what it does, 2188 01:34:46,240 --> 01:34:49,000 I'm going to add the word "times" here. 2189 01:34:49,000 --> 01:34:52,840 And I'm going to change this placeholder to n. 2190 01:34:52,840 --> 01:34:54,970 n for "number" is the go-to placeholder any time 2191 01:34:54,970 --> 01:34:57,230 we want to talk about a number in CS. 2192 01:34:57,230 --> 01:35:00,020 So now notice the puzzle piece looks a little different. 2193 01:35:00,020 --> 01:35:02,830 It takes an argument or a parameter called 2194 01:35:02,830 --> 01:35:05,680 n, which represents the number of times you want the thing to meow. 2195 01:35:05,680 --> 01:35:07,280 Now, that doesn't do that yet. 2196 01:35:07,280 --> 01:35:10,240 So let me go back to my other code. 2197 01:35:10,240 --> 01:35:13,210 Let me just decouple these temporarily. 2198 01:35:13,210 --> 01:35:17,950 I'm going to move my loop into my implementation of meowing. 2199 01:35:17,950 --> 01:35:21,950 But I don't want to hard code, that is literally write the number 3 anymore. 2200 01:35:21,950 --> 01:35:25,860 I'm going to grab this oval and put it there. 2201 01:35:25,860 --> 01:35:27,900 So now I've generalized the function. 2202 01:35:27,900 --> 01:35:33,860 So now it will meow any number of times, 0 on up, by executing that loop 2203 01:35:33,860 --> 01:35:35,540 and now more powerfully. 2204 01:35:35,540 --> 01:35:36,890 Out of sight, out of mind. 2205 01:35:36,890 --> 01:35:40,850 Notice that my code just became so darn simple. 2206 01:35:40,850 --> 01:35:42,650 Like, my function is called "meow." 2207 01:35:42,650 --> 01:35:44,330 It meows some number of times. 2208 01:35:44,330 --> 01:35:46,910 All I have to do is type a number there, and it just works. 2209 01:35:46,910 --> 01:35:50,660 And I don't care any more about those lower-level, so to speak, 2210 01:35:50,660 --> 01:35:52,230 implementation details. 2211 01:35:52,230 --> 01:35:53,270 So here, no surprise. 2212 01:35:53,270 --> 01:35:55,985 If I type in the number 3, zoom out, and hit Play-- 2213 01:35:55,985 --> 01:36:00,270 [MEOWING] 2214 01:36:00,270 --> 01:36:02,500 --it still works just fine. 2215 01:36:02,500 --> 01:36:05,460 So any questions on what we've just done here? 2216 01:36:05,460 --> 01:36:07,710 It's still just meowing, but that's besides the point. 2217 01:36:07,710 --> 01:36:11,340 It's this creation of our own functions, this modularity, 2218 01:36:11,340 --> 01:36:15,640 this abstraction that's going to be the idea that keeps coming back to us. 2219 01:36:15,640 --> 01:36:16,140 No? 2220 01:36:16,140 --> 01:36:16,640 All right. 2221 01:36:16,640 --> 01:36:19,050 So let's make this a little more cat-like. 2222 01:36:19,050 --> 01:36:20,980 Let me throw away all of this code. 2223 01:36:20,980 --> 01:36:22,000 And let me go ahead-- 2224 01:36:22,000 --> 01:36:25,000 oops-- let me throw away this code first and then the rest of this code. 2225 01:36:25,000 --> 01:36:28,500 And let me go ahead and give myself another green flag block. 2226 01:36:28,500 --> 01:36:32,430 And let me go ahead, and let's create a cat that allows us to pet it 2227 01:36:32,430 --> 01:36:34,530 by moving my cursor over the cat. 2228 01:36:34,530 --> 01:36:36,820 And maybe it likes that, so it'll meow when I do that. 2229 01:36:36,820 --> 01:36:42,270 So let me go under Control, and let me grab this if conditional, 2230 01:36:42,270 --> 01:36:44,910 which we talked about as a building block earlier. 2231 01:36:44,910 --> 01:36:47,310 Let me go to Sensing, and we haven't used this before. 2232 01:36:47,310 --> 01:36:50,130 But here is a weird sort of diagonal shape 2233 01:36:50,130 --> 01:36:52,440 that says touching mouse pointer question mark. 2234 01:36:52,440 --> 01:36:54,027 So that's a Boolean expression. 2235 01:36:54,027 --> 01:36:56,610 So I'm going to drag that, and it's definitely the wrong size. 2236 01:36:56,610 --> 01:36:59,070 But it is the right shape, so it will grow to fill. 2237 01:36:59,070 --> 01:37:03,820 And the question I want to ask is if the cat is touching the mouse pointer, 2238 01:37:03,820 --> 01:37:05,770 then go ahead and meow happily. 2239 01:37:05,770 --> 01:37:08,360 So let me grab the meow sound, put it in there. 2240 01:37:08,360 --> 01:37:12,970 And so I think when I click the green flag to start the program, 2241 01:37:12,970 --> 01:37:19,174 and now I let the mouse pointer touch the cat, we should hear-- 2242 01:37:19,174 --> 01:37:20,110 huh. 2243 01:37:20,110 --> 01:37:21,120 huh. 2244 01:37:21,120 --> 01:37:23,820 Doesn't seem to be working. 2245 01:37:23,820 --> 01:37:27,440 There's a bug or a mistake in this program too. 2246 01:37:27,440 --> 01:37:28,440 What did I do wrong? 2247 01:37:28,440 --> 01:37:28,940 Yeah. 2248 01:37:28,940 --> 01:37:31,090 AUDIENCE: You didn't specify the sprite [INAUDIBLE].. 2249 01:37:31,090 --> 01:37:33,130 DAVID J. MALAN: I don't need to specify the sprite explicitly 2250 01:37:33,130 --> 01:37:35,200 because a detail I didn't discuss earlier. 2251 01:37:35,200 --> 01:37:37,630 In the bottom right of the screen, notice 2252 01:37:37,630 --> 01:37:39,890 that the cat is already selected. 2253 01:37:39,890 --> 01:37:42,100 So this code relates to that cat. 2254 01:37:42,100 --> 01:37:45,340 So your instinct is good if we had two or more sprites, 2255 01:37:45,340 --> 01:37:48,045 but I just have one, so I'm covered there. 2256 01:37:48,045 --> 01:37:48,670 Other thoughts. 2257 01:37:48,670 --> 01:37:49,602 Yeah. 2258 01:37:49,602 --> 01:37:50,870 AUDIENCE: It only checks once. 2259 01:37:50,870 --> 01:37:51,980 DAVID J. MALAN: It only checks? 2260 01:37:51,980 --> 01:37:52,250 AUDIENCE: Once. 2261 01:37:52,250 --> 01:37:53,125 DAVID J. MALAN: Once. 2262 01:37:53,125 --> 01:37:54,960 So I click the green flag. 2263 01:37:54,960 --> 01:37:57,230 The computer did what I told it to do. 2264 01:37:57,230 --> 01:38:00,165 The mouse pointer was not touching the cat at that moment 2265 01:38:00,165 --> 01:38:01,790 because it was touching the green flag. 2266 01:38:01,790 --> 01:38:03,320 So, of course, it didn't meow. 2267 01:38:03,320 --> 01:38:05,360 So what maybe is the fix here? 2268 01:38:05,360 --> 01:38:06,980 What puzzle piece can we add? 2269 01:38:06,980 --> 01:38:09,290 AUDIENCE: After the green flag is [INAUDIBLE].. 2270 01:38:09,290 --> 01:38:10,140 DAVID J. MALAN: OK. 2271 01:38:10,140 --> 01:38:10,640 OK. 2272 01:38:10,640 --> 01:38:12,360 Interesting solution. 2273 01:38:12,360 --> 01:38:17,930 So let me go ahead, and under Control let me grab a-- wait one second. 2274 01:38:17,930 --> 01:38:21,360 I'm going to change the 1 to 5, and now I'm going to click the green flag. 2275 01:38:21,360 --> 01:38:22,370 So here we go. 2276 01:38:22,370 --> 01:38:28,490 1, 2, 3, 4, 5. 2277 01:38:28,490 --> 01:38:29,060 Damn it. 2278 01:38:29,060 --> 01:38:29,630 [MEOWING] 2279 01:38:29,630 --> 01:38:29,810 OK. 2280 01:38:29,810 --> 01:38:30,852 That was yours, not mine. 2281 01:38:30,852 --> 01:38:32,240 [LAUGHTER] 2282 01:38:32,240 --> 01:38:33,915 It didn't work. 2283 01:38:33,915 --> 01:38:34,790 AUDIENCE: [INAUDIBLE] 2284 01:38:34,790 --> 01:38:35,707 DAVID J. MALAN: Sorry? 2285 01:38:35,707 --> 01:38:36,703 AUDIENCE: [INAUDIBLE] 2286 01:38:36,703 --> 01:38:38,120 DAVID J. MALAN: Oh, maybe forever. 2287 01:38:38,120 --> 01:38:42,230 So your approach would work, but it's very much a hack, if you will. 2288 01:38:42,230 --> 01:38:46,700 Like, I would have to time it perfectly so that the mouse pointer is touching 2289 01:38:46,700 --> 01:38:49,040 it, or, conversely, I have to drag it there and just 2290 01:38:49,040 --> 01:38:50,540 leave it there for five seconds. 2291 01:38:50,540 --> 01:38:53,040 And that's a little weird because you don't just touch a cat 2292 01:38:53,040 --> 01:38:54,960 and then five seconds later it meows at you. 2293 01:38:54,960 --> 01:38:57,190 Like, presumably, we want it to be more interactive. 2294 01:38:57,190 --> 01:38:58,660 So I like this idea of a loop. 2295 01:38:58,660 --> 01:38:59,160 Right? 2296 01:38:59,160 --> 01:39:04,440 Why don't we just tell the cat to forever listen for the cursor 2297 01:39:04,440 --> 01:39:07,170 as by using not repeat but forever? 2298 01:39:07,170 --> 01:39:08,240 Let me move this in here. 2299 01:39:08,240 --> 01:39:11,490 So now the cat's going to be told when the green flag is clicked just forever, 2300 01:39:11,490 --> 01:39:13,073 if touching, if touching, if touching. 2301 01:39:13,073 --> 01:39:15,270 Oh, meow when actually touched. 2302 01:39:15,270 --> 01:39:19,368 So now if I zoom out and hit Play, nothing's happening. 2303 01:39:19,368 --> 01:39:21,160 I don't have to wait any number of seconds. 2304 01:39:21,160 --> 01:39:22,545 But when I do touch the cat-- 2305 01:39:22,545 --> 01:39:23,260 [MEOWING] 2306 01:39:23,260 --> 01:39:24,180 [APPLAUSE] 2307 01:39:24,180 --> 01:39:26,765 [CHUCKLES] Fan section here. 2308 01:39:26,765 --> 01:39:27,265 Thank you. 2309 01:39:27,265 --> 01:39:27,765 [MEOWING] 2310 01:39:27,765 --> 01:39:30,890 So now it's actually working quite well. 2311 01:39:30,890 --> 01:39:33,220 So there we have sort of a logical bug. 2312 01:39:33,220 --> 01:39:35,545 But it does make sense if you think about what it was 2313 01:39:35,545 --> 01:39:38,020 you told the computer to actually do. 2314 01:39:38,020 --> 01:39:39,915 Well, let's make things even more interesting 2315 01:39:39,915 --> 01:39:41,290 by using one of these extensions. 2316 01:39:41,290 --> 01:39:44,620 In this bottom left corner, this is how I got to text-to-speech earlier. 2317 01:39:44,620 --> 01:39:47,470 Let me go to Video Sensing over here too. 2318 01:39:47,470 --> 01:39:50,750 And I can actually-- there we go-- literally, the video has come on. 2319 01:39:50,750 --> 01:39:52,060 Let me go ahead and do this. 2320 01:39:52,060 --> 01:39:55,690 Get rid of this code, and let me step out of the frame. 2321 01:39:55,690 --> 01:39:58,540 When video motion is greater than-- 2322 01:39:58,540 --> 01:40:00,490 well, this is CS50, so let's just type in 50, 2323 01:40:00,490 --> 01:40:02,150 which is just a measure of motion. 2324 01:40:02,150 --> 01:40:07,370 Let me go and play sound meow. 2325 01:40:07,370 --> 01:40:07,870 OK. 2326 01:40:07,870 --> 01:40:11,720 And let me stop and restart. 2327 01:40:11,720 --> 01:40:12,220 All right. 2328 01:40:12,220 --> 01:40:13,030 So there's the cat. 2329 01:40:13,030 --> 01:40:18,270 2330 01:40:18,270 --> 01:40:19,260 [MEOWING] 2331 01:40:19,260 --> 01:40:20,040 OK. 2332 01:40:20,040 --> 01:40:20,880 It worked. 2333 01:40:20,880 --> 01:40:24,330 The cat's a little insensitive. 2334 01:40:24,330 --> 01:40:25,190 [MEOWING] 2335 01:40:25,190 --> 01:40:25,720 There we go. 2336 01:40:25,720 --> 01:40:26,720 Actually, you know what? 2337 01:40:26,720 --> 01:40:30,300 Maybe it's just-- let me put-- let's change it. 2338 01:40:30,300 --> 01:40:31,130 20. 2339 01:40:31,130 --> 01:40:31,940 Oh, my God. 2340 01:40:31,940 --> 01:40:33,480 Oh, that's OK. 2341 01:40:33,480 --> 01:40:33,980 [MEOWING] 2342 01:40:33,980 --> 01:40:34,790 There we go. 2343 01:40:34,790 --> 01:40:35,690 All right. 2344 01:40:35,690 --> 01:40:36,420 There we go. 2345 01:40:36,420 --> 01:40:40,038 So now it's a little more sensitive to the petting by using the camera. 2346 01:40:40,038 --> 01:40:41,580 Now, this is kind of a weird example. 2347 01:40:41,580 --> 01:40:43,160 And if I just start moving around crazily, like, 2348 01:40:43,160 --> 01:40:45,320 it's just going to meow incessantly, which was what was happening-- 2349 01:40:45,320 --> 01:40:46,430 [MEOWING] 2350 01:40:46,430 --> 01:40:48,222 Stop. 2351 01:40:48,222 --> 01:40:49,020 [LAUGHTER] 2352 01:40:49,020 --> 01:40:49,520 OK. 2353 01:40:49,520 --> 01:40:51,800 When in doubt, this is when you reload the page. 2354 01:40:51,800 --> 01:40:53,010 [LAUGHTER] 2355 01:40:53,010 --> 01:40:53,510 All right. 2356 01:40:53,510 --> 01:40:55,730 So now we're back to where we wanted to be. 2357 01:40:55,730 --> 01:40:58,220 But where can we now use these kinds of building blocks? 2358 01:40:58,220 --> 01:41:00,540 Like, we were doing such tiny little programs. 2359 01:41:00,540 --> 01:41:04,220 But even that we could turn into a whole game, I bet. 2360 01:41:04,220 --> 01:41:07,700 Could we get like one volunteer to come on up? 2361 01:41:07,700 --> 01:41:08,810 One volunteer? 2362 01:41:08,810 --> 01:41:10,170 Everyone's looking down. 2363 01:41:10,170 --> 01:41:10,670 OK. 2364 01:41:10,670 --> 01:41:11,180 On the end here. 2365 01:41:11,180 --> 01:41:11,722 Come on down. 2366 01:41:11,722 --> 01:41:12,290 Yeah. 2367 01:41:12,290 --> 01:41:12,790 All right. 2368 01:41:12,790 --> 01:41:14,930 Round of applause for our one brave volunteer here. 2369 01:41:14,930 --> 01:41:18,150 [APPLAUSE] 2370 01:41:18,150 --> 01:41:18,650 2371 01:41:18,650 --> 01:41:19,400 All right. 2372 01:41:19,400 --> 01:41:22,020 These Super Mario cookies are on the line for you, 2373 01:41:22,020 --> 01:41:23,160 depending on how this goes. 2374 01:41:23,160 --> 01:41:24,827 So I'm going to have you come over here. 2375 01:41:24,827 --> 01:41:28,940 And in advance on Scratch's website, we have some pre-made games, 2376 01:41:28,940 --> 01:41:32,930 one of them written by one of your predecessors, a former student, 2377 01:41:32,930 --> 01:41:36,050 that they implemented this sort of "Whac-A-Mole" game. 2378 01:41:36,050 --> 01:41:39,290 So what you're about to see is the camera turn on on you. 2379 01:41:39,290 --> 01:41:43,160 And you're going to see four moles above, below, left, and right. 2380 01:41:43,160 --> 01:41:44,720 And using only your head-- 2381 01:41:44,720 --> 01:41:47,930 up, down, left, right-- the goal is to whack a mole 2382 01:41:47,930 --> 01:41:51,860 to get a point every time your head touches one of these sprites. 2383 01:41:51,860 --> 01:41:54,740 So you're about to see things get very interesting very quickly. 2384 01:41:54,740 --> 01:41:57,050 But using these building blocks, just those simple 2385 01:41:57,050 --> 01:42:01,350 blocks but have four sprites, not four cats but four moles in this case. 2386 01:42:01,350 --> 01:42:03,955 We can actually turn these into actual games. 2387 01:42:03,955 --> 01:42:04,580 [MUSIC PLAYING] 2388 01:42:04,580 --> 01:42:06,950 So here we go. 2389 01:42:06,950 --> 01:42:08,360 Click Beginner. 2390 01:42:08,360 --> 01:42:08,900 OK. 2391 01:42:08,900 --> 01:42:10,858 And we just need you to center your head first. 2392 01:42:10,858 --> 01:42:13,808 [MUSIC PLAYING] 2393 01:42:13,808 --> 01:42:20,152 2394 01:42:20,152 --> 01:42:23,080 [INDISTINCT CHATTER] 2395 01:42:23,080 --> 01:42:24,056 2396 01:42:24,056 --> 01:42:25,032 [CHUCKLES] 2397 01:42:25,032 --> 01:42:28,448 [MUSIC PLAYING] 2398 01:42:28,448 --> 01:42:30,920 2399 01:42:30,920 --> 01:42:31,820 Nice. 2400 01:42:31,820 --> 01:42:32,630 Ten seconds. 2401 01:42:32,630 --> 01:42:36,004 [MUSIC PLAYING] 2402 01:42:36,004 --> 01:42:39,390 2403 01:42:39,390 --> 01:42:40,470 Nice. 2404 01:42:40,470 --> 01:42:42,486 Two seconds. 2405 01:42:42,486 --> 01:42:43,290 AUDIENCE: [LAUGHS] 2406 01:42:43,290 --> 01:42:43,770 DAVID J. MALAN: All right. 2407 01:42:43,770 --> 01:42:44,610 A round of applause. 2408 01:42:44,610 --> 01:42:45,906 [APPLAUSE] 2409 01:42:45,906 --> 01:42:48,100 Thank you. 2410 01:42:48,100 --> 01:42:50,380 You want to introduce yourself? 2411 01:42:50,380 --> 01:42:51,380 AUDIENCE: Hi, everybody. 2412 01:42:51,380 --> 01:42:53,890 My name is [? Vanilla. ?] I'm a first year, 2413 01:42:53,890 --> 01:42:56,955 and I'm going to be majoring in computer science and economics. 2414 01:42:56,955 --> 01:42:58,330 DAVID J. MALAN: Nice to meet you. 2415 01:42:58,330 --> 01:42:58,830 Here we go. 2416 01:42:58,830 --> 01:42:59,435 Thank you. 2417 01:42:59,435 --> 01:43:00,560 AUDIENCE: Nice to meet you. 2418 01:43:00,560 --> 01:43:01,393 [APPLAUSE, CHEERING] 2419 01:43:01,393 --> 01:43:04,210 DAVID J. MALAN: So we won't look at the code for that actual game. 2420 01:43:04,210 --> 01:43:05,740 It was written by one of your predecessors. 2421 01:43:05,740 --> 01:43:07,573 And you can see it online if you're curious. 2422 01:43:07,573 --> 01:43:10,780 But you can think about now with our functions, conditionals, 2423 01:43:10,780 --> 01:43:15,010 Boolean expressions, loops how you could kind of compose that kind of program. 2424 01:43:15,010 --> 01:43:17,770 So odds are there was a loop that was just constantly listening 2425 01:43:17,770 --> 01:43:19,690 for that kind of connectivity, or it was one 2426 01:43:19,690 --> 01:43:22,900 of those extensions that was waiting for motion to go 2427 01:43:22,900 --> 01:43:24,180 touch one of those sprites. 2428 01:43:24,180 --> 01:43:25,930 Notice that there's these numbers up here. 2429 01:43:25,930 --> 01:43:27,040 And we haven't talked about this yet. 2430 01:43:27,040 --> 01:43:30,040 But just like in math, where you can have variables x, y, and z, 2431 01:43:30,040 --> 01:43:33,220 in programming, you can create variables using other puzzle pieces 2432 01:43:33,220 --> 01:43:36,460 in Scratch that just keep track of how many seconds are left, 2433 01:43:36,460 --> 01:43:40,310 that keeps track of how many times her head hit one of the moles. 2434 01:43:40,310 --> 01:43:43,760 And so you can implement the mechanics of games using very simple building 2435 01:43:43,760 --> 01:43:44,260 blocks. 2436 01:43:44,260 --> 01:43:46,240 But how do you go about building something 2437 01:43:46,240 --> 01:43:48,600 that's more interesting and interactive like that? 2438 01:43:48,600 --> 01:43:50,760 Let me go ahead and bring up, for instance, 2439 01:43:50,760 --> 01:43:52,930 one of the very first things I wrote years ago 2440 01:43:52,930 --> 01:43:55,430 when I was in graduate school and Scratch had just come out. 2441 01:43:55,430 --> 01:43:57,380 I was taking a class at MIT's Media Lab. 2442 01:43:57,380 --> 01:44:01,520 And they invited us to beta test-- that is, try out the software before it then 2443 01:44:01,520 --> 01:44:03,140 became part of the world. 2444 01:44:03,140 --> 01:44:07,200 And the game I made was this one here. 2445 01:44:07,200 --> 01:44:10,640 Let me find the right version of "Oscartime." 2446 01:44:10,640 --> 01:44:15,673 So "Oscartime" is a game that took me tens of hours probably in the end. 2447 01:44:15,673 --> 01:44:18,590 It was a little bit addictive, but let me go ahead and full-screen it. 2448 01:44:18,590 --> 01:44:20,270 And I won't play the whole game. 2449 01:44:20,270 --> 01:44:23,995 But it looked a little something like this. 2450 01:44:23,995 --> 01:44:25,120 OSCAR: (SINGS) Oh, I love-- 2451 01:44:25,120 --> 01:44:28,220 DAVID J. MALAN: Where trash is falling from the sky. 2452 01:44:28,220 --> 01:44:30,070 And I can click on it and drag it. 2453 01:44:30,070 --> 01:44:33,430 And notice as I get close, the lid opens up like this. 2454 01:44:33,430 --> 01:44:37,450 And if I let it keep falling, it goes in, and Oscar gives me a point. 2455 01:44:37,450 --> 01:44:39,585 And I can do this again. 2456 01:44:39,585 --> 01:44:41,710 OSCAR: If you really want to see something trashy-- 2457 01:44:41,710 --> 01:44:41,860 DAVID J. MALAN: All right. 2458 01:44:41,860 --> 01:44:42,943 Here comes something else. 2459 01:44:42,943 --> 01:44:44,565 OSCAR: I have here a sneaker that-- 2460 01:44:44,565 --> 01:44:46,690 DAVID J. MALAN: So now there's two pieces of trash. 2461 01:44:46,690 --> 01:44:49,787 OSCAR: It's all full of holes, and the laces are-- 2462 01:44:49,787 --> 01:44:52,370 DAVID J. MALAN: And it just keeps going, and going, and going. 2463 01:44:52,370 --> 01:44:55,537 And if we can lower the volume for just a moment, we'll let more trash fall. 2464 01:44:55,537 --> 01:44:58,300 But to your comment earlier about one sprite or more 2465 01:44:58,300 --> 01:45:00,040 sprites, that's what we're seeing here. 2466 01:45:00,040 --> 01:45:03,190 Even though our examples thus far are just one cat, one or two puzzle 2467 01:45:03,190 --> 01:45:04,660 pieces, or a few puzzle pieces. 2468 01:45:04,660 --> 01:45:06,670 Here is, I claim, a sprite. 2469 01:45:06,670 --> 01:45:08,110 Here is another sprite. 2470 01:45:08,110 --> 01:45:09,340 Here is another sprite. 2471 01:45:09,340 --> 01:45:11,950 And by toggling among them in that bottom right-hand corner, 2472 01:45:11,950 --> 01:45:15,460 I can just associate different puzzle pieces with each of these sprites. 2473 01:45:15,460 --> 01:45:17,987 Now, I didn't start off by implementing this whole game. 2474 01:45:17,987 --> 01:45:20,570 And in just a moment, if we can raise the volume a little bit, 2475 01:45:20,570 --> 01:45:22,400 we'll see even more trash is falling. 2476 01:45:22,400 --> 01:45:23,300 So this is what-- 2477 01:45:23,300 --> 01:45:26,930 I hate this song now, like 10 plus hours listening to this song on loop 2478 01:45:26,930 --> 01:45:28,160 just to get the timing right. 2479 01:45:28,160 --> 01:45:31,040 But it brings to life all of these different sprites. 2480 01:45:31,040 --> 01:45:34,130 And if you play it again and again, it's always a little bit different 2481 01:45:34,130 --> 01:45:35,600 because I'm using some randomness. 2482 01:45:35,600 --> 01:45:38,510 So this newspaper doesn't always fall from there. 2483 01:45:38,510 --> 01:45:39,650 Sometimes it's here. 2484 01:45:39,650 --> 01:45:40,680 Sometimes it's here. 2485 01:45:40,680 --> 01:45:42,920 And so here, again, we have mechanics of a game where 2486 01:45:42,920 --> 01:45:45,770 things are being perturbed a little, randomized a little bit 2487 01:45:45,770 --> 01:45:47,772 to keep things more interesting. 2488 01:45:47,772 --> 01:45:48,605 And let me go ahead. 2489 01:45:48,605 --> 01:45:50,240 OSCAR: (SINGS) I love trash. 2490 01:45:50,240 --> 01:45:51,407 DAVID J. MALAN: There we go. 2491 01:45:51,407 --> 01:45:53,420 How. about raise a little volume? 2492 01:45:53,420 --> 01:45:54,890 One more piece of trash. 2493 01:45:54,890 --> 01:45:55,490 So a clock. 2494 01:45:55,490 --> 01:45:57,600 It just goes on forever, this kind of game. 2495 01:45:57,600 --> 01:45:59,010 But let's go ahead and consider. 2496 01:45:59,010 --> 01:46:00,060 Let me close that. 2497 01:46:00,060 --> 01:46:01,610 Let me go ahead and consider. 2498 01:46:01,610 --> 01:46:04,770 How I went about implementing that from the get-go. 2499 01:46:04,770 --> 01:46:06,920 So I will stipulate-- 2500 01:46:06,920 --> 01:46:11,090 let me open a few of these versions here-- that the very first thing I did 2501 01:46:11,090 --> 01:46:13,070 was pretty much just implement the stage. 2502 01:46:13,070 --> 01:46:13,220 Right? 2503 01:46:13,220 --> 01:46:15,262 I was kind of procrastinating, so I poked around. 2504 01:46:15,262 --> 01:46:18,390 I found the Sesame Street lamppost, and I dragged it into the world. 2505 01:46:18,390 --> 01:46:18,890 And done. 2506 01:46:18,890 --> 01:46:19,820 Version one is done. 2507 01:46:19,820 --> 01:46:23,510 It didn't do anything, but at least I had the world sort of laid out. 2508 01:46:23,510 --> 01:46:25,820 That is to say I took a baby step toward my goal. 2509 01:46:25,820 --> 01:46:27,528 Then I started thinking about, all right, 2510 01:46:27,528 --> 01:46:31,620 how do I bring the trash to life, even if it doesn't do much of anything else? 2511 01:46:31,620 --> 01:46:34,370 And so I created another sprite by clicking the appropriate button 2512 01:46:34,370 --> 01:46:35,840 in that bottom right-hand corner. 2513 01:46:35,840 --> 01:46:38,420 And I thought about, well, what do I want this trash to do? 2514 01:46:38,420 --> 01:46:40,860 I want it to just kind of fall from the sky. 2515 01:46:40,860 --> 01:46:44,690 And so what I did here was the following. 2516 01:46:44,690 --> 01:46:48,020 If I go to this trash piece here or-- actually, sorry. 2517 01:46:48,020 --> 01:46:48,780 Out of order. 2518 01:46:48,780 --> 01:46:51,860 What I actually did first was I didn't even have the trash fall. 2519 01:46:51,860 --> 01:46:55,280 If I play this game, the trash just stays there in the air. 2520 01:46:55,280 --> 01:46:57,480 But I can do this. 2521 01:46:57,480 --> 01:47:01,370 I can drag it, and as before, as I touch the other sprite, 2522 01:47:01,370 --> 01:47:03,090 I get the trash can lid to go up. 2523 01:47:03,090 --> 01:47:04,080 So how do I do that? 2524 01:47:04,080 --> 01:47:07,130 Well, let me click on Oscar down there, my first sprite. 2525 01:47:07,130 --> 01:47:10,580 And here are the puzzle pieces via which I implemented this idea. 2526 01:47:10,580 --> 01:47:13,340 I changed Oscar's costume, his appearance, 2527 01:47:13,340 --> 01:47:17,960 to be just number one, which was one of the images I imported into the program. 2528 01:47:17,960 --> 01:47:19,820 And then I forever did this. 2529 01:47:19,820 --> 01:47:22,460 If Oscar is touching the mouse pointer, then 2530 01:47:22,460 --> 01:47:26,390 change Oscar's costume to number two, otherwise change it back to one. 2531 01:47:26,390 --> 01:47:28,190 So it's super simple animation. 2532 01:47:28,190 --> 01:47:31,970 I'm just toggling between lid up, lid down, lid up, lid down, 2533 01:47:31,970 --> 01:47:33,710 but it kind of feels interactive. 2534 01:47:33,710 --> 01:47:35,810 And if I wanted to really make this pretty, 2535 01:47:35,810 --> 01:47:40,580 I could have 30 different costumes where the lid is ever so slightly higher. 2536 01:47:40,580 --> 01:47:44,120 Then it would look even more like a movie or fluid motion. 2537 01:47:44,120 --> 01:47:46,640 But this was enough to get the job done, which 2538 01:47:46,640 --> 01:47:49,700 is to say I didn't try to implement all of "Oscartime" together. 2539 01:47:49,700 --> 01:47:52,490 I just took a second baby step toward my goal. 2540 01:47:52,490 --> 01:47:54,950 And then my next version of "Oscartime" might 2541 01:47:54,950 --> 01:47:57,675 have looked a little something like this, where now the trash-- 2542 01:47:57,675 --> 01:47:58,800 there's more going on here. 2543 01:47:58,800 --> 01:48:02,300 Let's look at two of these blocks of code. 2544 01:48:02,300 --> 01:48:04,972 The first thing I did was I enabled drag mode to draggable, 2545 01:48:04,972 --> 01:48:07,430 and I had to Google to figure this out because otherwise it 2546 01:48:07,430 --> 01:48:09,890 didn't let me drag the trash while playing the game. 2547 01:48:09,890 --> 01:48:12,800 But once I figured that out, I tell the trash 2548 01:48:12,800 --> 01:48:16,700 to go to a random x-coordinate between 0 and 240 2549 01:48:16,700 --> 01:48:19,670 from left to right and then the y location 180 2550 01:48:19,670 --> 01:48:22,070 because I always want the trash falling from the sky. 2551 01:48:22,070 --> 01:48:23,270 And then what do I do? 2552 01:48:23,270 --> 01:48:27,530 I told the trash to forever change its y-coordinate, its vertical coordinate, 2553 01:48:27,530 --> 01:48:30,740 by negative 1, negative 1, negative 1, one pixel 2554 01:48:30,740 --> 01:48:34,190 at a time, which creates the illusion of it falling from the sky. 2555 01:48:34,190 --> 01:48:36,950 But I needed to do one other thing, and let me scroll up. 2556 01:48:36,950 --> 01:48:41,360 Each of your sprites can have multiple programs, multiple scripts, 2557 01:48:41,360 --> 01:48:44,070 so to speak, that are not attached to one another. 2558 01:48:44,070 --> 01:48:46,050 They will happen in parallel for you. 2559 01:48:46,050 --> 01:48:47,750 The second one is saying this. 2560 01:48:47,750 --> 01:48:52,850 Forever if the trash is touching Oscar, what should it do? 2561 01:48:52,850 --> 01:48:57,440 Go to a completely different x and y location at the very top. 2562 01:48:57,440 --> 01:48:57,950 Why? 2563 01:48:57,950 --> 01:49:01,010 Well, as soon as I drag the trash over the Oscar, 2564 01:49:01,010 --> 01:49:03,530 I want it to disappear as though it's going into the can. 2565 01:49:03,530 --> 01:49:06,830 And I then want it to reappear at the top so more trash falls. 2566 01:49:06,830 --> 01:49:08,840 So I just thought about what would it mean 2567 01:49:08,840 --> 01:49:10,910 for the trash to go into the trash can. 2568 01:49:10,910 --> 01:49:11,870 Well, who cares? 2569 01:49:11,870 --> 01:49:14,210 What really matters to the human user is that it just 2570 01:49:14,210 --> 01:49:16,980 disappears and teleports elsewhere. 2571 01:49:16,980 --> 01:49:19,620 And so that's the idea I implemented here. 2572 01:49:19,620 --> 01:49:24,960 So if you can reduce intuitive ideas to just basic building blocks like this, 2573 01:49:24,960 --> 01:49:27,440 you can start to make things much more interactive. 2574 01:49:27,440 --> 01:49:29,970 And lastly, if I look at this version here, 2575 01:49:29,970 --> 01:49:33,050 you'll see that we've combined these. 2576 01:49:33,050 --> 01:49:35,930 And so indeed, if I actually go ahead and play this now, 2577 01:49:35,930 --> 01:49:37,790 not only is it falling. 2578 01:49:37,790 --> 01:49:41,090 I can let it fall right on top of Oscar and watch it disappear. 2579 01:49:41,090 --> 01:49:44,795 But notice Oscar doesn't pop out yet because that was the fourth version 2580 01:49:44,795 --> 01:49:45,920 and then the fifth version. 2581 01:49:45,920 --> 01:49:48,650 And then I added the annoying music and so forth but sort of 2582 01:49:48,650 --> 01:49:51,600 composed this program step by step by step 2583 01:49:51,600 --> 01:49:53,193 so as to accomplish my larger goal. 2584 01:49:53,193 --> 01:49:55,610 And this is going to be true of all of the code you write, 2585 01:49:55,610 --> 01:50:00,980 be it in Scratch, or C, or Python, or in the like, trying to come up with-- 2586 01:50:00,980 --> 01:50:05,360 or rather, trying to reduce your ideas, your grand vision to just baby steps, 2587 01:50:05,360 --> 01:50:07,670 building blocks so that you start with version one, 2588 01:50:07,670 --> 01:50:10,010 and maybe you submit version 10 or 20. 2589 01:50:10,010 --> 01:50:13,190 But you don't try to implement version 10 or 20 at the get-go. 2590 01:50:13,190 --> 01:50:15,780 You take those incremental steps. 2591 01:50:15,780 --> 01:50:16,280 All right. 2592 01:50:16,280 --> 01:50:17,270 How about one other? 2593 01:50:17,270 --> 01:50:19,550 Well, let me propose this. 2594 01:50:19,550 --> 01:50:23,370 Let me go ahead and open three games that represent one 2595 01:50:23,370 --> 01:50:27,570 that your predecessors also implemented, which looks a little something 2596 01:50:27,570 --> 01:50:29,220 like this in version zero. 2597 01:50:29,220 --> 01:50:32,220 Suppose I wanted to implement a game that 2598 01:50:32,220 --> 01:50:33,900 simply has these kinds of mechanics. 2599 01:50:33,900 --> 01:50:37,050 I'm touching my arrow keys on my keyboard-- up, down, left, and right. 2600 01:50:37,050 --> 01:50:38,460 And I'm moving the Harvard logo. 2601 01:50:38,460 --> 01:50:39,610 Let me zoom in a bit. 2602 01:50:39,610 --> 01:50:42,210 So if I hit the up arrow, the Harvard shield goes up. 2603 01:50:42,210 --> 01:50:44,760 If I hit the down arrow, the shield goes down. 2604 01:50:44,760 --> 01:50:47,070 If I go all the way to the left, it goes left 2605 01:50:47,070 --> 01:50:49,548 until it hits the wall and same thing on the right. 2606 01:50:49,548 --> 01:50:51,840 So this is like the beginnings of a game or a beginning 2607 01:50:51,840 --> 01:50:53,370 of a maze, something like that. 2608 01:50:53,370 --> 01:50:55,150 Well, how might I implement this? 2609 01:50:55,150 --> 01:50:57,210 Well, let me look inside this one. 2610 01:50:57,210 --> 01:51:01,020 And there's a lot going on, but, again, I sort of took simple steps. 2611 01:51:01,020 --> 01:51:02,730 Notice that I've got three sprites-- 2612 01:51:02,730 --> 01:51:04,920 a left wall, which is just a straight line, 2613 01:51:04,920 --> 01:51:07,140 the right wall, which is a straight line. 2614 01:51:07,140 --> 01:51:10,710 And just intuitively, why did I implement those as sprites? 2615 01:51:10,710 --> 01:51:15,240 Why do they need to exist as entities themselves? 2616 01:51:15,240 --> 01:51:16,230 Yeah, in front. 2617 01:51:16,230 --> 01:51:16,530 AUDIENCE: [INAUDIBLE] 2618 01:51:16,530 --> 01:51:17,405 DAVID J. MALAN: Yeah. 2619 01:51:17,405 --> 01:51:19,033 I want it to interact with the shield. 2620 01:51:19,033 --> 01:51:21,450 So I need to be able to ask that Boolean expression, like, 2621 01:51:21,450 --> 01:51:24,940 not touching mouse pointer but touching shield, for instance, 2622 01:51:24,940 --> 01:51:26,560 a different type of yes/no question. 2623 01:51:26,560 --> 01:51:29,130 And so what is the code for the shield actually doing? 2624 01:51:29,130 --> 01:51:32,850 Well, there's a lot of duplication, and let me focus on the abstraction first. 2625 01:51:32,850 --> 01:51:35,680 Notice that I've got this one green flag clicked. 2626 01:51:35,680 --> 01:51:38,430 I want the shield to go dead center, 0 comma 0, 2627 01:51:38,430 --> 01:51:42,600 and then forever listen for the human's keyboard, and feel for the wall. 2628 01:51:42,600 --> 01:51:45,815 So I decided to implement my own pink puzzle pieces that 2629 01:51:45,815 --> 01:51:47,190 implement the two separate ideas. 2630 01:51:47,190 --> 01:51:49,450 One, just listen for the keyboard-- up, down, left, 2631 01:51:49,450 --> 01:51:50,700 right-- and then do something. 2632 01:51:50,700 --> 01:51:53,770 And then feel for walls is this idea of whenever I go up, 2633 01:51:53,770 --> 01:51:56,550 down, left, or right, if I touch a wall, I 2634 01:51:56,550 --> 01:52:00,600 need to stop doing whatever the keystrokes are telling me to do. 2635 01:52:00,600 --> 01:52:05,580 So now if we dive into those implementation details, listen and feel 2636 01:52:05,580 --> 01:52:07,930 are abstractions, custom puzzle pieces. 2637 01:52:07,930 --> 01:52:09,870 Let's look at the implementation details. 2638 01:52:09,870 --> 01:52:11,220 Well, here's the keyboard. 2639 01:52:11,220 --> 01:52:15,840 If the key arrow up is pressed, change y by 1. 2640 01:52:15,840 --> 01:52:19,495 If key down arrow is pressed, change y by negative 1. 2641 01:52:19,495 --> 01:52:21,370 And you can probably see where this is going. 2642 01:52:21,370 --> 01:52:23,310 Right arrow is x by 1. 2643 01:52:23,310 --> 01:52:25,920 Left arrow is x by negative 1, and that's 2644 01:52:25,920 --> 01:52:29,050 sort of all that's involved with up, down, left, right. 2645 01:52:29,050 --> 01:52:30,030 But wait a minute. 2646 01:52:30,030 --> 01:52:35,910 Why is there no loop in this listen for keyboard puzzle piece? 2647 01:52:35,910 --> 01:52:39,240 I needed a loop last time so it constantly works. 2648 01:52:39,240 --> 01:52:40,770 AUDIENCE: [INAUDIBLE] 2649 01:52:40,770 --> 01:52:41,770 DAVID J. MALAN: Exactly. 2650 01:52:41,770 --> 01:52:44,350 I put the loop in my main part of my program 2651 01:52:44,350 --> 01:52:48,020 up top so something is telling me to keep listening again and again. 2652 01:52:48,020 --> 01:52:50,020 So it's got to be somewhere, but it doesn't have 2653 01:52:50,020 --> 01:52:51,760 to be in the actual implementation. 2654 01:52:51,760 --> 01:52:53,950 And lastly, how about this feel for walls? 2655 01:52:53,950 --> 01:52:58,420 Well, if touching left wall, which is just another sprite, change x by 1. 2656 01:52:58,420 --> 01:53:00,880 So that is to say if I'm touching the left wall, 2657 01:53:00,880 --> 01:53:03,465 I want to bounce it back the other direction 2658 01:53:03,465 --> 01:53:04,840 and same thing on the right wall. 2659 01:53:04,840 --> 01:53:06,580 If I'm touching the right wall, I want to bounce it 2660 01:53:06,580 --> 01:53:09,670 back to the left, which effectively means that even if the human's hitting 2661 01:53:09,670 --> 01:53:11,680 the key, it's like fighting with this code, 2662 01:53:11,680 --> 01:53:14,890 but it's never going to go through the wall based on that math. 2663 01:53:14,890 --> 01:53:16,760 It's going to stop it right there. 2664 01:53:16,760 --> 01:53:17,260 All right. 2665 01:53:17,260 --> 01:53:18,760 Let's add something else to the mix. 2666 01:53:18,760 --> 01:53:21,640 Suppose I want the game to change to be a little something like this, 2667 01:53:21,640 --> 01:53:25,300 where Yale is some kind of block in between me and the exit. 2668 01:53:25,300 --> 01:53:27,140 So some dramatic race here. 2669 01:53:27,140 --> 01:53:27,640 OK. 2670 01:53:27,640 --> 01:53:30,100 I just got by, but the Yale logo doesn't seem 2671 01:53:30,100 --> 01:53:32,200 to be doing all that much except bouncing. 2672 01:53:32,200 --> 01:53:35,660 So I'm guessing there's a loop, maybe a conditional checking for those walls 2673 01:53:35,660 --> 01:53:36,160 too. 2674 01:53:36,160 --> 01:53:38,823 So let's go ahead and zoom out, see inside. 2675 01:53:38,823 --> 01:53:41,490 Let's not worry about Harvard because it's pretty much the same. 2676 01:53:41,490 --> 01:53:43,520 Let's look at the Yale puzzle pieces. 2677 01:53:43,520 --> 01:53:45,710 And sure enough, go to the middle. 2678 01:53:45,710 --> 01:53:46,880 0 comma zero. 2679 01:53:46,880 --> 01:53:50,930 Point in direction 90, so point horizontally on the grid. 2680 01:53:50,930 --> 01:53:53,870 And then if touching left wall or touching right wall-- 2681 01:53:53,870 --> 01:53:58,470 I'm kind of cheating this time, but cleverly, just spin around and do 180 2682 01:53:58,470 --> 01:54:00,198 so you effectively bounce off the wall. 2683 01:54:00,198 --> 01:54:01,490 This just tightened up my code. 2684 01:54:01,490 --> 01:54:03,490 I don't need to do the negative 1 or the plus 1. 2685 01:54:03,490 --> 01:54:07,010 I just say bounce in this form of code, otherwise just 2686 01:54:07,010 --> 01:54:08,420 constantly move one step. 2687 01:54:08,420 --> 01:54:12,080 Now, if this is a game where Yale is supposed to be better and faster, 2688 01:54:12,080 --> 01:54:13,520 well, let's change the 1 to 5. 2689 01:54:13,520 --> 01:54:15,300 Move 5 pixels at a time. 2690 01:54:15,300 --> 01:54:17,610 Let's move it 10 back and forth. 2691 01:54:17,610 --> 01:54:19,040 Let's maybe 100. 2692 01:54:19,040 --> 01:54:20,150 Uh-oh. 2693 01:54:20,150 --> 01:54:21,380 So what just happened? 2694 01:54:21,380 --> 01:54:25,310 That is a bug, which we can avoid by just not doing that. 2695 01:54:25,310 --> 01:54:27,310 But why did it break out of the wall? 2696 01:54:27,310 --> 01:54:28,310 Yeah. 2697 01:54:28,310 --> 01:54:29,600 AUDIENCE: [INAUDIBLE]. 2698 01:54:29,600 --> 01:54:30,890 At first it was [INAUDIBLE]. 2699 01:54:30,890 --> 01:54:31,890 DAVID J. MALAN: Exactly. 2700 01:54:31,890 --> 01:54:34,010 Because I'm doing 100 steps at a time, I'm 2701 01:54:34,010 --> 01:54:36,200 never actually touching the other sprite because I'm 2702 01:54:36,200 --> 01:54:38,060 sort of stepping way over it. 2703 01:54:38,060 --> 01:54:40,610 So there's never a moment where they're actually touching. 2704 01:54:40,610 --> 01:54:44,630 So previously, I was just getting lucky by doing fewer steps because it's 2705 01:54:44,630 --> 01:54:46,700 gradually going over the wall, which gives me 2706 01:54:46,700 --> 01:54:48,557 just enough time to detect as much. 2707 01:54:48,557 --> 01:54:50,390 So I would have to kind of tinker, and he'll 2708 01:54:50,390 --> 01:54:51,932 handle this a little bit differently. 2709 01:54:51,932 --> 01:54:53,790 So it's a bug if it's too fast. 2710 01:54:53,790 --> 01:54:55,730 But at least if I keep it slow and reasonable 2711 01:54:55,730 --> 01:54:59,870 the math actually does work out, so long as it starts again in the middle. 2712 01:54:59,870 --> 01:55:04,200 Well, let's do one final flourish here, whereby let's bring MIT into the mix. 2713 01:55:04,200 --> 01:55:04,700 Right? 2714 01:55:04,700 --> 01:55:06,770 They're super smart, so maybe they can kind of 2715 01:55:06,770 --> 01:55:11,390 track us and follow wherever I'm going. 2716 01:55:11,390 --> 01:55:13,140 So how might this work? 2717 01:55:13,140 --> 01:55:13,640 All right. 2718 01:55:13,640 --> 01:55:16,580 So nothing happens yet because we haven't finished composing the game. 2719 01:55:16,580 --> 01:55:17,490 And notice here-- 2720 01:55:17,490 --> 01:55:17,990 OK. 2721 01:55:17,990 --> 01:55:19,063 Now MIT is struggling. 2722 01:55:19,063 --> 01:55:21,980 It's kind of twitching there because it's going just above, and below, 2723 01:55:21,980 --> 01:55:23,100 and then above, and below. 2724 01:55:23,100 --> 01:55:24,840 So we could fix that too if we want. 2725 01:55:24,840 --> 01:55:28,080 But that's just a function of my math, one pixel at a time. 2726 01:55:28,080 --> 01:55:33,570 Let me open up this one, see inside, and click on MIT. 2727 01:55:33,570 --> 01:55:37,110 And it doesn't take much to implement MIT, it seems. 2728 01:55:37,110 --> 01:55:43,200 So go to random position, forever point towards the Harvard logo outline, 2729 01:55:43,200 --> 01:55:46,330 AKA the shield, and then move one step. 2730 01:55:46,330 --> 01:55:50,705 So if I wanted to make MIT even smarter, even faster, what do I change here? 2731 01:55:50,705 --> 01:55:51,580 AUDIENCE: [INAUDIBLE] 2732 01:55:51,580 --> 01:55:52,455 DAVID J. MALAN: Yeah. 2733 01:55:52,455 --> 01:55:56,070 Change one step to two steps to double their speed or five steps, 10 steps, 2734 01:55:56,070 --> 01:55:56,612 or 100 steps. 2735 01:55:56,612 --> 01:55:58,403 And the game is going to be over like that. 2736 01:55:58,403 --> 01:56:00,940 But that's all it takes to now make these kinds of elements. 2737 01:56:00,940 --> 01:56:03,330 So if you are a game player on your phone, or consoles, 2738 01:56:03,330 --> 01:56:06,120 or computer, or whatever, if you think about almost any game, 2739 01:56:06,120 --> 01:56:08,910 you can probably now start to think about how they implemented 2740 01:56:08,910 --> 01:56:12,210 those mechanics because it's just being reduced to functions, conditionals, 2741 01:56:12,210 --> 01:56:15,640 loops, variables, and the like in this case. 2742 01:56:15,640 --> 01:56:20,560 So let's go ahead here and have maybe one final volunteer. 2743 01:56:20,560 --> 01:56:22,480 We've got one more bag of Oreos here. 2744 01:56:22,480 --> 01:56:22,980 OK. 2745 01:56:22,980 --> 01:56:23,640 That was super fast. 2746 01:56:23,640 --> 01:56:24,750 Do you want to come on up? 2747 01:56:24,750 --> 01:56:25,250 All right. 2748 01:56:25,250 --> 01:56:25,920 Brave volunteer. 2749 01:56:25,920 --> 01:56:26,820 Come on up. 2750 01:56:26,820 --> 01:56:30,271 [APPLAUSE] 2751 01:56:30,271 --> 01:56:31,180 2752 01:56:31,180 --> 01:56:31,680 All right. 2753 01:56:31,680 --> 01:56:36,720 Let me find the full-fledged version of this that one of your predecessors 2754 01:56:36,720 --> 01:56:37,650 made. 2755 01:56:37,650 --> 01:56:40,490 And let me get the right one. 2756 01:56:40,490 --> 01:56:40,990 OK. 2757 01:56:40,990 --> 01:56:41,740 Here we go. 2758 01:56:41,740 --> 01:56:45,030 We'll see some instructions on the screen in just a moment. 2759 01:56:45,030 --> 01:56:50,460 And when we hit Play, you'll see that the mechanics are all combined now 2760 01:56:50,460 --> 01:56:51,630 into one full-fledged game. 2761 01:56:51,630 --> 01:56:54,740 But first, an introduction. 2762 01:56:54,740 --> 01:56:55,890 It's on. 2763 01:56:55,890 --> 01:56:56,750 SAM: Hi, everyone. 2764 01:56:56,750 --> 01:56:57,780 I'm Sam. 2765 01:56:57,780 --> 01:56:58,830 I live in [INAUDIBLE]. 2766 01:56:58,830 --> 01:57:00,657 I'm a freshman, and I'm from Nepal. 2767 01:57:00,657 --> 01:57:01,740 DAVID J. MALAN: All right. 2768 01:57:01,740 --> 01:57:02,655 Welcome to the stage. 2769 01:57:02,655 --> 01:57:03,155 [APPLAUSE] 2770 01:57:03,155 --> 01:57:04,287 SAM: Thank you. 2771 01:57:04,287 --> 01:57:05,370 DAVID J. MALAN: All right. 2772 01:57:05,370 --> 01:57:05,980 So here we go. 2773 01:57:05,980 --> 01:57:06,480 Yep. 2774 01:57:06,480 --> 01:57:08,010 Go ahead and click the green flag. 2775 01:57:08,010 --> 01:57:10,435 [MUSIC PLAYING] 2776 01:57:10,435 --> 01:57:14,010 [MC HAMMER, "U CAN'T TOUCH THIS"] You can't touch this. 2777 01:57:14,010 --> 01:57:17,982 DAVID J. MALAN: You see the grid is just bigger this time. 2778 01:57:17,982 --> 01:57:19,395 (SINGING) You can't touch this. 2779 01:57:19,395 --> 01:57:20,270 DAVID J. MALAN: Nice. 2780 01:57:20,270 --> 01:57:22,227 Now there's that Yale element. 2781 01:57:22,227 --> 01:57:24,080 (SINGING) You can't touch this. 2782 01:57:24,080 --> 01:57:27,770 My, my, my my music hits me so hard. 2783 01:57:27,770 --> 01:57:29,570 Makes me say, oh, my Lord. 2784 01:57:29,570 --> 01:57:32,518 Thank you for blessing me with a mind to rhyme and two hyped feet. 2785 01:57:32,518 --> 01:57:35,810 It feels good when you know you're down, a super dope homeboy from the Oaktown. 2786 01:57:35,810 --> 01:57:36,602 DAVID J. MALAN: OK. 2787 01:57:36,602 --> 01:57:38,810 Third Yale. 2788 01:57:38,810 --> 01:57:41,480 All started at slightly different positions. 2789 01:57:41,480 --> 01:57:43,035 (SINGING) I told you, homeboy. 2790 01:57:43,035 --> 01:57:43,910 You can't touch this. 2791 01:57:43,910 --> 01:57:44,660 DAVID J. MALAN: Nice. 2792 01:57:44,660 --> 01:57:45,160 All right. 2793 01:57:45,160 --> 01:57:45,830 There's MIT. 2794 01:57:45,830 --> 01:57:47,780 (SINGING) And ya know you can't touch this. 2795 01:57:47,780 --> 01:57:49,139 [CHEERING, APPLAUSE] 2796 01:57:49,139 --> 01:57:50,500 DAVID J. MALAN: Oh. 2797 01:57:50,500 --> 01:57:52,520 (SINGING) You can't touch this. 2798 01:57:52,520 --> 01:57:53,020 Yo. 2799 01:57:53,020 --> 01:57:54,245 Let me bust the funky lyrics. 2800 01:57:54,245 --> 01:57:55,495 DAVID J. MALAN: Gotta go fast. 2801 01:57:55,495 --> 01:57:58,000 2802 01:57:58,000 --> 01:57:59,930 Oh. 2803 01:57:59,930 --> 01:58:00,430 No. 2804 01:58:00,430 --> 01:58:05,030 2805 01:58:05,030 --> 01:58:07,090 Oh. 2806 01:58:07,090 --> 01:58:07,590 [CHUCKLES] 2807 01:58:07,590 --> 01:58:09,465 (SINGING) Cold on a mission, so fall on back. 2808 01:58:09,465 --> 01:58:13,690 Let them know that you're too much, and this is a beat they can't touch. 2809 01:58:13,690 --> 01:58:14,590 DAVID J. MALAN: Nice. 2810 01:58:14,590 --> 01:58:15,970 [EXCLAIMING] 2811 01:58:15,970 --> 01:58:18,270 (SINGING) You can't touch this. 2812 01:58:18,270 --> 01:58:20,482 DAVID J. MALAN: No more walls but two MITs. 2813 01:58:20,482 --> 01:58:21,690 (SINGING) Yo, sound the bell. 2814 01:58:21,690 --> 01:58:22,765 School's in, sucker. 2815 01:58:22,765 --> 01:58:24,015 DAVID J. MALAN: Princeton now. 2816 01:58:24,015 --> 01:58:25,612 (SINGING) Give me a song or rhythm. 2817 01:58:25,612 --> 01:58:27,570 Making them sweat, that's what I'm giving them. 2818 01:58:27,570 --> 01:58:31,140 Now, they know you talk about the Hammer when you're talkin' 2819 01:58:31,140 --> 01:58:32,670 'bout a show that's hyped and tight. 2820 01:58:32,670 --> 01:58:36,463 Singers are sweatin', so pass them a wipe or a tape to learn. 2821 01:58:36,463 --> 01:58:38,005 DAVID J. MALAN: Second to last level. 2822 01:58:38,005 --> 01:58:39,800 (SINGING) The chart's legit. 2823 01:58:39,800 --> 01:58:41,980 Either work hard, or you might as well quit. 2824 01:58:41,980 --> 01:58:45,540 That's word because you know you can't touch this. 2825 01:58:45,540 --> 01:58:48,265 2826 01:58:48,265 --> 01:58:49,140 You can't touch this. 2827 01:58:49,140 --> 01:58:51,870 2828 01:58:51,870 --> 01:58:52,600 Break it down. 2829 01:58:52,600 --> 01:58:53,683 DAVID J. MALAN: All right. 2830 01:58:53,683 --> 01:58:54,660 Clear. 2831 01:58:54,660 --> 01:58:55,160 There we go. 2832 01:58:55,160 --> 01:58:55,660 Nice. 2833 01:58:55,660 --> 01:58:56,310 Oh, oh. 2834 01:58:56,310 --> 01:58:59,565 2835 01:58:59,565 --> 01:59:00,960 Oh. 2836 01:59:00,960 --> 01:59:02,814 Few more lives. 2837 01:59:02,814 --> 01:59:05,590 Oh. 2838 01:59:05,590 --> 01:59:06,280 (SINGING) Stop. 2839 01:59:06,280 --> 01:59:06,700 Hammer time. 2840 01:59:06,700 --> 01:59:07,130 DAVID J. MALAN: Here we go. 2841 01:59:07,130 --> 01:59:08,110 There we go. 2842 01:59:08,110 --> 01:59:09,690 [EXCLAIMING] 2843 01:59:09,690 --> 01:59:10,190 All right. 2844 01:59:10,190 --> 01:59:12,220 Couple more tries. 2845 01:59:12,220 --> 01:59:13,260 Yes! 2846 01:59:13,260 --> 01:59:14,345 Oh, no. 2847 01:59:14,345 --> 01:59:15,997 (SINGING) This is it for a winner. 2848 01:59:15,997 --> 01:59:17,830 Dance to this, and you're gonna get thinner. 2849 01:59:17,830 --> 01:59:19,480 Now move, slide your rump. 2850 01:59:19,480 --> 01:59:20,080 DAVID J. MALAN: Starts getting stressful. 2851 01:59:20,080 --> 01:59:22,210 (SINGING) Just for a minute, let's all do the bump. 2852 01:59:22,210 --> 01:59:23,140 Bump, bump, bump. 2853 01:59:23,140 --> 01:59:24,310 Yeah. 2854 01:59:24,310 --> 01:59:27,020 You can't touch this. 2855 01:59:27,020 --> 01:59:27,890 Look, man. 2856 01:59:27,890 --> 01:59:29,358 You can't touch this. 2857 01:59:29,358 --> 01:59:30,650 You'll probably get hyped, boy. 2858 01:59:30,650 --> 01:59:31,620 DAVID J. MALAN: One more try. 2859 01:59:31,620 --> 01:59:33,087 (SINGING) You can't touch this. 2860 01:59:33,087 --> 01:59:33,670 Ring the bell. 2861 01:59:33,670 --> 01:59:34,840 School's back in. 2862 01:59:34,840 --> 01:59:35,140 DAVID J. MALAN: All right. 2863 01:59:35,140 --> 01:59:36,515 A round of applause, nonetheless. 2864 01:59:36,515 --> 01:59:37,420 [APPLAUSE] 2865 01:59:37,420 --> 01:59:38,360 Nicely done. 2866 01:59:38,360 --> 01:59:39,280 Thank you. 2867 01:59:39,280 --> 01:59:42,500 2868 01:59:42,500 --> 01:59:46,660 So as you might have noticed if your eyes started 2869 01:59:46,660 --> 01:59:48,410 to wander to the light bulbs here, there's 2870 01:59:48,410 --> 01:59:50,570 actually 64 of these light bulbs. 2871 01:59:50,570 --> 01:59:55,062 And I'm wondering if you divide 64 by 8, that's 8 bytes of light bulbs. 2872 01:59:55,062 --> 01:59:57,020 And we now have some Unicode in our vocabulary. 2873 01:59:57,020 --> 01:59:58,970 So might very well be the case that we've 2874 01:59:58,970 --> 02:00:03,360 been spelling something out on the stage here for you all of this time. 2875 02:00:03,360 --> 02:00:07,190 But before we adjourn for cake to be served in the Transept, 2876 02:00:07,190 --> 02:00:11,930 allow me to introduce some of CS50's human friends, 2877 02:00:11,930 --> 02:00:17,210 the Harvard Krokodiloes and the Radcliffe Pitches, 2878 02:00:17,210 --> 02:00:23,148 to give us this exciting ending, "This is CS50." 2879 02:00:23,148 --> 02:00:26,606 [APPLAUSE, CHEERING] 2880 02:00:26,606 --> 02:00:36,980 2881 02:00:36,980 --> 02:00:38,462 [HARMONICA NOTE] 2882 02:00:38,462 --> 02:00:41,420 2883 02:00:41,420 --> 02:00:41,920 [VOCALIZING] 2884 02:00:41,920 --> 02:00:50,820 SPEAKER: (SINGING) There's a certain someone who I'm indebted to. 2885 02:00:50,820 --> 02:01:00,080 And since the old [? BNC ?] has 50, I have this friend for you. 2886 02:01:00,080 --> 02:01:03,090 2887 02:01:03,090 --> 02:01:04,300 A two, three, four. 2888 02:01:04,300 --> 02:01:08,845 [VOCALIZING] 2889 02:01:08,845 --> 02:01:12,130 Oh, rubber ducky, you're the one. 2890 02:01:12,130 --> 02:01:14,770 You make [INAUDIBLE] so much fun. 2891 02:01:14,770 --> 02:01:18,400 Rubber ducky, I'm awfully fond of you. 2892 02:01:18,400 --> 02:01:25,030 [SCATTING] Rubber ducky, you make me smile, and you help my code compile. 2893 02:01:25,030 --> 02:01:27,100 Rubber ducky, you're my very best friend. 2894 02:01:27,100 --> 02:01:29,230 It's true. 2895 02:01:29,230 --> 02:01:33,760 When I'm at a standstill, your debugging abilities stun me. 2896 02:01:33,760 --> 02:01:40,330 When I'm at the end of my rope, you just snap, and my code's up and running. 2897 02:01:40,330 --> 02:01:45,160 Rubber ducky, you're so fine, and I'm lucky that you're mine. 2898 02:01:45,160 --> 02:01:47,320 Rubber ducky, you're my very best friend. 2899 02:01:47,320 --> 02:01:48,610 It's true. 2900 02:01:48,610 --> 02:01:49,910 You're my best friend. 2901 02:01:49,910 --> 02:01:52,750 It's true. 2902 02:01:52,750 --> 02:01:56,785 Rubber ducky, I'm awfully fond of you. 2903 02:01:56,785 --> 02:02:02,128 2904 02:02:02,128 --> 02:02:05,607 [CHEERING, APPLAUSE] 2905 02:02:05,607 --> 02:02:08,600 2906 02:02:08,600 --> 02:02:10,140 SPEAKER: Good afternoon, CS50. 2907 02:02:10,140 --> 02:02:12,890 We are the Harvard Krokodiloes, Harvard's oldest a cappella group, 2908 02:02:12,890 --> 02:02:16,160 founded way back in 1946 at the historic Hasty Pudding Club. 2909 02:02:16,160 --> 02:02:18,462 We'd love to make a big thank you to CS50 staff 2910 02:02:18,462 --> 02:02:21,170 and to David Malan for having us perform here at Sanders Theater. 2911 02:02:21,170 --> 02:02:24,800 And you enjoyed this performance, please come audition for us 2912 02:02:24,800 --> 02:02:26,856 this weekend at Farkas Hall. 2913 02:02:26,856 --> 02:02:30,328 [CHEERING, APPLAUSE] 2914 02:02:30,328 --> 02:02:36,280 2915 02:02:36,280 --> 02:02:37,730 SPEAKER: Hello, everyone. 2916 02:02:37,730 --> 02:02:40,000 We are some of the Radcliffe Pitches, and we are also 2917 02:02:40,000 --> 02:02:41,920 hosting auditions this weekend. 2918 02:02:41,920 --> 02:02:45,280 You can find more information at our Instagram, @radcliffepitches. 2919 02:02:45,280 --> 02:02:48,700 Now, let me tell you a little bit about just about a year ago 2920 02:02:48,700 --> 02:02:52,840 today, when I was sitting in your very seats on my first day of CS50 lecture. 2921 02:02:52,840 --> 02:02:55,700 And this is just about how I was feeling. 2922 02:02:55,700 --> 02:02:57,170 [HARMONICA NOTE] 2923 02:02:57,170 --> 02:03:00,110 2924 02:03:00,110 --> 02:03:03,540 [VOCALIZING] 2925 02:03:03,540 --> 02:03:07,410 2926 02:03:07,410 --> 02:03:11,700 (SINGING) It's the first day of class, and I'm brand new to code. 2927 02:03:11,700 --> 02:03:14,190 Is this for me? 2928 02:03:14,190 --> 02:03:16,200 So many people around. 2929 02:03:16,200 --> 02:03:18,750 Can I get through the workload? 2930 02:03:18,750 --> 02:03:21,660 But it's my dream. 2931 02:03:21,660 --> 02:03:25,260 I tend to stick to English, not science. 2932 02:03:25,260 --> 02:03:29,167 But my [INAUDIBLE] friends told me to try this. 2933 02:03:29,167 --> 02:03:32,250 Hey, dancing robot dog, you kind of look like you have your life together, 2934 02:03:32,250 --> 02:03:33,180 I guess. 2935 02:03:33,180 --> 02:03:35,697 I really need some advice. 2936 02:03:35,697 --> 02:03:37,530 (ALL SINGING) We know you're feeling unsure, 2937 02:03:37,530 --> 02:03:40,590 but this is really the right call. 2938 02:03:40,590 --> 02:03:44,760 In CS50, you'll meet new friends, get free food. 2939 02:03:44,760 --> 02:03:50,160 You'll be all set for this fall in CS50. 2940 02:03:50,160 --> 02:03:54,150 You have a thousand TAs who will help you. 2941 02:03:54,150 --> 02:03:58,190 You'll get cupcakes, duckies, Chinese food. 2942 02:03:58,190 --> 02:04:03,870 And you can always take this class and set aside. 2943 02:04:03,870 --> 02:04:06,880 2944 02:04:06,880 --> 02:04:08,680 SPEAKER: This is CS50. 2945 02:04:08,680 --> 02:04:10,828 Fist bump. 2946 02:04:10,828 --> 02:04:11,800 [LAUGHTER] 2947 02:04:11,800 --> 02:04:15,202 [APPLAUSE, CHEERING] 2948 02:04:15,202 --> 02:04:16,645 2949 02:04:16,645 --> 02:04:18,270 DAVID J. MALAN: Thank you to the Kroks. 2950 02:04:18,270 --> 02:04:19,380 Thank you to the Pitches. 2951 02:04:19,380 --> 02:04:20,370 Cake is now served. 2952 02:04:20,370 --> 02:04:23,490 Come on up to say hi if you'd like or meet Spot. 2953 02:04:23,490 --> 02:04:24,330 See you next time. 2954 02:04:24,330 --> 02:04:25,163 [APPLAUSE, CHEERING] 2955 02:04:25,163 --> 02:04:28,280 [MUSIC PLAYING] 2956 02:04:28,280 --> 02:04:54,000 233166

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.