1 00:00:14,320 --> 00:00:17,970 So it is my greatest pleasure to welcome you all here today 2 00:00:17,970 --> 00:00:20,600 for the first lecture of, well, Introduction 3 00:00:20,600 --> 00:00:22,510 to Computing and Programming. 4 00:00:22,510 --> 00:00:29,110 Also known as CS50 or well, CPSC 100, officially here at Yale. 5 00:00:29,110 --> 00:00:34,820 >> So we couldn't be more excited to welcome you all here. 6 00:00:34,820 --> 00:00:36,620 My name is Patrick Rebeschini. 7 00:00:36,620 --> 00:00:39,180 I'm the head instructor for the class. 8 00:00:39,180 --> 00:00:43,600 I am here representing a group of about 60 staff members 9 00:00:43,600 --> 00:00:46,380 that will work with you throughout the semester. 10 00:00:46,380 --> 00:00:49,040 This number is almost 60 of us. 11 00:00:49,040 --> 00:00:52,440 Yet along the extraordinary level of commitments 12 00:00:52,440 --> 00:00:56,555 that we put into this class, makes CS50 the class 13 00:00:56,555 --> 00:01:00,690 at Yale University that offers the greatest level of support 14 00:01:00,690 --> 00:01:01,960 to all of you. 15 00:01:01,960 --> 00:01:05,940 And we couldn't be more proud of offering this class here again. 16 00:01:05,940 --> 00:01:11,380 >> In fact, as you will soon experience, CS50 is much more than a class. 17 00:01:11,380 --> 00:01:13,120 It's a community. 18 00:01:13,120 --> 00:01:15,250 And you will be part soon of this community. 19 00:01:15,250 --> 00:01:18,730 This is the second year that Yale is offering this class. 20 00:01:18,730 --> 00:01:21,640 We are building on the extreme success of last year, where 21 00:01:21,640 --> 00:01:24,340 for the first time, here at this university, 22 00:01:24,340 --> 00:01:28,930 undergraduate learning assistant were adopted in classrooms. 23 00:01:28,930 --> 00:01:32,650 It all started with this class last year. 24 00:01:32,650 --> 00:01:37,050 >> So as you know, the class is taught jointly with Harvard University. 25 00:01:37,050 --> 00:01:39,920 To teach this course we are relying-- we can 26 00:01:39,920 --> 00:01:44,850 count on the great expertise of David Malan and the Harvard team. 27 00:01:44,850 --> 00:01:48,930 So David has been teaching CS50 for well, 10 years now. 28 00:01:48,930 --> 00:01:51,160 And every year he has been pushing the boundaries 29 00:01:51,160 --> 00:01:54,210 and improving the classroom experience. 30 00:01:54,210 --> 00:01:58,940 Again, we couldn't be more happy to continue this collaboration with them. 31 00:01:58,940 --> 00:02:01,840 >> In fact, one of the most interesting parts, 32 00:02:01,840 --> 00:02:06,560 I will say of running this class now, both at Harvard and here at Yale, 33 00:02:06,560 --> 00:02:09,420 is the really incredible cross-fertilization 34 00:02:09,420 --> 00:02:13,770 of ideas, aimed at improving the learning experience to you all. 35 00:02:13,770 --> 00:02:18,130 So as a result of this extensive collaboration between the two 36 00:02:18,130 --> 00:02:23,070 university, CS50 is proud to announce the new version this year 37 00:02:23,070 --> 00:02:24,770 with noticeable changes. 38 00:02:24,770 --> 00:02:27,580 David will all tell us about them now. 39 00:02:27,580 --> 00:02:31,450 So please-- this being said, please join me 40 00:02:31,450 --> 00:02:34,220 and welcome to give a big round of applause 41 00:02:34,220 --> 00:02:37,290 to welcome David and Harvard team here at Yale. 42 00:02:37,290 --> 00:02:40,032 >> [APPLAUSE] 43 00:02:40,032 --> 00:02:41,882 44 00:02:41,882 --> 00:02:43,247 >> DAVID MALAN: Thank you. 45 00:02:43,247 --> 00:02:43,746 Thanks. 46 00:02:43,746 --> 00:02:46,550 47 00:02:46,550 --> 00:02:51,400 This is CS50, Harvard University's and Yale University's introduction 48 00:02:51,400 --> 00:02:53,960 to the intellectual enterprises of computer science 49 00:02:53,960 --> 00:02:55,490 and the art of programming. 50 00:02:55,490 --> 00:02:59,640 And what that means is that this course ultimately, is about problem solving. 51 00:02:59,640 --> 00:03:01,849 Indeed many of you might have come out of high school 52 00:03:01,849 --> 00:03:04,931 or have spent the past couple of years wondering what some of your friends 53 00:03:04,931 --> 00:03:06,380 did last year or in other classes. 54 00:03:06,380 --> 00:03:08,449 And yet, the reality is, no matter what we 55 00:03:08,449 --> 00:03:11,740 do at the end of the day in this class, it's going to be about problem solving. 56 00:03:11,740 --> 00:03:14,320 >> And as such, perhaps take some reassurance in the fact 57 00:03:14,320 --> 00:03:16,770 that 73% of the students that take this class, both here 58 00:03:16,770 --> 00:03:20,235 at Yale as well as at Harvard, have never taken a CS class before. 59 00:03:20,235 --> 00:03:22,610 So if you're sitting here in the audience today wondering 60 00:03:22,610 --> 00:03:24,520 why you are sitting here in the audience today, 61 00:03:24,520 --> 00:03:26,300 or maybe you just followed along with some friends, 62 00:03:26,300 --> 00:03:28,299 or maybe you've been a little curious as to what 63 00:03:28,299 --> 00:03:30,194 computer science and programming is, realize 64 00:03:30,194 --> 00:03:32,860 that most of your classmates to the left and to the right of you 65 00:03:32,860 --> 00:03:35,840 are very much in that same demographic. 66 00:03:35,840 --> 00:03:38,120 >> And indeed, if we look at last year statistics 67 00:03:38,120 --> 00:03:42,760 within the student body of CS50, both here and at Harvard, 58% of students 68 00:03:42,760 --> 00:03:44,630 describe themselves as less comfortable. 69 00:03:44,630 --> 00:03:46,090 9% is more comfortable. 70 00:03:46,090 --> 00:03:47,699 And then 33% is somewhere in between. 71 00:03:47,699 --> 00:03:50,240 And there's no formal definition of what these buckets means. 72 00:03:50,240 --> 00:03:52,335 You sort of know you're less comfortable if you are. 73 00:03:52,335 --> 00:03:54,840 You're feeling a little uneasy with maybe being in the class. 74 00:03:54,840 --> 00:03:57,840 You're not quite sure if a computer science class is ultimately for you, 75 00:03:57,840 --> 00:04:00,009 and realize that you are in very good company. 76 00:04:00,009 --> 00:04:01,800 And indeed the grading, and the assessment, 77 00:04:01,800 --> 00:04:04,466 and the feedback, and all of that support structure in the class 78 00:04:04,466 --> 00:04:06,550 is ultimately very much individualized. 79 00:04:06,550 --> 00:04:09,187 More so than most any other class by design. 80 00:04:09,187 --> 00:04:11,520 And indeed, what ultimately matters in this class is not 81 00:04:11,520 --> 00:04:14,180 so much where you end up relative to others, 82 00:04:14,180 --> 00:04:18,070 but where you, in week 11 or last, and relative to yourself in week 83 00:04:18,070 --> 00:04:20,372 0 here our first. 84 00:04:20,372 --> 00:04:21,330 So what does that mean? 85 00:04:21,330 --> 00:04:24,750 Well, this means of those 73% of students last year that had never taken 86 00:04:24,750 --> 00:04:26,917 a CS class before, by the start of the semester they 87 00:04:26,917 --> 00:04:29,500 were dabbling in a language called Scratch, which we ourselves 88 00:04:29,500 --> 00:04:30,340 will see here today. 89 00:04:30,340 --> 00:04:32,190 And by the end of the semester had they gone 90 00:04:32,190 --> 00:04:34,700 through this entire list of challenges. 91 00:04:34,700 --> 00:04:36,399 Starting with a language called c. 92 00:04:36,399 --> 00:04:38,190 Implementing, what's at first glance, going 93 00:04:38,190 --> 00:04:41,010 to be a bit of a challenge for some, but fairly gratifying once you 94 00:04:41,010 --> 00:04:44,510 get Super Mario bouncing up and down a pyramid 95 00:04:44,510 --> 00:04:47,005 implemented, albeit, with just something called ASCII art. 96 00:04:47,005 --> 00:04:49,380 Implementing last year-- what the students last year then 97 00:04:49,380 --> 00:04:53,270 did after that was implement their own Caesar cipher and vigenere cipher. 98 00:04:53,270 --> 00:04:55,180 So encryption algorithms with which you could 99 00:04:55,180 --> 00:04:58,920 scramble information and then unscramble information to send secret messages. 100 00:04:58,920 --> 00:05:00,010 The game of 15. 101 00:05:00,010 --> 00:05:02,260 If you remember from childhood or some party favor, 102 00:05:02,260 --> 00:05:05,000 that little plastic game where you move the numbers up, down, left and right 103 00:05:05,000 --> 00:05:07,500 to try to get them in order, actually implementing that game 104 00:05:07,500 --> 00:05:09,640 and solving the logic required there. 105 00:05:09,640 --> 00:05:11,640 And then we dabbled in forensics last year. 106 00:05:11,640 --> 00:05:13,810 >> So by mid-semester, students who had never 107 00:05:13,810 --> 00:05:16,130 used their keyboards for this purpose before, 108 00:05:16,130 --> 00:05:19,030 were writing software to recover, so to speak, 109 00:05:19,030 --> 00:05:21,420 JPEGs or photographs that we had accidentally 110 00:05:21,420 --> 00:05:24,430 deleted from a digital memory card from a camera. 111 00:05:24,430 --> 00:05:28,130 Recovering secret messages from inside of a bitmap image, 112 00:05:28,130 --> 00:05:30,030 and other such types of graphics as well. 113 00:05:30,030 --> 00:05:32,770 >> We then transitioned to giving the whole class a dictionary. 114 00:05:32,770 --> 00:05:36,330 Just a really big text file with 150,000 English words. 115 00:05:36,330 --> 00:05:39,080 And everyone was challenged to somehow read, so to speak, 116 00:05:39,080 --> 00:05:40,780 those words into memory. 117 00:05:40,780 --> 00:05:42,060 Into the computer's memory. 118 00:05:42,060 --> 00:05:44,310 And then answer questions of the form, is this a word? 119 00:05:44,310 --> 00:05:44,934 Is this a word? 120 00:05:44,934 --> 00:05:45,580 Is this a word? 121 00:05:45,580 --> 00:05:47,880 Really just implementing a spell checker. 122 00:05:47,880 --> 00:05:50,320 And then challenging each other with a big board-- 123 00:05:50,320 --> 00:05:53,040 a leader board to see who could use the least amount of memory, 124 00:05:53,040 --> 00:05:56,470 in the least amount of time to actually spell check large documents. 125 00:05:56,470 --> 00:05:59,760 >> We transitioned from then to implementing ones own web server. 126 00:05:59,760 --> 00:06:04,070 So not making web pages in languages like HTML and CSS, if you're familiar. 127 00:06:04,070 --> 00:06:06,360 But actually implementing the server that 128 00:06:06,360 --> 00:06:09,260 listens on the internet for requests from browsers 129 00:06:09,260 --> 00:06:11,022 and then responding to those requests. 130 00:06:11,022 --> 00:06:13,230 Then implementing our own e-trade like website, where 131 00:06:13,230 --> 00:06:15,490 students could buy and sell stocks. 132 00:06:15,490 --> 00:06:18,590 Drawing in nearly real time stock quotes from Yahoo Finance. 133 00:06:18,590 --> 00:06:21,200 And allowing students to see how their portfolio develops. 134 00:06:21,200 --> 00:06:23,570 And then finally a mash up of Google News and Google 135 00:06:23,570 --> 00:06:26,540 Maps whereby students by term by terms end 136 00:06:26,540 --> 00:06:30,110 had the ability to click, and round, and search on a Google map. 137 00:06:30,110 --> 00:06:32,060 And then see all of the news articles that 138 00:06:32,060 --> 00:06:33,940 are proximal to those particular areas. 139 00:06:33,940 --> 00:06:36,180 So truly going from zero to 60. 140 00:06:36,180 --> 00:06:39,420 >> And along the way having what we had last year called, hacker additions. 141 00:06:39,420 --> 00:06:41,211 That raise the bar further for those of you 142 00:06:41,211 --> 00:06:44,390 who might very well have a good amount of experience being in that 9% 143 00:06:44,390 --> 00:06:45,349 of more comfortable. 144 00:06:45,349 --> 00:06:47,140 So realize that there's a very high ceiling 145 00:06:47,140 --> 00:06:49,200 even within those challenges for students 146 00:06:49,200 --> 00:06:50,660 coming from a different background. 147 00:06:50,660 --> 00:06:52,618 Because at the end of the day, we're ultimately 148 00:06:52,618 --> 00:06:54,910 focused quite simply on this. 149 00:06:54,910 --> 00:06:57,010 >> But what does this mean, problem solving? 150 00:06:57,010 --> 00:06:59,100 So let's propose that we distill it like this. 151 00:06:59,100 --> 00:07:01,550 So problem solving is really just this kind of picture. 152 00:07:01,550 --> 00:07:04,675 So you've got inputs to some problem, something you actually want to solve. 153 00:07:04,675 --> 00:07:07,020 The goal is to get outputs, a solution to that problem. 154 00:07:07,020 --> 00:07:09,950 And then in the middle is what we'll call a black box. 155 00:07:09,950 --> 00:07:13,970 You don't necessarily know or even care what's inside that black box. 156 00:07:13,970 --> 00:07:16,670 All you know is that when you feed input into it, 157 00:07:16,670 --> 00:07:19,890 you hopefully get output or a solution from it. 158 00:07:19,890 --> 00:07:22,380 And while today we'll look both at inputs and outputs, 159 00:07:22,380 --> 00:07:24,838 we'll long term, and over the course of the whole semester, 160 00:07:24,838 --> 00:07:26,880 focus on what's inside that box. 161 00:07:26,880 --> 00:07:30,040 >> And therein will lie something called algorithms. 162 00:07:30,040 --> 00:07:33,300 Step by step instructions for actually solving some problems. 163 00:07:33,300 --> 00:07:35,090 But what's an example of some inputs? 164 00:07:35,090 --> 00:07:37,840 So maybe a simple thing at the start of every school year, someone 165 00:07:37,840 --> 00:07:39,090 might want to take attendance. 166 00:07:39,090 --> 00:07:42,030 So we might do one, two, three, four, five, six, 167 00:07:42,030 --> 00:07:44,010 and how would I keep track of that information. 168 00:07:44,010 --> 00:07:46,051 I might just go one, two, three, four, five, six. 169 00:07:46,051 --> 00:07:47,720 And just use sort of single digits. 170 00:07:47,720 --> 00:07:51,210 >> Or I could actually record this a little longer term. 171 00:07:51,210 --> 00:07:53,340 And how do I represent all the humans in this room? 172 00:07:53,340 --> 00:07:54,900 Well, I might do something like, OK. 173 00:07:54,900 --> 00:07:56,070 I see one person. 174 00:07:56,070 --> 00:07:56,600 All right. 175 00:07:56,600 --> 00:08:01,180 I see another person, a third person, and so forth. 176 00:08:01,180 --> 00:08:04,070 But no one counts people like this. 177 00:08:04,070 --> 00:08:06,952 So literally, most of us if we're even going to draw anything at all, 178 00:08:06,952 --> 00:08:08,910 are probably going to go one, two, three, four, 179 00:08:08,910 --> 00:08:14,240 maybe get a little fancy, five, six, seven, eight, nine, ten and so forth. 180 00:08:14,240 --> 00:08:16,960 >> And that's actually a system called unary. 181 00:08:16,960 --> 00:08:20,549 Uno, like uno implying one, where you just have one letter of the alphabet. 182 00:08:20,549 --> 00:08:21,840 You've just got this hash mark. 183 00:08:21,840 --> 00:08:24,570 And I, for efficiency, just drew these hash marks, ultimately 184 00:08:24,570 --> 00:08:25,500 as straight lines. 185 00:08:25,500 --> 00:08:27,666 But I could have drawn them as little stick figures. 186 00:08:27,666 --> 00:08:29,550 Where to represent one person, one input, 187 00:08:29,550 --> 00:08:32,210 I just draw a stick figure or a hash mark. 188 00:08:32,210 --> 00:08:33,910 But this isn't all that expressive. 189 00:08:33,910 --> 00:08:38,020 >> If all I have is these hash marks, let alone stick figures, 190 00:08:38,020 --> 00:08:41,410 how might I represent something like the number 15? 191 00:08:41,410 --> 00:08:43,050 Or 15 people in the room? 192 00:08:43,050 --> 00:08:48,740 I might have to do something like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 193 00:08:48,740 --> 00:08:51,270 14, 15. 194 00:08:51,270 --> 00:08:52,830 It just does not scale very well. 195 00:08:52,830 --> 00:08:55,730 As the inputs get large, we need a better system than this. 196 00:08:55,730 --> 00:08:57,910 >> And it turns out that the system that computers use 197 00:08:57,910 --> 00:09:00,510 is not all that different from what you and I know. 198 00:09:00,510 --> 00:09:03,301 In fact, most people in this room, even if you are among those less 199 00:09:03,301 --> 00:09:06,300 comfortable, don't necessarily know how your Mac or PC really works, 200 00:09:06,300 --> 00:09:09,810 you've probably at least heard, that underneath the hood are 0's and 1's. 201 00:09:09,810 --> 00:09:11,390 The so-called binary system. 202 00:09:11,390 --> 00:09:15,340 So indeed, computers have more than just hash marks in their vocabulary, 203 00:09:15,340 --> 00:09:17,450 but not as much of a vocabulary as we humans. 204 00:09:17,450 --> 00:09:19,210 >> Indeed, we humans don't use binary. 205 00:09:19,210 --> 00:09:21,160 Bi meaning 2, 0 and 1. 206 00:09:21,160 --> 00:09:24,140 But decimal, deca meaning 10, 0 through 9. 207 00:09:24,140 --> 00:09:27,660 So we have a lot more expressive capabilities in our normal human world. 208 00:09:27,660 --> 00:09:31,720 But I'd argue that these systems, binary, and decimal, and everything 209 00:09:31,720 --> 00:09:35,290 in between and beyond, are actually all quite familiar. 210 00:09:35,290 --> 00:09:39,650 For instance, consider this example here, 123. 211 00:09:39,650 --> 00:09:43,850 So this really is, of course, a number we know as 123. 212 00:09:43,850 --> 00:09:47,160 But all I just drew was just this pattern of symbols, glyphs so to speak. 213 00:09:47,160 --> 00:09:49,100 Sort of shapes on the board in chalk. 214 00:09:49,100 --> 00:09:52,951 >> But why do we immediately and intuitively grasp this as 123? 215 00:09:52,951 --> 00:09:54,700 Well, if you were like me in grade school, 216 00:09:54,700 --> 00:09:59,920 you probably learned that this is the 1s column, this is the 10s column, 217 00:09:59,920 --> 00:10:01,330 this is the 100s column. 218 00:10:01,330 --> 00:10:02,860 And why is that useful? 219 00:10:02,860 --> 00:10:06,440 Well, it's simple arithmetic you now do to get from a pattern of symbols 220 00:10:06,440 --> 00:10:08,940 to a number we understand intuitively. 221 00:10:08,940 --> 00:10:14,160 Is what, 100 times 1, and then 10 times 2, and 1 times 3, 222 00:10:14,160 --> 00:10:17,860 which of course is just 100, and this is 20, and this is three. 223 00:10:17,860 --> 00:10:19,740 And so if we add those together-- ah. 224 00:10:19,740 --> 00:10:23,880 So therein lies the sort of reasoning behind why this set of symbols 225 00:10:23,880 --> 00:10:26,550 means something real and numeric. 226 00:10:26,550 --> 00:10:32,030 >> Well, computers do the exact same thing, but they only can count as high as one. 227 00:10:32,030 --> 00:10:34,400 Whereas I was able to count as high as three. 228 00:10:34,400 --> 00:10:37,380 And in fact, if I kept going I could go as high as nine in this system. 229 00:10:37,380 --> 00:10:40,430 Computers only have zeros and ones in their alphabet. 230 00:10:40,430 --> 00:10:41,410 >> So what does that mean? 231 00:10:41,410 --> 00:10:46,900 Well, it just means that if a computer wants to represent, say the number 0, 232 00:10:46,900 --> 00:10:51,300 maybe using three characters-- three letters of the alphabet so to speak, 233 00:10:51,300 --> 00:10:53,050 that's how a computer represents 0. 234 00:10:53,050 --> 00:10:54,620 So not all that scary so far. 235 00:10:54,620 --> 00:10:56,450 It's exactly what we humans would do. 236 00:10:56,450 --> 00:10:59,410 And in fact, most of us would just ignore the leading zeros anyway. 237 00:10:59,410 --> 00:11:01,640 >> A computer, if it wants to store the number 1, 238 00:11:01,640 --> 00:11:03,330 turns out is going to do this. 239 00:11:03,330 --> 00:11:05,630 And a computer to store the number 2 is not 240 00:11:05,630 --> 00:11:09,280 going to do the unary system, which I alluded to earlier. 241 00:11:09,280 --> 00:11:11,360 It's actually going to do this. 242 00:11:11,360 --> 00:11:13,570 And this is probably where the pattern starts 243 00:11:13,570 --> 00:11:15,570 to become less obvious for most folks. 244 00:11:15,570 --> 00:11:18,580 That's 2, this is 3. 245 00:11:18,580 --> 00:11:21,600 Curiously, this is now 4. 246 00:11:21,600 --> 00:11:24,120 And now it really does seem to be perhaps cryptic, 247 00:11:24,120 --> 00:11:26,762 but it's not if we consider what binary really means. 248 00:11:26,762 --> 00:11:28,720 It means you have two letters of your alphabet. 249 00:11:28,720 --> 00:11:31,940 So two possible characters for each placeholder. 250 00:11:31,940 --> 00:11:35,970 >> So that really means we're going to need a 1s place, or 2s place, 251 00:11:35,970 --> 00:11:40,800 a 4s place and then 8, and 16, 32, and 64. 252 00:11:40,800 --> 00:11:42,290 And what's the difference there? 253 00:11:42,290 --> 00:11:47,150 Like these are 1, 2, 4, 8, 16, 32, 64. 254 00:11:47,150 --> 00:11:50,690 And before we had 110, 100,000, 10,000. 255 00:11:50,690 --> 00:11:53,170 What's the similarity there? 256 00:11:53,170 --> 00:11:54,940 And what's the pattern? 257 00:11:54,940 --> 00:11:55,505 Yeah. 258 00:11:55,505 --> 00:11:57,380 STUDENT: Powers of 2 instead of powers of 10. 259 00:11:57,380 --> 00:11:57,660 DAVID MALAN: Yeah. 260 00:11:57,660 --> 00:11:59,290 Powers of 2 instead of powers of 10. 261 00:11:59,290 --> 00:12:02,160 And so if I wanted to keep going, 8, 16s and so forth-- 262 00:12:02,160 --> 00:12:05,822 but now if you have this sort of clue, now the binary system 263 00:12:05,822 --> 00:12:07,280 is actually pretty straightforward. 264 00:12:07,280 --> 00:12:10,910 Why is this pattern of 0's in the world of computers 0? 265 00:12:10,910 --> 00:12:14,910 Well because it's 4 times 0, 2 times 0, 1 times 0 and you get 0. 266 00:12:14,910 --> 00:12:16,650 >> Why is this the number 1? 267 00:12:16,650 --> 00:12:20,070 Same reasoning, but now we have a 1 in the 1 column. 268 00:12:20,070 --> 00:12:21,840 Why is this 2? 269 00:12:21,840 --> 00:12:24,450 We have a 1 in the 2s column. 270 00:12:24,450 --> 00:12:30,190 And how then do I represent say, the number 7 in binary? 271 00:12:30,190 --> 00:12:31,324 Say louder. 272 00:12:31,324 --> 00:12:32,170 >> STUDENT: Three 1s. 273 00:12:32,170 --> 00:12:33,086 >> DAVID MALAN: Three 1s. 274 00:12:33,086 --> 00:12:37,110 So 1, 1, 1 because we just need 4 plus 2 plus 1 gives me 7. 275 00:12:37,110 --> 00:12:37,610 All right. 276 00:12:37,610 --> 00:12:40,410 So from there how do we represent 8 with 3 placeholders? 277 00:12:40,410 --> 00:12:43,310 278 00:12:43,310 --> 00:12:43,922 Yeah. 279 00:12:43,922 --> 00:12:45,070 >> STUDENT: 1, 0, 0, 0. 280 00:12:45,070 --> 00:12:46,970 >> DAVID MALAN: Yeah 1, 0, 0, 0. 281 00:12:46,970 --> 00:12:49,380 And yet maybe, I kind of technically need 282 00:12:49,380 --> 00:12:52,380 to add another placeholder to the board. 283 00:12:52,380 --> 00:12:55,480 If I want to fit that I indeed need to do something like this. 284 00:12:55,480 --> 00:12:58,990 So I actually need to use now the 8s column, and that's fine. 285 00:12:58,990 --> 00:13:02,680 But the curious thing in computing is that that's going to cost us something. 286 00:13:02,680 --> 00:13:04,390 You need more RAM in your computer now. 287 00:13:04,390 --> 00:13:06,348 You need more memory because you need something 288 00:13:06,348 --> 00:13:09,650 physical to store that additional bit, so to speak. 289 00:13:09,650 --> 00:13:10,700 Binary digits. 290 00:13:10,700 --> 00:13:13,260 And indeed all that's happened here, like the decimal system, 291 00:13:13,260 --> 00:13:17,380 if we keep adding numbers up and up and up, we go to 5 to 6 to 7 to 8 292 00:13:17,380 --> 00:13:19,330 it's like carrying the 1, literally. 293 00:13:19,330 --> 00:13:21,940 And then everything else goes back down to zero. 294 00:13:21,940 --> 00:13:25,870 >> But how do we actually represent these things physically in a computer? 295 00:13:25,870 --> 00:13:29,380 Well, at the end of the day, the only physical input going into my computer 296 00:13:29,380 --> 00:13:33,630 here is this power cord, so electricity or electrons from the wall. 297 00:13:33,630 --> 00:13:36,920 And so how do I get from something physical like that to actually 298 00:13:36,920 --> 00:13:40,630 representing an idea like this instead. 299 00:13:40,630 --> 00:13:41,930 >> Well, what could we do? 300 00:13:41,930 --> 00:13:45,560 We could consider that, all right, maybe if electricity is flowing 301 00:13:45,560 --> 00:13:47,420 I could store it and hold on to it. 302 00:13:47,420 --> 00:13:49,250 And if I'm holding on to some electricity, 303 00:13:49,250 --> 00:13:51,700 that's just going to arbitrarily represent a 1. 304 00:13:51,700 --> 00:13:53,997 And if I pull the plug and there's nothing there, 305 00:13:53,997 --> 00:13:56,330 you know that's just going to arbitrarily represent a 0. 306 00:13:56,330 --> 00:13:57,700 >> So if something's there, 1. 307 00:13:57,700 --> 00:13:59,280 If nothing's there, 0. 308 00:13:59,280 --> 00:14:01,420 Or you can make this a little more visual. 309 00:14:01,420 --> 00:14:02,704 Here is a 0. 310 00:14:02,704 --> 00:14:05,370 There's nothing interesting going on about the back of my phone. 311 00:14:05,370 --> 00:14:08,690 But if I allow a little bit of electricity to flow, 312 00:14:08,690 --> 00:14:11,490 even though it's a little bright in here, my flashlight went on. 313 00:14:11,490 --> 00:14:15,840 So I'm storing a charge and ergo, this phone now represents a 1. 314 00:14:15,840 --> 00:14:17,700 So 0 1. 315 00:14:17,700 --> 00:14:23,630 >> So with 1 iPhone how high can I count using this kind of approach? 316 00:14:23,630 --> 00:14:24,490 I mean to 1. 317 00:14:24,490 --> 00:14:25,900 It's not all that compelling. 318 00:14:25,900 --> 00:14:27,170 So what more could we do? 319 00:14:27,170 --> 00:14:31,180 Well let's see, is anyone on their phone right now that I could borrow? 320 00:14:31,180 --> 00:14:33,800 Anyone who has a phone with a flashlight built in? 321 00:14:33,800 --> 00:14:34,969 May I borrow? 322 00:14:34,969 --> 00:14:36,010 I don't need it unlocked. 323 00:14:36,010 --> 00:14:36,510 All right. 324 00:14:36,510 --> 00:14:37,150 Thank you. 325 00:14:37,150 --> 00:14:37,780 Let me borrow this. 326 00:14:37,780 --> 00:14:38,279 All right. 327 00:14:38,279 --> 00:14:45,570 So if I now scroll up and here, what am I representing now? 328 00:14:45,570 --> 00:14:46,070 Yeah. 329 00:14:46,070 --> 00:14:49,350 So it's a three because this is in the 1s column, this is in the 2s column. 330 00:14:49,350 --> 00:14:50,480 So 1 plus 2 is 3. 331 00:14:50,480 --> 00:14:53,410 And then if we try to get really creative-- oh, thank you. 332 00:14:53,410 --> 00:14:54,690 Very preemptive. 333 00:14:54,690 --> 00:14:55,560 All right. 334 00:14:55,560 --> 00:14:57,100 I now have three iPhones. 335 00:14:57,100 --> 00:14:58,810 All right. 336 00:14:58,810 --> 00:15:02,500 >> And now this-- I won't do any further than this. 337 00:15:02,500 --> 00:15:04,380 What am I representing now? 338 00:15:04,380 --> 00:15:05,090 Just sevens. 339 00:15:05,090 --> 00:15:08,000 But I needed physically more memory in this case. 340 00:15:08,000 --> 00:15:08,920 But that's all it is. 341 00:15:08,920 --> 00:15:12,870 You can think of what's going on-- thank you-- inside of your phone 342 00:15:12,870 --> 00:15:16,240 as just being a switch that's being turned on and off. 343 00:15:16,240 --> 00:15:18,350 >> And if you've ever heard the word transistor. 344 00:15:18,350 --> 00:15:21,312 Or if you've ever heard the marketing speak Intel inside, 345 00:15:21,312 --> 00:15:24,270 that's speaking to the kind of hardware that's inside of your computer. 346 00:15:24,270 --> 00:15:26,707 Intel makes CPUs, central processing units, 347 00:15:26,707 --> 00:15:28,790 which are like the brains inside of your computer. 348 00:15:28,790 --> 00:15:30,640 And these CPUs and things they're connected 349 00:15:30,640 --> 00:15:32,740 to have lots and lots of tiny switches. 350 00:15:32,740 --> 00:15:36,440 Millions, billions of switches that can either be on or off. 351 00:15:36,440 --> 00:15:38,840 >> So computers, thankfully, like our Macs and PCs, 352 00:15:38,840 --> 00:15:43,830 can count way higher than 7 or 8 because they have way more than three 353 00:15:43,830 --> 00:15:44,660 or four bits. 354 00:15:44,660 --> 00:15:48,140 Way more than the equivalent of the three flashlights that we just had. 355 00:15:48,140 --> 00:15:52,110 But now this starts to get pretty uninteresting quickly. 356 00:15:52,110 --> 00:15:55,810 If I now want to actually be able to do something more interesting, 357 00:15:55,810 --> 00:16:00,340 I want to be able to jump to something like this. 358 00:16:00,340 --> 00:16:03,604 >> So ASCII, it's not really a useful acronym, but American Standard Code 359 00:16:03,604 --> 00:16:04,770 for Information Interchange. 360 00:16:04,770 --> 00:16:07,450 It just means, some years ago we humans decided, 361 00:16:07,450 --> 00:16:10,724 you know what, we want to be able to do more with computers than just numbers. 362 00:16:10,724 --> 00:16:12,890 We don't want them to just be expensive calculators, 363 00:16:12,890 --> 00:16:16,730 we'd like to be able to do things like word processing, albeit very simply. 364 00:16:16,730 --> 00:16:20,030 Later we had email and other such media. 365 00:16:20,030 --> 00:16:23,700 >> And so the world decided some years ago according to this system ASCII, 366 00:16:23,700 --> 00:16:24,770 you know what? 367 00:16:24,770 --> 00:16:26,970 In certain types of programs any time you 368 00:16:26,970 --> 00:16:30,649 see the equivalent of the number 65, like the pattern of bits. 369 00:16:30,649 --> 00:16:32,440 And we could do the math here on the board. 370 00:16:32,440 --> 00:16:34,450 The pattern of bits that represent 65. 371 00:16:34,450 --> 00:16:37,240 Don't think of it as 65 in decimal. 372 00:16:37,240 --> 00:16:41,620 Think of it as arbitrarily, but globally, consistently as the capital 373 00:16:41,620 --> 00:16:42,201 A. 374 00:16:42,201 --> 00:16:43,950 And then the world decided, you know what? 375 00:16:43,950 --> 00:16:45,630 Let's take another pattern of bits. 376 00:16:45,630 --> 00:16:47,770 And if we ever see the number 66, let's just 377 00:16:47,770 --> 00:16:50,573 assume that that is the capital B. Fast forward to H 378 00:16:50,573 --> 00:16:55,510 and I, if you see 72 or 73, that should be an H and an I, respectively. 379 00:16:55,510 --> 00:16:57,780 And so as long as the whole world agrees upon this. 380 00:16:57,780 --> 00:17:01,342 So that when you receive an email, or you would get a file on a USB stick, 381 00:17:01,342 --> 00:17:03,800 or something like that-- when you see that pattern of bits, 382 00:17:03,800 --> 00:17:06,980 you know that it should be this letter or some other letter. 383 00:17:06,980 --> 00:17:08,620 >> But it's context specific, right. 384 00:17:08,620 --> 00:17:12,250 An email program might interpret these things as characters, 385 00:17:12,250 --> 00:17:15,760 but a graphing calculator or calculator might represent or interpret 386 00:17:15,760 --> 00:17:18,370 these things, of course, as letters. 387 00:17:18,370 --> 00:17:21,610 >> So with that said, quick little review. 388 00:17:21,610 --> 00:17:25,440 This is maybe a three character e-mail that's been sent to me. 389 00:17:25,440 --> 00:17:27,990 Underneath the hood it's all in 0s and 1s, But we don't care. 390 00:17:27,990 --> 00:17:31,580 We're going to start to abstract above the 0s and 1s to letters. 391 00:17:31,580 --> 00:17:36,830 And if I see a pattern of 0s and 1s that really represent 72, hint, hint, 73, 392 00:17:36,830 --> 00:17:38,866 and then 33, what's the message? 393 00:17:38,866 --> 00:17:40,348 >> STUDENT: [INAUDIBLE] 394 00:17:40,348 --> 00:17:42,639 DAVID MALAN: So if you think back just a moment ago, HI 395 00:17:42,639 --> 00:17:47,210 was the message I was trying to communicate here because H is 72, 396 00:17:47,210 --> 00:17:50,925 I is 73, and now 33-- you wouldn't necessarily know this in advance, 397 00:17:50,925 --> 00:17:53,800 but it turns out if you actually see more of the chart and the system 398 00:17:53,800 --> 00:17:56,800 that humanity agreed upon years ago, it's just an exclamation point. 399 00:17:56,800 --> 00:18:01,590 And indeed, there is a pattern of symbols and numbers for every character 400 00:18:01,590 --> 00:18:03,849 that you might have on your keyboard. 401 00:18:03,849 --> 00:18:04,389 >> All right. 402 00:18:04,389 --> 00:18:05,660 Let's abstract further. 403 00:18:05,660 --> 00:18:09,380 If we don't want to just have things like numbers and letters, 404 00:18:09,380 --> 00:18:11,420 we actually want to implement graphics. 405 00:18:11,420 --> 00:18:13,351 Well, if you've ever heard the acronym RGB. 406 00:18:13,351 --> 00:18:15,559 It's kind of dated now, but it's still kind of there. 407 00:18:15,559 --> 00:18:17,380 RGB is red, green, blue. 408 00:18:17,380 --> 00:18:19,380 And it's just a system of saying, you know what, 409 00:18:19,380 --> 00:18:21,650 let's use three sets of bits. 410 00:18:21,650 --> 00:18:25,280 A set of 8 bits, another set of 8 bits, and another set of 8 bits. 411 00:18:25,280 --> 00:18:27,710 And let's use those bits to store how much red we 412 00:18:27,710 --> 00:18:31,430 want on our screen, how much green we want on our screen, 413 00:18:31,430 --> 00:18:34,070 and how much blue we want on our screen. 414 00:18:34,070 --> 00:18:37,860 And this just means that if you have a lot-- a big number for red, 415 00:18:37,860 --> 00:18:39,200 that means give me a lot of red. 416 00:18:39,200 --> 00:18:41,658 If you have a big number for green, give me a lot of green. 417 00:18:41,658 --> 00:18:44,660 And if you have just a little bit of blue or a small number like 33, 418 00:18:44,660 --> 00:18:45,960 give me a little bit of blue. 419 00:18:45,960 --> 00:18:49,720 And if you happen to combine those three magnitudes, so to speak, 420 00:18:49,720 --> 00:18:53,160 you get this-- you barely can see on the projector here, but this murky 421 00:18:53,160 --> 00:18:54,630 shade of yellow or brown. 422 00:18:54,630 --> 00:18:58,590 >> But this is to say, using that pattern of 8 plus 8 plus plus 8-- 423 00:18:58,590 --> 00:19:01,710 that pattern of 24 bits is how a computer would 424 00:19:01,710 --> 00:19:06,460 store that shade of yellow in one tiny dot a pixel on the screen. 425 00:19:06,460 --> 00:19:10,570 So we've gone from 0s and 1s to decimal numbers to letters of the alphabet. 426 00:19:10,570 --> 00:19:13,680 Or more interesting, colored dots. 427 00:19:13,680 --> 00:19:16,200 >> Well, what of course then comes next? 428 00:19:16,200 --> 00:19:19,040 Well, what is an image that you see on Facebook or get in an email? 429 00:19:19,040 --> 00:19:20,172 Or the like? 430 00:19:20,172 --> 00:19:22,130 What is the definition technically of an image? 431 00:19:22,130 --> 00:19:25,090 432 00:19:25,090 --> 00:19:27,710 Yeah. 433 00:19:27,710 --> 00:19:31,270 What is an image composed of if you look really close at your screen? 434 00:19:31,270 --> 00:19:31,770 Yeah. 435 00:19:31,770 --> 00:19:33,186 It's just a whole bunch of pixels. 436 00:19:33,186 --> 00:19:35,220 In fact, if you take your laptop maybe later on, 437 00:19:35,220 --> 00:19:37,180 and look really closely at it-- depending 438 00:19:37,180 --> 00:19:40,370 on how expensive the laptop is and how high quality the screen is, 439 00:19:40,370 --> 00:19:43,480 you might very well see all of the little dots on the screen. 440 00:19:43,480 --> 00:19:45,890 >> And those dots or pixels, which means there's 441 00:19:45,890 --> 00:19:49,810 24 bits representing every pixel in that photograph that you see on Facebook, 442 00:19:49,810 --> 00:19:52,049 or that you just took on your iPhone recently. 443 00:19:52,049 --> 00:19:54,090 And so that's how we get to things like graphics. 444 00:19:54,090 --> 00:19:55,120 Well, what's a video? 445 00:19:55,120 --> 00:19:58,660 A video is just a set of graphics flying by the screen again 446 00:19:58,660 --> 00:19:59,780 and again and again. 447 00:19:59,780 --> 00:20:04,080 And so videos really, are just patterns of bits representing grids, rows 448 00:20:04,080 --> 00:20:06,880 and columns of dots, flying by the screen image, 449 00:20:06,880 --> 00:20:09,240 after image, after image, a.k.a. 450 00:20:09,240 --> 00:20:10,650 Motion pictures. 451 00:20:10,650 --> 00:20:12,340 So that's it for inputs and outputs. 452 00:20:12,340 --> 00:20:14,420 >> All we have now is an assumption that, you 453 00:20:14,420 --> 00:20:17,190 know what, if we want a computer to represent information, 454 00:20:17,190 --> 00:20:18,560 we have a system for doing it. 455 00:20:18,560 --> 00:20:20,780 We can do it with 0s and 1s at the end of the day. 456 00:20:20,780 --> 00:20:23,160 But we can abstract, so to speak, on top of that 457 00:20:23,160 --> 00:20:25,140 so as to represent more interesting things. 458 00:20:25,140 --> 00:20:28,790 And here on out in CS50, and in computer science more generally, 459 00:20:28,790 --> 00:20:31,250 we now stand on the shoulders of all the people who 460 00:20:31,250 --> 00:20:33,530 came before us who figured that out. 461 00:20:33,530 --> 00:20:38,170 And now just assume that computers can represent inputs and outputs. 462 00:20:38,170 --> 00:20:41,140 >> But now let's actually do something with them. 463 00:20:41,140 --> 00:20:44,850 So an algorithm is just a set of instructions, step by step, 464 00:20:44,850 --> 00:20:46,340 for solving some problem. 465 00:20:46,340 --> 00:20:48,730 And what might one such problem be. 466 00:20:48,730 --> 00:20:52,440 So this is an old school technology, a phone book. 467 00:20:52,440 --> 00:20:55,534 And inside of a phone book is a whole bunch of names and numbers. 468 00:20:55,534 --> 00:20:57,700 And those names are generally sorted alphabetically. 469 00:20:57,700 --> 00:21:01,310 >> So if I wanted to find someone in this phone book like Mike Smith, 470 00:21:01,310 --> 00:21:02,930 what's a typical human going to do? 471 00:21:02,930 --> 00:21:06,000 Well, you could simply open it up, look at the first page. 472 00:21:06,000 --> 00:21:07,390 I don't see Mike Smith. 473 00:21:07,390 --> 00:21:09,740 Turn to the second page, I don't see Mike Smith. 474 00:21:09,740 --> 00:21:11,830 And just keep going and going. 475 00:21:11,830 --> 00:21:14,397 Is this step by step approach correct? 476 00:21:14,397 --> 00:21:17,380 477 00:21:17,380 --> 00:21:18,310 Yeah. 478 00:21:18,310 --> 00:21:20,080 It's kind of stupid, right. 479 00:21:20,080 --> 00:21:21,646 It's inefficient, right. 480 00:21:21,646 --> 00:21:24,520 Because it's going to take forever to get to Mike, but it is correct. 481 00:21:24,520 --> 00:21:26,620 Because if Mike is here I will indeed find him. 482 00:21:26,620 --> 00:21:29,030 >> So what's a slightly more reasonable person going to do? 483 00:21:29,030 --> 00:21:32,180 They might still open to the front, and maybe fly through the phone book 484 00:21:32,180 --> 00:21:33,250 two pages at a time. 485 00:21:33,250 --> 00:21:34,840 Two, four, six, eight. 486 00:21:34,840 --> 00:21:36,830 I can't actually physically do it very well. 487 00:21:36,830 --> 00:21:39,560 But in theory, this should be twice as fast, two pages at a time. 488 00:21:39,560 --> 00:21:41,152 Is this algorithm correct? 489 00:21:41,152 --> 00:21:43,252 >> STUDENT: [INAUDIBLE] 490 00:21:43,252 --> 00:21:44,460 DAVID MALAN: Not necessarily. 491 00:21:44,460 --> 00:21:44,960 Good. 492 00:21:44,960 --> 00:21:46,112 Why that caveat? 493 00:21:46,112 --> 00:21:50,020 >> STUDENT: Because he could be on one of the pages that you're skipping. 494 00:21:50,020 --> 00:21:50,770 DAVID MALAN: Yeah. 495 00:21:50,770 --> 00:21:52,260 So even if I get closer and closer. 496 00:21:52,260 --> 00:21:56,150 What if he's just accidentally, by bad luck, sandwiched between the two pages 497 00:21:56,150 --> 00:21:57,290 that I'm flying over? 498 00:21:57,290 --> 00:21:59,920 499 00:21:59,920 --> 00:22:01,730 So we need a fix for this. 500 00:22:01,730 --> 00:22:03,590 We actually need to then say, wait a minute, 501 00:22:03,590 --> 00:22:06,240 maybe if we go too far, maybe if we hit the T section, 502 00:22:06,240 --> 00:22:09,670 for T coming after Smith, then we should at least double back at least one page. 503 00:22:09,670 --> 00:22:12,630 So fixable, but there is a conditional issue there. 504 00:22:12,630 --> 00:22:16,159 So it's twice as fast, but you might have to double back just a little bit. 505 00:22:16,159 --> 00:22:19,200 But no one in his room, even if you don't really use phone books anymore, 506 00:22:19,200 --> 00:22:20,740 is going to start at the beginning. 507 00:22:20,740 --> 00:22:23,317 What are you going to do looking for Mike Smith? 508 00:22:23,317 --> 00:22:24,900 You're going to go roughly to the S's. 509 00:22:24,900 --> 00:22:26,820 Or if you don't really have the cheat sheet on the paper, 510 00:22:26,820 --> 00:22:28,365 you're going to go at least roughly to the middle. 511 00:22:28,365 --> 00:22:30,220 And certainly not to the front of the book. 512 00:22:30,220 --> 00:22:31,130 You're going to look down. 513 00:22:31,130 --> 00:22:33,770 And mathematically you're probably going to see the M section, which 514 00:22:33,770 --> 00:22:34,890 is roughly in the middle. 515 00:22:34,890 --> 00:22:36,848 And then you're going to realize, what is true? 516 00:22:36,848 --> 00:22:37,968 Where is Mike? 517 00:22:37,968 --> 00:22:39,170 >> STUDENT: [INAUDIBLE] 518 00:22:39,170 --> 00:22:39,920 DAVID MALAN: Yeah. 519 00:22:39,920 --> 00:22:41,530 So he's over on this side. 520 00:22:41,530 --> 00:22:42,710 And so what can you do? 521 00:22:42,710 --> 00:22:48,870 Well, both figuratively and literally can you tear the problem in half once? 522 00:22:48,870 --> 00:22:54,260 And then know that you can throw this half of the problem away. 523 00:22:54,260 --> 00:22:58,170 And now we're left with fundamentally the same problem, but it's half as big. 524 00:22:58,170 --> 00:22:59,920 And so now what's the set of instructions? 525 00:22:59,920 --> 00:23:01,753 What's the algorithm for finding Mike Smith? 526 00:23:01,753 --> 00:23:03,030 It's the exact same thing. 527 00:23:03,030 --> 00:23:05,750 >> Now this happens to be the M section and this is the Z section, 528 00:23:05,750 --> 00:23:08,650 but the fundamental formula is still the same. 529 00:23:08,650 --> 00:23:10,800 Go roughly to the middle, look down, oh, darn it. 530 00:23:10,800 --> 00:23:13,160 Now I'm in the T section, I've gone too far. 531 00:23:13,160 --> 00:23:16,640 But here too can you apply that same logic. 532 00:23:16,640 --> 00:23:19,189 Throw half of the problem away and now we're 533 00:23:19,189 --> 00:23:21,230 left with a problem that's a quarter of the size. 534 00:23:21,230 --> 00:23:28,140 And we can repeat, and we can repeat, and we can repeat until theoretically 535 00:23:28,140 --> 00:23:32,190 there's just one page left on which Mike either is or isn't. 536 00:23:32,190 --> 00:23:34,014 >> So what's so powerful about this idea? 537 00:23:34,014 --> 00:23:35,680 I mean after all, it's pretty intuitive. 538 00:23:35,680 --> 00:23:37,390 No one's going to start at the beginning of the phone book 539 00:23:37,390 --> 00:23:39,320 and flip 1,000 pages to find Mike Smith. 540 00:23:39,320 --> 00:23:42,319 Most everyone in this room is going to do roughly that kind of algorithm 541 00:23:42,319 --> 00:23:43,220 save for the tearing. 542 00:23:43,220 --> 00:23:45,480 >> And so why did we do that? 543 00:23:45,480 --> 00:23:47,810 Well, consider the efficiency. 544 00:23:47,810 --> 00:23:51,500 Consider just how much better this algorithm was by breaking it down 545 00:23:51,500 --> 00:23:52,890 into its component parts. 546 00:23:52,890 --> 00:23:53,980 So what did I first do? 547 00:23:53,980 --> 00:23:55,389 I picked up the phone book. 548 00:23:55,389 --> 00:23:57,180 And a computer scientist, and a programmer, 549 00:23:57,180 --> 00:24:00,090 more generally it turns out, is going to start counting everything at 0. 550 00:24:00,090 --> 00:24:00,610 >> Why? 551 00:24:00,610 --> 00:24:03,240 Well, it's a little strange that we humans count, generally, 552 00:24:03,240 --> 00:24:04,400 starting from one. 553 00:24:04,400 --> 00:24:08,110 Because what's the smallest number we can clearly represent based 554 00:24:08,110 --> 00:24:09,930 even on our old grade school math? 555 00:24:09,930 --> 00:24:12,400 Well, it was 0, whether it's in decimal or binary. 556 00:24:12,400 --> 00:24:14,900 And so you'll see in the world of computing and programming, 557 00:24:14,900 --> 00:24:17,620 specifically, we start counting everything from 0. 558 00:24:17,620 --> 00:24:19,690 >> So I picked up the phone book step 0. 559 00:24:19,690 --> 00:24:21,924 I'm going to open to the middle of the phone book. 560 00:24:21,924 --> 00:24:23,840 And that's indeed an expression of what I did. 561 00:24:23,840 --> 00:24:25,900 And then step two was look at the names. 562 00:24:25,900 --> 00:24:29,110 Step three is a little different conceptually. 563 00:24:29,110 --> 00:24:30,600 I'm asking myself a question. 564 00:24:30,600 --> 00:24:33,610 If Smith is among the names, I'm going to make a decision. 565 00:24:33,610 --> 00:24:36,550 If he's among the names, then I'm going to call Mike. 566 00:24:36,550 --> 00:24:39,590 And I'm going to make a decision based on that piece of information. 567 00:24:39,590 --> 00:24:44,100 >> However, if not, if Smith is earlier in the book to the left, 568 00:24:44,100 --> 00:24:48,200 I'm going to open to the middle of the left half of the book. 569 00:24:48,200 --> 00:24:51,674 And then here's the cleverness, I'm going to go back to step two. 570 00:24:51,674 --> 00:24:53,590 I'm going to sort of stand on my own shoulders 571 00:24:53,590 --> 00:24:55,110 and just repeat the past work I did. 572 00:24:55,110 --> 00:24:58,062 But the work I have left is less, and less, and less. 573 00:24:58,062 --> 00:24:59,270 But it's still going to work. 574 00:24:59,270 --> 00:25:02,110 But if Mike, instead, is later in the book to the right, 575 00:25:02,110 --> 00:25:04,980 I'm going to open to the middle of the right half of the book, 576 00:25:04,980 --> 00:25:07,240 then go back to step two. 577 00:25:07,240 --> 00:25:09,330 >> But there's actually a fourth scenario. 578 00:25:09,330 --> 00:25:13,336 Mike's either here, or here, or here, or-- 579 00:25:13,336 --> 00:25:14,152 >> STUDENT: Not there. 580 00:25:14,152 --> 00:25:15,110 DAVID MALAN: Not there. 581 00:25:15,110 --> 00:25:18,580 And indeed, if we don't anticipate this fourth and final scenario 582 00:25:18,580 --> 00:25:21,510 our program might be buggy or flawed in some way. 583 00:25:21,510 --> 00:25:25,020 Else, quit in the case that we haven't found Mike at all. 584 00:25:25,020 --> 00:25:27,720 And indeed, if you've ever noticed your computer hanging, or all 585 00:25:27,720 --> 00:25:30,490 of a sudden word or some other program just quits unexpectedly, 586 00:25:30,490 --> 00:25:32,614 and sometimes thee error message is literally that. 587 00:25:32,614 --> 00:25:34,070 This program quit unexpectedly. 588 00:25:34,070 --> 00:25:35,570 It can be for any number of reasons. 589 00:25:35,570 --> 00:25:38,120 But sometimes it's something as simple as this. 590 00:25:38,120 --> 00:25:40,440 The human programmer who wrote that software 591 00:25:40,440 --> 00:25:43,610 didn't realize that, oh, there's a forth thing that can actually happen. 592 00:25:43,610 --> 00:25:46,480 And if you don't write code to capture that fourth scenario, 593 00:25:46,480 --> 00:25:51,342 it is indeed unexpected sometimes what the computer might actually do. 594 00:25:51,342 --> 00:25:53,050 Now let's call out a few of these things. 595 00:25:53,050 --> 00:25:55,465 So in yellow here, I have highlighted terms 596 00:25:55,465 --> 00:25:57,590 that henceforth we're just going to call functions. 597 00:25:57,590 --> 00:26:00,700 Functions in the world of programming are just like actions, 598 00:26:00,700 --> 00:26:01,850 statements of actions. 599 00:26:01,850 --> 00:26:05,720 So pick up, open to, look at, call, open, open, quit. 600 00:26:05,720 --> 00:26:09,350 That's a function, a procedure, an action, any number of synonyms 601 00:26:09,350 --> 00:26:10,184 would work as well. 602 00:26:10,184 --> 00:26:11,850 Now what are these things now in yellow? 603 00:26:11,850 --> 00:26:14,210 If else, if else, if else, these are what 604 00:26:14,210 --> 00:26:16,500 we're going to call conditions in programming, 605 00:26:16,500 --> 00:26:19,270 or branches, decision points, if you will. 606 00:26:19,270 --> 00:26:22,759 But how do you know which fork in the road to take, so to speak? 607 00:26:22,759 --> 00:26:24,550 We need to highlight the terms to the right 608 00:26:24,550 --> 00:26:27,570 there, which are these yes, no questions. 609 00:26:27,570 --> 00:26:29,040 These true false questions. 610 00:26:29,040 --> 00:26:30,880 Smith among names? 611 00:26:30,880 --> 00:26:32,190 Smith earlier in book? 612 00:26:32,190 --> 00:26:33,260 Smith later in book? 613 00:26:33,260 --> 00:26:35,490 These are questions to which there is a yes, or no, 614 00:26:35,490 --> 00:26:42,110 or equivalently true, or false, or equivalently, one or zero answer. 615 00:26:42,110 --> 00:26:44,260 >> And meanwhile there's just one last piece. 616 00:26:44,260 --> 00:26:45,940 This here has what kind of effect? 617 00:26:45,940 --> 00:26:48,230 Whether or not you program before, how would you 618 00:26:48,230 --> 00:26:51,030 describe what step seven and 10 are doing? 619 00:26:51,030 --> 00:26:54,110 620 00:26:54,110 --> 00:26:55,027 What did you say? 621 00:26:55,027 --> 00:26:56,110 STUDENT: A recursive step. 622 00:26:56,110 --> 00:26:56,980 DAVID MALAN: A recursive step. 623 00:26:56,980 --> 00:26:58,000 Yes, essentially. 624 00:26:58,000 --> 00:27:00,384 It's technically iterative here if you're familiar. 625 00:27:00,384 --> 00:27:01,550 But we'll come back to that. 626 00:27:01,550 --> 00:27:03,930 But it's doing something clearly. 627 00:27:03,930 --> 00:27:06,370 Again, it's inducing a cycle, a loop, right. 628 00:27:06,370 --> 00:27:08,770 You're literally going back to some earlier step. 629 00:27:08,770 --> 00:27:12,592 And so indeed, this is going to implement some kind of cycle. 630 00:27:12,592 --> 00:27:15,050 But you're not going to get stuck in this endlessly, right. 631 00:27:15,050 --> 00:27:19,290 Because if you're constantly checking is Mike here, or to the left, or not here, 632 00:27:19,290 --> 00:27:21,360 eventually he's not going to be there. 633 00:27:21,360 --> 00:27:24,590 And you can just quit altogether as per that last line. 634 00:27:24,590 --> 00:27:25,834 >> So that's it for vocabulary. 635 00:27:25,834 --> 00:27:28,250 And this was what we would generally call pseudocode code. 636 00:27:28,250 --> 00:27:29,570 It's not an actual language. 637 00:27:29,570 --> 00:27:32,405 It's just very terse English, but it communicates the point. 638 00:27:32,405 --> 00:27:33,780 There's no formal structure here. 639 00:27:33,780 --> 00:27:35,738 You just use it's few words, but as clear words 640 00:27:35,738 --> 00:27:37,870 as you can to communicate your idea. 641 00:27:37,870 --> 00:27:40,580 >> Now how good is that algorithm and how much better is it? 642 00:27:40,580 --> 00:27:43,570 Well, we don't have to get into the specifics of numbers or anything 643 00:27:43,570 --> 00:27:44,069 like that. 644 00:27:44,069 --> 00:27:46,300 But we can look at the shape of this solution. 645 00:27:46,300 --> 00:27:50,194 So if we just draw some xy plot here on the horizontal axis here. 646 00:27:50,194 --> 00:27:51,860 Let's just call the size of the problem. 647 00:27:51,860 --> 00:27:55,540 And a computer scientist would typically use n as the variable here. 648 00:27:55,540 --> 00:27:59,690 So n pages, or n people in the room, or whatever it is you're trying to count. 649 00:27:59,690 --> 00:28:03,039 >> And then on the vertical axis on the left, that would be the time to solve. 650 00:28:03,039 --> 00:28:05,330 So how many seconds does it take me to find Mike Smith? 651 00:28:05,330 --> 00:28:06,621 Or how many steps does it take? 652 00:28:06,621 --> 00:28:08,100 How many page turns does it take? 653 00:28:08,100 --> 00:28:11,370 So that's how much it costs me in time to solve a problem. 654 00:28:11,370 --> 00:28:15,030 And we might draw the first algorithms slope, if you will, 655 00:28:15,030 --> 00:28:16,910 as just this straight line in red. 656 00:28:16,910 --> 00:28:18,450 And I'll call it n. 657 00:28:18,450 --> 00:28:19,117 >> Why n? 658 00:28:19,117 --> 00:28:20,950 Why is it just this one to one relationship? 659 00:28:20,950 --> 00:28:22,700 Well, if Verizon or whatever phone company 660 00:28:22,700 --> 00:28:25,130 adds one more page to the phone book next year, 661 00:28:25,130 --> 00:28:28,370 that might push Mike one more step closer to the end, 662 00:28:28,370 --> 00:28:29,950 depending on where that page is. 663 00:28:29,950 --> 00:28:32,380 And so the effect might just be to add one more second. 664 00:28:32,380 --> 00:28:33,520 Or one more page turn. 665 00:28:33,520 --> 00:28:34,970 A one to one ratio. 666 00:28:34,970 --> 00:28:37,410 >> By contrast, the second algorithm. 667 00:28:37,410 --> 00:28:41,406 How much faster was that intuitively? 668 00:28:41,406 --> 00:28:42,780 Where I went two pages at a time? 669 00:28:42,780 --> 00:28:43,664 Yeah. 670 00:28:43,664 --> 00:28:44,497 >> STUDENT: [INAUDIBLE] 671 00:28:44,497 --> 00:28:47,255 672 00:28:47,255 --> 00:28:48,080 >> DAVID MALAN: Yeah. 673 00:28:48,080 --> 00:28:49,220 So it's going to be twice as fast. 674 00:28:49,220 --> 00:28:51,344 And we would draw that here depending on the scale. 675 00:28:51,344 --> 00:28:54,220 It still is a straight line, but lower than the red line. 676 00:28:54,220 --> 00:28:56,410 Because for some number of pages, if it takes 677 00:28:56,410 --> 00:28:58,360 you this many steps with the first algorithm, 678 00:28:58,360 --> 00:29:00,570 it's going to take you half as many steps with the second. 679 00:29:00,570 --> 00:29:02,770 And so the yellow line describing the second algorithm 680 00:29:02,770 --> 00:29:03,990 is just going to be below it. 681 00:29:03,990 --> 00:29:07,250 >> But what's really powerful is to think about the third and final, 682 00:29:07,250 --> 00:29:10,480 and amazingly most intuitive algorithm, that has this shape. 683 00:29:10,480 --> 00:29:12,720 Technically we would call this a logarithmic curve. 684 00:29:12,720 --> 00:29:14,309 Log base 2 of n in this case. 685 00:29:14,309 --> 00:29:15,600 But that doesn't really matter. 686 00:29:15,600 --> 00:29:19,140 What matters really is the fundamentally different shape that it has. 687 00:29:19,140 --> 00:29:22,810 And you can consider just how much shorter this line really 688 00:29:22,810 --> 00:29:24,620 is in the long run. 689 00:29:24,620 --> 00:29:25,870 It's constantly increasing. 690 00:29:25,870 --> 00:29:27,620 It doesn't flatten out perfectly. 691 00:29:27,620 --> 00:29:34,030 But it grows ever so much more slowly as the problem gets bigger and bigger. 692 00:29:34,030 --> 00:29:36,710 And you can think of it this way-- if Verizon doesn't just 693 00:29:36,710 --> 00:29:40,410 add one page next year but doubles the number of pages in the phone book, 694 00:29:40,410 --> 00:29:42,740 the first algorithm might take twice as many steps. 695 00:29:42,740 --> 00:29:45,360 If it's 1,000 pages this year, 2,000 pages next year, 696 00:29:45,360 --> 00:29:47,180 Mike might be that much farther away. 697 00:29:47,180 --> 00:29:49,380 So it's 1,000 extra steps to find him. 698 00:29:49,380 --> 00:29:51,610 The second algorithm might be only 500 more 699 00:29:51,610 --> 00:29:55,490 steps to find him because again, I'm flying through it two at a time. 700 00:29:55,490 --> 00:29:56,950 >> But what about the third algorithm? 701 00:29:56,950 --> 00:29:59,010 If Verizon doubles the size of the phone book 702 00:29:59,010 --> 00:30:02,620 next year from 1,000 to 2000 pages, how many more steps 703 00:30:02,620 --> 00:30:05,540 is my third algorithm going to take? 704 00:30:05,540 --> 00:30:06,630 Yeah, it's just one. 705 00:30:06,630 --> 00:30:08,600 And that's the powerful idea. 706 00:30:08,600 --> 00:30:12,780 You can take 1,000 page bite out of that problem at once. 707 00:30:12,780 --> 00:30:14,510 And now if you consider a silly scenario, 708 00:30:14,510 --> 00:30:17,320 but it kind of speaks to the power of this kind of intuition-- 709 00:30:17,320 --> 00:30:21,494 if a phone book had, like, four billion pages, feels like a really big problem. 710 00:30:21,494 --> 00:30:23,410 And indeed, it might take me four billion page 711 00:30:23,410 --> 00:30:26,549 turns to find Mike Smith in that case with the first algorithm. 712 00:30:26,549 --> 00:30:28,840 But how many steps would it take in the third algorithm 713 00:30:28,840 --> 00:30:31,585 to find Mike among four billion pieces of paper? 714 00:30:31,585 --> 00:30:34,865 715 00:30:34,865 --> 00:30:36,240 So four billion you tear in half. 716 00:30:36,240 --> 00:30:37,220 You get two billion. 717 00:30:37,220 --> 00:30:42,810 Then one billion, then 500 million, 250 million, 125 million-- but it 718 00:30:42,810 --> 00:30:44,780 feels like this is going to take a while. 719 00:30:44,780 --> 00:30:47,340 I might need 32 fingers to count up that high. 720 00:30:47,340 --> 00:30:51,340 But it is indeed as few as 32 page tears. 721 00:30:51,340 --> 00:30:54,060 You can go from four billion to one page dividing 722 00:30:54,060 --> 00:30:57,030 the original number of pages in half 32 times 723 00:30:57,030 --> 00:30:59,290 until you're left with just that single page. 724 00:30:59,290 --> 00:31:01,320 >> Now, of course, I'm cheating here. 725 00:31:01,320 --> 00:31:06,470 It's not that we are just being sort of stupid entirely with the first two 726 00:31:06,470 --> 00:31:07,470 algorithms. 727 00:31:07,470 --> 00:31:11,500 I am cheating in some sense, or really I'm leveraging an assumption. 728 00:31:11,500 --> 00:31:15,610 What was true about the phone book in its original form that allowed 729 00:31:15,610 --> 00:31:17,450 me to even use that third algorithm? 730 00:31:17,450 --> 00:31:18,110 Yeah? 731 00:31:18,110 --> 00:31:19,360 AUDIENCE: It was alphabetized. 732 00:31:19,360 --> 00:31:21,130 DAVID MALAN: It was alphabetized, right? 733 00:31:21,130 --> 00:31:23,500 If it were just in random order, this is a waste 734 00:31:23,500 --> 00:31:24,880 of time, this whole conversation. 735 00:31:24,880 --> 00:31:27,500 I have to look at every page if it's in random order 736 00:31:27,500 --> 00:31:30,350 to find Mike Smith before I can conclude he's there or not. 737 00:31:30,350 --> 00:31:32,880 And so the corner we have cut is that I have 738 00:31:32,880 --> 00:31:35,752 assumed that someone else in this case did the work for me. 739 00:31:35,752 --> 00:31:38,460 And so that ultimately invites the question, well, wait a minute. 740 00:31:38,460 --> 00:31:41,284 How do you sort 1,000 pages of names and numbers? 741 00:31:41,284 --> 00:31:43,200 That's actually a different problem, something 742 00:31:43,200 --> 00:31:44,574 we'll come back to in the future. 743 00:31:44,574 --> 00:31:48,130 But when you think about websites like Facebook and Google for Gmail 744 00:31:48,130 --> 00:31:50,450 and things like Google's own search indexes, 745 00:31:50,450 --> 00:31:53,800 when you have millions or billions of pieces of data being stored these days, 746 00:31:53,800 --> 00:31:56,660 searching-- and not to mention sorting those problems-- 747 00:31:56,660 --> 00:31:59,450 is ultimately a challenge unto itself. 748 00:31:59,450 --> 00:32:02,250 And indeed, this then is just one of those challenges 749 00:32:02,250 --> 00:32:03,460 that we'll be looking at. 750 00:32:03,460 --> 00:32:05,590 >> So now let's take a moment and take a look at CS50 751 00:32:05,590 --> 00:32:09,082 itself and give you a sense of what's in store this semester. 752 00:32:09,082 --> 00:32:11,540 Indeed, if you haven't already, do take a look at this URL. 753 00:32:11,540 --> 00:32:13,880 And as Patrick alluded to, this year we're 754 00:32:13,880 --> 00:32:17,130 making a significant investment all the more in the course's support 755 00:32:17,130 --> 00:32:20,170 structure in terms of the TAs and the CAs, office hours, 756 00:32:20,170 --> 00:32:23,520 sections availability, and digital materials online, as well. 757 00:32:23,520 --> 00:32:27,489 Indeed, in terms of the course's lecture, we're here today. 758 00:32:27,489 --> 00:32:29,780 And the expectations this year officially of the course 759 00:32:29,780 --> 00:32:32,370 are attend to today, the course's last lecture, and a course 760 00:32:32,370 --> 00:32:35,161 roughly in the middle of the semester with every lecture in between 761 00:32:35,161 --> 00:32:37,280 made available generally on a Friday afternoon 762 00:32:37,280 --> 00:32:40,240 online, both for Yale students and Harvard students this year. 763 00:32:40,240 --> 00:32:42,090 Indeed, one of the fundamental changes is 764 00:32:42,090 --> 00:32:44,310 that we're adopting at Harvard a paradigm very much 765 00:32:44,310 --> 00:32:46,570 like we did here last year and now this year, 766 00:32:46,570 --> 00:32:50,300 so that similarly, we still film most of the course's lectures in Cambridge 767 00:32:50,300 --> 00:32:52,900 but make them available earlier than we have in the past 768 00:32:52,900 --> 00:32:55,540 so that those of you-- if you would like to, for instance, 769 00:32:55,540 --> 00:32:58,400 get a head start on materials on the the first weekend rather 770 00:32:58,400 --> 00:33:02,000 than the second weekend, you'll have access to these kinds of materials, 771 00:33:02,000 --> 00:33:06,561 searchable, embeddable, hyperlinkable to related resources all the earlier. 772 00:33:06,561 --> 00:33:09,560 In terms of the topics, to give you a sense of the course's trajectory-- 773 00:33:09,560 --> 00:33:12,365 and some of this might be jargon for now, but not for long, rest assured. 774 00:33:12,365 --> 00:33:15,010 We'll start today, ultimately, with looking at one programming 775 00:33:15,010 --> 00:33:16,260 language called Scratch. 776 00:33:16,260 --> 00:33:19,380 We'll transition thereafter next week to something called C 777 00:33:19,380 --> 00:33:22,140 and then looking at other building blocks for solving problems, 778 00:33:22,140 --> 00:33:26,230 things called arrays and algorithms, how we use memory to our advantage 779 00:33:26,230 --> 00:33:28,326 and disadvantage, and things like data structures, 780 00:33:28,326 --> 00:33:31,200 and then toward the tail end of the class looking at machine learning 781 00:33:31,200 --> 00:33:33,410 and looking at another language called Python, 782 00:33:33,410 --> 00:33:37,460 how the web works, how the internet more generally works, protocols like HTTP, 783 00:33:37,460 --> 00:33:40,950 languages for databases like SQL, JavaScript for the web, 784 00:33:40,950 --> 00:33:43,000 and ultimately tying all of those together. 785 00:33:43,000 --> 00:33:44,708 >> And so indeed, at the end of the day, you 786 00:33:44,708 --> 00:33:50,250 will not learn in this class Scratch or C or Python or SQL or JavaScript. 787 00:33:50,250 --> 00:33:53,560 You will instead more generally learn computer science and the foundations 788 00:33:53,560 --> 00:33:55,790 thereof, and you will learn how to program 789 00:33:55,790 --> 00:33:58,800 in any number of these languages along the way. 790 00:33:58,800 --> 00:34:00,970 So indeed, one of the goals of the course in the end 791 00:34:00,970 --> 00:34:04,160 is to take off all of the course's training wheels by those final weeks 792 00:34:04,160 --> 00:34:06,710 so that after this, you can return to your own fields-- 793 00:34:06,710 --> 00:34:08,510 whether that is or is not computer science 794 00:34:08,510 --> 00:34:12,290 or engineering, in the natural sciences, arts, humanities, or beyond-- 795 00:34:12,290 --> 00:34:14,720 and bring some of this course's ideas and this field's 796 00:34:14,720 --> 00:34:17,400 ideas and practical skills to your own domain 797 00:34:17,400 --> 00:34:19,480 in order to solve problems therein. 798 00:34:19,480 --> 00:34:22,990 >> What we'll be doing here meanwhile in most Thursdays after today 799 00:34:22,990 --> 00:34:26,160 is with the course's heads leading what we'll call walkthroughs 800 00:34:26,160 --> 00:34:27,620 of the course's problem sets. 801 00:34:27,620 --> 00:34:29,610 So each week when we have a problem set, we'll 802 00:34:29,610 --> 00:34:32,900 be walking through in a location like this the course's challenges, 803 00:34:32,900 --> 00:34:35,582 offering you some tips and tricks and design techniques. 804 00:34:35,582 --> 00:34:37,540 But if you're not able to make those in person, 805 00:34:37,540 --> 00:34:39,760 realize those same resources will be embedded 806 00:34:39,760 --> 00:34:41,590 by one of the course's teaching assistants 807 00:34:41,590 --> 00:34:43,860 in the problem sets themselves, as well. 808 00:34:43,860 --> 00:34:47,124 >> The problem sets this year, unlike last year, based on feedback, 809 00:34:47,124 --> 00:34:48,540 will still be released on Fridays. 810 00:34:48,540 --> 00:34:51,310 But rather than being due the subsequent Friday, 811 00:34:51,310 --> 00:34:55,079 thereby giving you only seven days, will effectively be due 10 days later. 812 00:34:55,079 --> 00:34:57,620 And indeed, this will mean that they'll overlap by a weekend. 813 00:34:57,620 --> 00:34:59,369 But we hope this year especially this will 814 00:34:59,369 --> 00:35:02,320 allow students to better accommodate ebb and flow in their schedules, 815 00:35:02,320 --> 00:35:05,040 whether it's academics or extracurriculars or athletics 816 00:35:05,040 --> 00:35:06,280 or midterm season. 817 00:35:06,280 --> 00:35:10,060 You can either front-load or back-load your week focusing on CS50 based 818 00:35:10,060 --> 00:35:12,400 on your own week's actual course load. 819 00:35:12,400 --> 00:35:14,990 >> The problem sets themselves will cover a range of languages, 820 00:35:14,990 --> 00:35:17,990 though we'll focus predominantly early on on C 821 00:35:17,990 --> 00:35:23,040 before we focus thereafter on higher level, more web-centric languages. 822 00:35:23,040 --> 00:35:25,970 And then a couple of FAQs here-- should you take a class like CS50 823 00:35:25,970 --> 00:35:26,900 as a first-year? 824 00:35:26,900 --> 00:35:27,970 So absolutely. 825 00:35:27,970 --> 00:35:30,470 And indeed, it's not necessarily something 826 00:35:30,470 --> 00:35:34,440 you should postpone until you've cut your teeth on other types of classes. 827 00:35:34,440 --> 00:35:36,290 But rather, consider that for many students, 828 00:35:36,290 --> 00:35:39,040 myself included back in the day, this is a very unfamiliar field, 829 00:35:39,040 --> 00:35:40,997 especially if you never did take a AP CSA 830 00:35:40,997 --> 00:35:42,580 or something like that in high school. 831 00:35:42,580 --> 00:35:44,705 But realize that early on, whether it's this course 832 00:35:44,705 --> 00:35:47,900 or some other introductory course, now is indeed the best time, 833 00:35:47,900 --> 00:35:52,082 I think, to find some new path or some new academic interest, as well. 834 00:35:52,082 --> 00:35:55,040 And then taking with other courses-- so one of the key differences here 835 00:35:55,040 --> 00:35:57,906 versus Harvard is that we only take four courses per semester 836 00:35:57,906 --> 00:35:59,030 at Harvard for some reason. 837 00:35:59,030 --> 00:36:01,494 And you guys actually pull off some 36 courses in total 838 00:36:01,494 --> 00:36:04,410 over the course of your four years, which means generally four or five 839 00:36:04,410 --> 00:36:05,040 classes. 840 00:36:05,040 --> 00:36:08,367 And I do think it's quite fair to say and to disclaim CS50, by design, is 841 00:36:08,367 --> 00:36:10,700 probably not the type of class that you should typically 842 00:36:10,700 --> 00:36:13,680 take with four other courses for a total of five 843 00:36:13,680 --> 00:36:16,249 because psets are by design fairly intensive. 844 00:36:16,249 --> 00:36:18,040 Indeed, I too learned this back in the day. 845 00:36:18,040 --> 00:36:21,110 I wouldn't describe CS50 and computer science, programming 846 00:36:21,110 --> 00:36:24,477 as so much hard as it is just time-consuming. 847 00:36:24,477 --> 00:36:26,560 It's not the kind of thing where after dinner, you 848 00:36:26,560 --> 00:36:28,310 can go back to your dorm room, sit down, and start 849 00:36:28,310 --> 00:36:29,710 focusing on the pset thinking, all right, 850 00:36:29,710 --> 00:36:31,340 I'm gonna bang this out tonight and then move 851 00:36:31,340 --> 00:36:33,000 on to my next subject the next day. 852 00:36:33,000 --> 00:36:34,450 Sometimes you just hit a wall. 853 00:36:34,450 --> 00:36:35,690 You have bugs in your code. 854 00:36:35,690 --> 00:36:37,900 You don't necessarily know how to solve some problem. 855 00:36:37,900 --> 00:36:41,670 And one of the key features of programming for myself to this day 856 00:36:41,670 --> 00:36:44,480 is you just kind of need to take a step back sometimes, sleep on it 857 00:36:44,480 --> 00:36:47,870 or think on it over the course of a jog or some other activity, 858 00:36:47,870 --> 00:36:49,240 and then come back to it fresh. 859 00:36:49,240 --> 00:36:50,930 And you just need these windows of time. 860 00:36:50,930 --> 00:36:52,910 >> And indeed, that's why we've lengthened the amount of time 861 00:36:52,910 --> 00:36:55,710 available for the problem sets this year and also, per that URL 862 00:36:55,710 --> 00:36:57,950 I put up earlier as to what's new this semester, 863 00:36:57,950 --> 00:37:00,950 trimmed the problem sets so that they're fundamentally no less rigorous, 864 00:37:00,950 --> 00:37:03,741 and the takeaways are no less, but there's a lot less front matter, 865 00:37:03,741 --> 00:37:07,630 a lot less legwork that you need to do at the front of every problem set, 866 00:37:07,630 --> 00:37:10,680 as you'll see, before you can actually dive into the meat of it. 867 00:37:10,680 --> 00:37:13,500 So realize that those and other changes are on the horizon 868 00:37:13,500 --> 00:37:16,490 to better accommodate students, but ultimately to make sure 869 00:37:16,490 --> 00:37:18,860 that the takeaways are indeed as high as possible. 870 00:37:18,860 --> 00:37:21,330 So while more work than it might be in a typical class, 871 00:37:21,330 --> 00:37:25,120 we do hope that the returns for you and the takeaways for you 872 00:37:25,120 --> 00:37:27,490 and the skills and ideas with which you exit 873 00:37:27,490 --> 00:37:29,921 are all the more compelling as a result. 874 00:37:29,921 --> 00:37:32,420 And to get you there-- and this is one of the key takeaways, 875 00:37:32,420 --> 00:37:35,470 as Patrick alluded earlier-- is the course's support structure. 876 00:37:35,470 --> 00:37:39,720 So not only does CS50 have one of the largest course staffs on campus. 877 00:37:39,720 --> 00:37:41,750 It also has one of the most undergraduate. 878 00:37:41,750 --> 00:37:43,700 Indeed, CS50 last year was the first class 879 00:37:43,700 --> 00:37:45,366 to have an undergraduate teaching staff. 880 00:37:45,366 --> 00:37:48,570 And testament to that success do now many other courses within Yale CS 881 00:37:48,570 --> 00:37:49,500 have that, as well. 882 00:37:49,500 --> 00:37:52,906 And for students, specifically, will these TAs and course assistants 883 00:37:52,906 --> 00:37:55,030 be supporting a whole network of support resources, 884 00:37:55,030 --> 00:37:58,250 among them sections or recitations, weekly opportunities 885 00:37:58,250 --> 00:38:01,674 to have more intimate discussions and reviews of material targeted 886 00:38:01,674 --> 00:38:04,590 for different tracks, for students less comfortable, more comfortable, 887 00:38:04,590 --> 00:38:05,720 or somewhere in between. 888 00:38:05,720 --> 00:38:08,886 These will follow the availability of the lectures by several days each week 889 00:38:08,886 --> 00:38:09,970 on Mondays and Tuesdays. 890 00:38:09,970 --> 00:38:11,970 And then office hours-- one-on-one opportunities 891 00:38:11,970 --> 00:38:15,490 for help from the course CAs and TAs will be on Wednesdays and Thursdays 892 00:38:15,490 --> 00:38:18,400 and Sundays at multiple times, all of which 893 00:38:18,400 --> 00:38:22,180 will be posted on the course's website, even more than last year, as well. 894 00:38:22,180 --> 00:38:25,501 >> But what's key to CS50, if not admittedly a bit unusual, 895 00:38:25,501 --> 00:38:27,750 is the course's culture that we've tried to cultivate, 896 00:38:27,750 --> 00:38:30,672 both in Cambridge for many years and now most recently in New Haven. 897 00:38:30,672 --> 00:38:33,130 And in fact, coming up this Saturday, if you haven't heard, 898 00:38:33,130 --> 00:38:36,410 is CS50 Puzzle Day, which has nothing to do with computer science 899 00:38:36,410 --> 00:38:39,430 but is entirely designed to send a message that computer science is 900 00:38:39,430 --> 00:38:40,665 about problem solving. 901 00:38:40,665 --> 00:38:43,540 And indeed, if you'd like to partner with one or two or three friends 902 00:38:43,540 --> 00:38:46,150 and form a team for CS50 Puzzle Day, take a look 903 00:38:46,150 --> 00:38:48,010 at the adverts that are on the way out. 904 00:38:48,010 --> 00:38:51,582 And three hours of pizza and puzzles and prizes await. 905 00:38:51,582 --> 00:38:53,290 And indeed, for the first time this year, 906 00:38:53,290 --> 00:38:54,873 it won't be held jointly with Harvard. 907 00:38:54,873 --> 00:38:57,530 It will be here independently at Yale. 908 00:38:57,530 --> 00:38:59,815 So keep an eye out for those if you haven't. 909 00:38:59,815 --> 00:39:02,440 Most every Friday in the semester do we try to make a big class 910 00:39:02,440 --> 00:39:06,710 feel small and bring some 50 students to lunch with the course's staff, 911 00:39:06,710 --> 00:39:08,730 with alumni, friends from industry to talk 912 00:39:08,730 --> 00:39:12,630 about what life is like after a class like CS50 and over the summers 913 00:39:12,630 --> 00:39:14,250 and after graduation. 914 00:39:14,250 --> 00:39:16,280 So keep an eye out for invitations to that. 915 00:39:16,280 --> 00:39:17,988 For the first time ever this year will we 916 00:39:17,988 --> 00:39:21,420 hold the first ever CS50 coding contest, an optional opt-in opportunity 917 00:39:21,420 --> 00:39:25,580 mid-semester, after all of us have had some six or seven weeks of programming 918 00:39:25,580 --> 00:39:30,100 in C under their belts to compete, if you would so choose-- again 919 00:39:30,100 --> 00:39:32,460 on teams-- trying to solve as many challenges 920 00:39:32,460 --> 00:39:36,160 as you can in programming with friends of yours against others. 921 00:39:36,160 --> 00:39:38,850 >> And toward the tail of the semester will we charter some buses, 922 00:39:38,850 --> 00:39:40,850 actually spend some time in Cambridge, if you'd 923 00:39:40,850 --> 00:39:43,460 like to join us, for the so-called CS50 hackathon. 924 00:39:43,460 --> 00:39:44,600 At 7 PM we'll begin. 925 00:39:44,600 --> 00:39:45,970 Around 9 PM, we'll have pizza. 926 00:39:45,970 --> 00:39:47,650 Around 1:00 AM, we'll have burritos. 927 00:39:47,650 --> 00:39:50,550 And anyone still awake on the bus ride home around 5:00 AM, 928 00:39:50,550 --> 00:39:54,070 we'll stop off for pancakes at IHOP on the way home-- 929 00:39:54,070 --> 00:39:57,540 a 12-hour opportunity to immerse yourself with classmates and staff 930 00:39:57,540 --> 00:39:59,950 in the course's final project, which is an opportunity 931 00:39:59,950 --> 00:40:01,870 to go well beyond the course's problem sets 932 00:40:01,870 --> 00:40:05,950 and design and implement most anything of interest to you, 933 00:40:05,950 --> 00:40:09,170 that will ultimately be featured here in Commons. 934 00:40:09,170 --> 00:40:12,510 The first ever CS50 fair was last year, an end-of-semester exhibition 935 00:40:12,510 --> 00:40:15,460 or celebration of what everyone in the class had accomplished, 936 00:40:15,460 --> 00:40:19,810 especially those, again, who went from nothing to something, from zero to 60, 937 00:40:19,810 --> 00:40:22,450 having no prior background and exhibiting, ultimately, 938 00:40:22,450 --> 00:40:26,960 something for the whole campus and, if online, the world to see, as well. 939 00:40:26,960 --> 00:40:30,780 >> Now, these here are just a few of the TAs and CAs that makes CS50 possible. 940 00:40:30,780 --> 00:40:33,034 Allow me to invite any of those staff members 941 00:40:33,034 --> 00:40:35,700 who are here to come up on stage, as well as the course's heads, 942 00:40:35,700 --> 00:40:38,785 to offer some words of inspiration, as well. 943 00:40:38,785 --> 00:41:03,138 944 00:41:03,138 --> 00:41:03,950 >> ANDI: Hi, guys. 945 00:41:03,950 --> 00:41:05,290 Can you guys hear me? 946 00:41:05,290 --> 00:41:10,260 Thanks for joining us on this lovely, rainy Thursday afternoon. 947 00:41:10,260 --> 00:41:11,010 My name is Andi. 948 00:41:11,010 --> 00:41:12,070 I'm a junior in Berkeley. 949 00:41:12,070 --> 00:41:17,250 And along with Stelios and Summer, we will be your three head teaching 950 00:41:17,250 --> 00:41:19,277 assistants for this upcoming year. 951 00:41:19,277 --> 00:41:21,110 So, I guess, show of hands-- how many of you 952 00:41:21,110 --> 00:41:26,680 have no intention of being a CS major nor really diving deeply 953 00:41:26,680 --> 00:41:29,930 into computer science as a major here? 954 00:41:29,930 --> 00:41:30,520 Awesome. 955 00:41:30,520 --> 00:41:32,730 That's brilliant. 956 00:41:32,730 --> 00:41:35,850 >> So I'm actually a global affairs and cognitive science major. 957 00:41:35,850 --> 00:41:37,780 I literally came to Yale with the intention 958 00:41:37,780 --> 00:41:42,199 of never having to look at a number ever again in my life. 959 00:41:42,199 --> 00:41:44,990 When I came to Yale, this was something that was never on my radar. 960 00:41:44,990 --> 00:41:46,460 I wanted to learn about poetry. 961 00:41:46,460 --> 00:41:48,500 I wanted to learn about international affairs. 962 00:41:48,500 --> 00:41:50,510 I wanted to learn about watercolor drawings. 963 00:41:50,510 --> 00:41:53,360 Yes, we offer a class on watercolor drawings. 964 00:41:53,360 --> 00:41:57,340 >> But I never really was interested in anything STEM related. 965 00:41:57,340 --> 00:41:59,620 But then the older I got, the more I realized 966 00:41:59,620 --> 00:42:03,340 that every field really in some sense employs computer science, 967 00:42:03,340 --> 00:42:05,700 or if not computer science, computation. 968 00:42:05,700 --> 00:42:08,300 In fact, for my global affairs capstone project, 969 00:42:08,300 --> 00:42:12,020 we're using data analytics to analyze terrorist attacks 970 00:42:12,020 --> 00:42:13,680 for Boko Haram in Nigeria. 971 00:42:13,680 --> 00:42:17,510 And so as you can see, regardless of what major you end up pursuing 972 00:42:17,510 --> 00:42:21,640 or what your interests here at Yale are, programming and the foundations 973 00:42:21,640 --> 00:42:24,130 of whatever skills are super useful. 974 00:42:24,130 --> 00:42:29,840 And CS50 really is well equipped to kind of lend a lot of its resources 975 00:42:29,840 --> 00:42:32,060 to you, regardless of how comfortable you are 976 00:42:32,060 --> 00:42:34,590 or how interested you are in pursuing the class. 977 00:42:34,590 --> 00:42:37,290 >> Summer's going to talk a little bit about what you guys are 978 00:42:37,290 --> 00:42:39,635 going to learn about this year. 979 00:42:39,635 --> 00:42:40,510 SUMMER: Hi, everyone. 980 00:42:40,510 --> 00:42:41,320 I'm Summer Wu. 981 00:42:41,320 --> 00:42:43,090 I'm a junior in Morse. 982 00:42:43,090 --> 00:42:48,100 And I actually started out as a CS50 student myself. 983 00:42:48,100 --> 00:42:51,460 So three years ago, I was on a gap year. 984 00:42:51,460 --> 00:42:53,940 I'd never taken a CS class in high school, 985 00:42:53,940 --> 00:42:57,800 but I thought that in my free time, it'd be cool to learn how to code. 986 00:42:57,800 --> 00:43:02,610 So I did a quick Google search, looked for what was available online, 987 00:43:02,610 --> 00:43:06,990 and saw this video with muppets and DJs and cool websites. 988 00:43:06,990 --> 00:43:09,450 I was like, I want to learn how to do that. 989 00:43:09,450 --> 00:43:14,690 >> So I took the course, and I just fell in love with it. 990 00:43:14,690 --> 00:43:20,410 But I remember being so jealous of the kids who could attend the hackathon, 991 00:43:20,410 --> 00:43:24,610 attend Puzzle Day, attend office hours, get help from TAs in person. 992 00:43:24,610 --> 00:43:27,410 And so I never imagined that I'd get the chance 993 00:43:27,410 --> 00:43:30,640 to be here involved in the course that first got 994 00:43:30,640 --> 00:43:33,630 me interested in computer science and is the reason why 995 00:43:33,630 --> 00:43:35,690 I'm a computer science major today. 996 00:43:35,690 --> 00:43:39,290 So I'll warn you, this class is going to stretch you. 997 00:43:39,290 --> 00:43:41,120 It's going to challenge you. 998 00:43:41,120 --> 00:43:43,910 But it's also going to teach you how to do things 999 00:43:43,910 --> 00:43:45,506 that you never imagined you could. 1000 00:43:45,506 --> 00:43:49,330 1001 00:43:49,330 --> 00:43:52,160 >> STELIOS: Hi, everyone. 1002 00:43:52,160 --> 00:43:53,510 My name is Stelios. 1003 00:43:53,510 --> 00:43:58,240 I am a junior in Branford College and a CS major. 1004 00:43:58,240 --> 00:44:01,640 I'm also from Athens, Greece. 1005 00:44:01,640 --> 00:44:03,830 I'm really looking forward to meeting all of you, 1006 00:44:03,830 --> 00:44:09,010 chatting with you at section, at office hours, at Friday lunches. 1007 00:44:09,010 --> 00:44:11,250 I'm really excited because we've put so much effort 1008 00:44:11,250 --> 00:44:14,650 into creating a unique support structure for all of you 1009 00:44:14,650 --> 00:44:19,170 to make your experience with the course the best possible. 1010 00:44:19,170 --> 00:44:22,640 And I hope that although most of you have probably not taken a CS 1011 00:44:22,640 --> 00:44:27,310 course before, I hope that's CS50 for you is what sparks interest 1012 00:44:27,310 --> 00:44:30,260 to further pursue computer science in the future, 1013 00:44:30,260 --> 00:44:33,270 as it has done with so many people in the past. 1014 00:44:33,270 --> 00:44:36,740 So thank you for being here, excited to see you. 1015 00:44:36,740 --> 00:44:38,487 Jason Hirschhorn. 1016 00:44:38,487 --> 00:44:39,820 JASON HIRSCHHORN: Hi, everybody. 1017 00:44:39,820 --> 00:44:41,700 My name is Jason Hirschhorn. 1018 00:44:41,700 --> 00:44:43,050 I live in Silliman. 1019 00:44:43,050 --> 00:44:46,910 And I went to Harvard as an undergrad and majored in social studies 1020 00:44:46,910 --> 00:44:48,870 and minored in computer science. 1021 00:44:48,870 --> 00:44:53,100 And one of my principal roles here is to support this wonderful staff 1022 00:44:53,100 --> 00:44:54,630 as they support you all. 1023 00:44:54,630 --> 00:44:56,410 In fact, this is not all of them. 1024 00:44:56,410 --> 00:45:01,230 There are 55 undergraduates and graduates here to support you all. 1025 00:45:01,230 --> 00:45:04,420 And I daresay one of the best parts of the course for you 1026 00:45:04,420 --> 00:45:08,080 all is getting to work with them, getting to know them, 1027 00:45:08,080 --> 00:45:12,389 getting to see them, both in CS50 and outside of CS50 this semester 1028 00:45:12,389 --> 00:45:13,680 and for many semesters to come. 1029 00:45:13,680 --> 00:45:16,770 So hopefully you'll take the course because hopefully you 1030 00:45:16,770 --> 00:45:21,060 get to interact with the wonderful staff we have on stage. 1031 00:45:21,060 --> 00:45:24,977 >> SPEAKER: Well, let me finish by saying it will be fun. 1032 00:45:24,977 --> 00:45:26,810 DAVID MALAN: Well, thanks to our whole team. 1033 00:45:26,810 --> 00:45:29,610 Allow me to dim the lights and allow some more of our team, 1034 00:45:29,610 --> 00:45:32,890 both from Cambridge and New Haven, to say hello as these guys file off. 1035 00:45:32,890 --> 00:45:36,130 And after that will we transition to the first of our programming engagements 1036 00:45:36,130 --> 00:45:37,584 with this language called Scratch. 1037 00:45:37,584 --> 00:45:38,500 So thanks to the team. 1038 00:45:38,500 --> 00:45:40,770 Let's dim the lights and hear from a few others. 1039 00:45:40,770 --> 00:45:44,207 >> [APPLAUSE] 1040 00:45:44,207 --> 00:45:45,680 1041 00:45:45,680 --> 00:45:48,140 >> [VIDEO PLAYBACK] 1042 00:45:48,140 --> 00:45:53,210 >> -The mission of CS50 is to make you more comfortable with a totally new way 1043 00:45:53,210 --> 00:45:54,947 of thinking, this computational mindset. 1044 00:45:54,947 --> 00:45:56,780 -It made computer science interesting, which 1045 00:45:56,780 --> 00:46:00,241 is something I didn't really realize was possible until I took the class. 1046 00:46:00,241 --> 00:46:00,990 -I was like, whoa. 1047 00:46:00,990 --> 00:46:04,120 I'm really translating my thoughts into a computer right now. 1048 00:46:04,120 --> 00:46:07,970 >> -Even if you don't have any background in computer science or any experience, 1049 00:46:07,970 --> 00:46:10,140 this is actually the class for you. 1050 00:46:10,140 --> 00:46:12,250 >> -So I definitely want my students to just 1051 00:46:12,250 --> 00:46:14,350 get excited about computer science. 1052 00:46:14,350 --> 00:46:17,187 Not just programming, but thinking like a computer scientist 1053 00:46:17,187 --> 00:46:19,270 is really what I want to try to teach my freshman. 1054 00:46:19,270 --> 00:46:21,560 >> -CS50 is hard and rewarding. 1055 00:46:21,560 --> 00:46:22,592 >> -An experience. 1056 00:46:22,592 --> 00:46:23,456 >> -Extravaganza. 1057 00:46:23,456 --> 00:46:26,350 >> -It's bringing us to the next level. 1058 00:46:26,350 --> 00:46:28,850 >> [MUSIC PLAYING] 1059 00:46:28,850 --> 00:46:32,167 >> -The TFs are, I think, the lifeblood of the course. 1060 00:46:32,167 --> 00:46:34,560 >> -I'm excited to have my students I'm helping 1061 00:46:34,560 --> 00:46:38,027 have that aha moment to realize what they're actually trying 1062 00:46:38,027 --> 00:46:39,610 to do, to figure out how to do a pset. 1063 00:46:39,610 --> 00:46:41,438 >> -CS50's definitely a hard course. 1064 00:46:41,438 --> 00:46:43,960 But unlike any other course really at Yale, 1065 00:46:43,960 --> 00:46:45,759 it has such a great, supportive community. 1066 00:46:45,759 --> 00:46:47,550 -You absolutely don't need to know anything 1067 00:46:47,550 --> 00:46:49,341 about coding to be able to take the course. 1068 00:46:49,341 --> 00:46:52,270 -It's amazing to watch how far people come in one semester. 1069 00:46:52,270 --> 00:46:55,610 >> -You weren't alone sitting in your room learning to code, 1070 00:46:55,610 --> 00:46:57,170 but it was more than just a class. 1071 00:46:57,170 --> 00:46:58,044 It was an experience. 1072 00:46:58,044 --> 00:47:02,500 -The best way to learn concepts and to process them is by teaching others. 1073 00:47:02,500 --> 00:47:04,033 >> -What is the telephone split? 1074 00:47:04,033 --> 00:47:06,934 >> [MUSIC PLAYING] 1075 00:47:06,934 --> 00:47:08,080 >> -And this is CS50. 1076 00:47:08,080 --> 00:47:10,810 >> [MUSIC PLAYING] 1077 00:47:10,810 --> 00:47:11,720 1078 00:47:11,720 --> 00:47:12,380 >> -This is CS50. 1079 00:47:12,380 --> 00:47:13,446 >> -Got a problem? 1080 00:47:13,446 --> 00:47:14,852 Tear it in half. 1081 00:47:14,852 --> 00:47:15,804 >> [MUSIC PLAYING] 1082 00:47:15,804 --> 00:47:18,184 >> Throw it away. 1083 00:47:18,184 --> 00:47:19,520 >> DAVID MALAN: All right. 1084 00:47:19,520 --> 00:47:23,190 So let's tackle-- in a little bit, incidentally, it's 1085 00:47:23,190 --> 00:47:25,270 been this tradition for some reason for 10 years 1086 00:47:25,270 --> 00:47:27,260 to serve cake at the start and the end of CS50. 1087 00:47:27,260 --> 00:47:30,800 So awaiting you at the end of today, in addition to syllabi, 1088 00:47:30,800 --> 00:47:34,270 will be some cake as well, and the course's staff to say hello. 1089 00:47:34,270 --> 00:47:37,110 But now, let's transition to the first of our languages, where 1090 00:47:37,110 --> 00:47:40,970 we'll spend really just a week and one problem set on this domain, Scratch. 1091 00:47:40,970 --> 00:47:43,160 And you'll find if you've programmed before, many 1092 00:47:43,160 --> 00:47:46,280 of the ideas and the possibilities are familiar to you. 1093 00:47:46,280 --> 00:47:48,160 But you'll find that it's fun along the way 1094 00:47:48,160 --> 00:47:51,201 to figure out exactly how to translate some of the ideas you already know 1095 00:47:51,201 --> 00:47:53,852 to this particular environment to really impress your family 1096 00:47:53,852 --> 00:47:57,060 and friends with your work, which can go online, if you so choose, afterward. 1097 00:47:57,060 --> 00:47:58,851 >> And if you have no prior experience and are 1098 00:47:58,851 --> 00:48:01,540 among the majority of students less comfortable, 1099 00:48:01,540 --> 00:48:05,320 realize that many of the ideas we just explored with reality-- things 1100 00:48:05,320 --> 00:48:07,970 like phone books and attendance and so forth-- translate 1101 00:48:07,970 --> 00:48:12,280 fairly nicely to a computer, but not if you use, 1102 00:48:12,280 --> 00:48:13,710 initially, a language like this. 1103 00:48:13,710 --> 00:48:16,290 So this is a program written in a language called C. 1104 00:48:16,290 --> 00:48:18,590 And we'll spend quite a bit of time in C, ultimately. 1105 00:48:18,590 --> 00:48:22,560 But odds are, this will look a bit cryptic to you at first glance. 1106 00:48:22,560 --> 00:48:25,760 In fact, there's a lot of weird syntax, parentheses, angle brackets, 1107 00:48:25,760 --> 00:48:27,422 curly braces, quotes, and semicolons. 1108 00:48:27,422 --> 00:48:29,880 And indeed, if you dive into programming for the first time 1109 00:48:29,880 --> 00:48:33,420 looking at and trying to create stuff like this, honestly, you get so mired 1110 00:48:33,420 --> 00:48:36,500 so often in just stupid minutia that has nothing 1111 00:48:36,500 --> 00:48:38,240 intellectually interesting about it. 1112 00:48:38,240 --> 00:48:40,980 >> But imagine if you could create this same program-- which, 1113 00:48:40,980 --> 00:48:46,200 as you might kind of infer, probably prints "Hello, world" somehow or other. 1114 00:48:46,200 --> 00:48:49,850 We can distill that same idea into just two puzzle pieces, if you will. 1115 00:48:49,850 --> 00:48:52,850 Indeed, Scratch is interesting because it's this graphical language. 1116 00:48:52,850 --> 00:48:56,110 You can drag and drop these puzzle pieces that only interlock 1117 00:48:56,110 --> 00:48:57,940 if it makes logical sense to do so. 1118 00:48:57,940 --> 00:48:59,830 And so in Scratch, we'll soon see, this is 1119 00:48:59,830 --> 00:49:03,460 how you would implement that same program, with just two puzzle pieces 1120 00:49:03,460 --> 00:49:05,420 that pretty much do what they say. 1121 00:49:05,420 --> 00:49:08,870 >> But we'll see in just a moment that some of the building blocks that we alluded 1122 00:49:08,870 --> 00:49:12,140 to earlier and a few more are all that ultimately are going to constitute 1123 00:49:12,140 --> 00:49:13,460 some of our earliest programs. 1124 00:49:13,460 --> 00:49:15,460 We're going to have things like functions-- just 1125 00:49:15,460 --> 00:49:18,034 actions that do something, like say hello, world. 1126 00:49:18,034 --> 00:49:20,200 We're going to have loops, things that induce cycles 1127 00:49:20,200 --> 00:49:23,210 again and again, just like we did a moment ago with searching 1128 00:49:23,210 --> 00:49:24,110 for Mike Smith. 1129 00:49:24,110 --> 00:49:27,190 Variables, like in algebra, if you have x or y, that can store a number. 1130 00:49:27,190 --> 00:49:29,940 Well, in a program, you can actually store more than just numbers. 1131 00:49:29,940 --> 00:49:34,290 You can store words and sentences and graphics and other things still. 1132 00:49:34,290 --> 00:49:37,530 Boolean expressions, just questions-- yes or no, true or false. 1133 00:49:37,530 --> 00:49:40,680 Conditions, making decisions based on those yes/no answers. 1134 00:49:40,680 --> 00:49:43,890 >> And then fancier things like array and threads and events 1135 00:49:43,890 --> 00:49:46,100 and any number of other features, but all of which 1136 00:49:46,100 --> 00:49:48,670 map very nicely to very friendly blocks like this. 1137 00:49:48,670 --> 00:49:52,736 This is going to be a function, a purple puzzle piece that just says 1138 00:49:52,736 --> 00:49:54,717 what its name is-- in this case, say. 1139 00:49:54,717 --> 00:49:56,550 And then often, there's a white box that you 1140 00:49:56,550 --> 00:49:58,550 can type in or drag some value into. 1141 00:49:58,550 --> 00:50:01,370 And that's what's generally called an argument or a parameter. 1142 00:50:01,370 --> 00:50:04,110 It's a way of altering the default behavior of a puzzle 1143 00:50:04,110 --> 00:50:07,530 piece or a function so that it does something custom for you like saying, 1144 00:50:07,530 --> 00:50:12,570 hello, world or hello, Andy or hello, Jason or some other sentence instead. 1145 00:50:12,570 --> 00:50:15,830 >> If you want to say that a lot-- literally forever-- 1146 00:50:15,830 --> 00:50:18,142 you can take another puzzle piece called forever 1147 00:50:18,142 --> 00:50:20,100 and just sandwiched the two together like this. 1148 00:50:20,100 --> 00:50:24,090 And that loop, as the picture suggests, means just say hello, world forever, 1149 00:50:24,090 --> 00:50:25,810 again and again and again. 1150 00:50:25,810 --> 00:50:28,840 Or, if you only want to do it a finite number of times, like 50 times, 1151 00:50:28,840 --> 00:50:32,050 there's going to be another puzzle piece for that-- repeat 50 times. 1152 00:50:32,050 --> 00:50:34,190 >> Meanwhile, if you want to have a variable 1153 00:50:34,190 --> 00:50:36,090 in this language we're about to play with, 1154 00:50:36,090 --> 00:50:37,880 you can use a orange block like this. 1155 00:50:37,880 --> 00:50:40,750 And this variable I arbitrarily called i for integer. 1156 00:50:40,750 --> 00:50:42,290 And I just set it equal to 0. 1157 00:50:42,290 --> 00:50:44,780 And so maybe i, in this case-- this variable-- 1158 00:50:44,780 --> 00:50:46,630 represents someone's score in a game. 1159 00:50:46,630 --> 00:50:49,680 You start at zero, and every time you make a goal or something like that, 1160 00:50:49,680 --> 00:50:51,270 you get one additional point. 1161 00:50:51,270 --> 00:50:52,830 >> You can ask questions in Scratch. 1162 00:50:52,830 --> 00:50:55,390 If we drag and drop puzzle pieces in a moment like this, 1163 00:50:55,390 --> 00:50:58,470 you can ask questions like, well, is i less than 50? 1164 00:50:58,470 --> 00:51:00,060 Maybe you need 50 points to win. 1165 00:51:00,060 --> 00:51:01,893 And so this would be the question you'd ask. 1166 00:51:01,893 --> 00:51:04,030 Or, more generally, you could say is x less than y, 1167 00:51:04,030 --> 00:51:05,780 where there's two variables involved? 1168 00:51:05,780 --> 00:51:08,320 Now, this one is a lot bigger at first glance, 1169 00:51:08,320 --> 00:51:11,470 but really not all that more complex. 1170 00:51:11,470 --> 00:51:15,390 >> This is just a combination of conditions and variables 1171 00:51:15,390 --> 00:51:19,370 and Boolean expressions to ask three questions-- is x less than y? 1172 00:51:19,370 --> 00:51:20,660 If so, say so. 1173 00:51:20,660 --> 00:51:22,170 Say, x is less than y. 1174 00:51:22,170 --> 00:51:26,571 Else, if x is greater than y, else x must be equal to y. 1175 00:51:26,571 --> 00:51:29,070 And whereas with Mike Smith, there were four scenarios, here 1176 00:51:29,070 --> 00:51:32,270 in the world of numbers, x is either less than, greater than, or equal to. 1177 00:51:32,270 --> 00:51:34,531 All we have are three forks in the road. 1178 00:51:34,531 --> 00:51:36,530 And then there's fancier puzzle pieces like this 1179 00:51:36,530 --> 00:51:39,613 for things like arrays, where we're going to be able to store information. 1180 00:51:39,613 --> 00:51:43,590 We're going to see blocks that allow us to implement multiple threads, 1181 00:51:43,590 --> 00:51:46,620 another feature we'll use, and then also something called events. 1182 00:51:46,620 --> 00:51:49,390 But before we get to that point and create even, 1183 00:51:49,390 --> 00:51:52,000 ultimately, our own custom puzzle pieces, let's 1184 00:51:52,000 --> 00:51:53,950 actually open the program itself. 1185 00:51:53,950 --> 00:51:54,860 >> So this is Scratch. 1186 00:51:54,860 --> 00:51:57,490 It's available at scratch.mit.edu. 1187 00:51:57,490 --> 00:51:59,650 And you're welcome to play now or later, as well. 1188 00:51:59,650 --> 00:52:01,330 This happens to be the offline version. 1189 00:52:01,330 --> 00:52:03,129 For people who don't necessarily have great internet, 1190 00:52:03,129 --> 00:52:04,962 you can download the same software, as well. 1191 00:52:04,962 --> 00:52:07,460 And there's really only three components to this software. 1192 00:52:07,460 --> 00:52:10,860 On the top left-hand corner of the screen is the sort of stage 1193 00:52:10,860 --> 00:52:13,800 that Scratch, who by default looks like a cat, lives inside. 1194 00:52:13,800 --> 00:52:16,799 He can move up, down, left, and right and do any number of other things, 1195 00:52:16,799 --> 00:52:20,520 and can look any number of ways based on the costumes that you assign to him. 1196 00:52:20,520 --> 00:52:22,980 But this is what we'll call a sprite, a sort of character. 1197 00:52:22,980 --> 00:52:25,429 And you can have multiple characters, as we'll soon see. 1198 00:52:25,429 --> 00:52:30,060 >> In the middle now are all these puzzle pieces and these categories or pallets 1199 00:52:30,060 --> 00:52:30,900 thereof. 1200 00:52:30,900 --> 00:52:32,429 So right now, I clicked on Motion. 1201 00:52:32,429 --> 00:52:35,900 And so I'm seeing all of the motion-related puzzle pieces or blocks, 1202 00:52:35,900 --> 00:52:37,950 so functions that have to do with going up, 1203 00:52:37,950 --> 00:52:39,950 down, left, or right or some other operation. 1204 00:52:39,950 --> 00:52:43,790 But if I clicked on Looks, you could see things like the say block 1205 00:52:43,790 --> 00:52:45,084 that we saw just a moment ago. 1206 00:52:45,084 --> 00:52:48,250 And if I click on Control, you'll see things like the repeat and the forever 1207 00:52:48,250 --> 00:52:50,410 and the if block that we saw a moment ago. 1208 00:52:50,410 --> 00:52:51,670 >> And so you'll find that we'll just scratch 1209 00:52:51,670 --> 00:52:53,750 the surface of some of the puzzle pieces together, 1210 00:52:53,750 --> 00:52:55,833 but it's all fairly intuitive and point and click. 1211 00:52:55,833 --> 00:52:58,219 Indeed, Scratch was designed for younger students 1212 00:52:58,219 --> 00:53:00,730 to help give them an outlet for creative thinking. 1213 00:53:00,730 --> 00:53:03,040 And yet wonderfully, it's a wonderful stepping stone 1214 00:53:03,040 --> 00:53:07,020 to exactly the ideas we're going to explore in C and Python and JavaScript, 1215 00:53:07,020 --> 00:53:07,719 as well. 1216 00:53:07,719 --> 00:53:11,960 >> On the right-hand side, finally, here is this, the so-called scripts area. 1217 00:53:11,960 --> 00:53:15,750 And this is just the blank slate with which you begin to write a program. 1218 00:53:15,750 --> 00:53:16,897 And I'll exactly that. 1219 00:53:16,897 --> 00:53:19,980 Now, I happen to know where things are because I've done this a few times. 1220 00:53:19,980 --> 00:53:22,710 But I know that under the Events category, 1221 00:53:22,710 --> 00:53:25,520 there's this block here-- when green flag clicked. 1222 00:53:25,520 --> 00:53:28,790 And notice if I zoom out and back in over here on the stage, 1223 00:53:28,790 --> 00:53:31,190 Scratch lives within this little rectangular world, 1224 00:53:31,190 --> 00:53:33,920 atop which is a green flag and a red stop sign. 1225 00:53:33,920 --> 00:53:36,180 So go and stop, respectively. 1226 00:53:36,180 --> 00:53:38,710 >> And so what do I want to do when that green flag is clicked? 1227 00:53:38,710 --> 00:53:40,900 Well, let me go to that Looks category. 1228 00:53:40,900 --> 00:53:43,357 And let me go ahead and drag and drop this. 1229 00:53:43,357 --> 00:53:45,940 And notice as soon as it gets close, they're sort of magnetic. 1230 00:53:45,940 --> 00:53:48,489 So if I now let go, it snaps together nice and cleanly. 1231 00:53:48,489 --> 00:53:51,030 And I'm going to go ahead and say something like hello, world 1232 00:53:51,030 --> 00:53:52,190 for two seconds. 1233 00:53:52,190 --> 00:53:56,730 Let me zoom out and click now the green flag, and say, hello, world. 1234 00:53:56,730 --> 00:53:57,230 All right. 1235 00:53:57,230 --> 00:53:58,460 So that's all fine and good. 1236 00:53:58,460 --> 00:53:59,900 Not all that exciting. 1237 00:53:59,900 --> 00:54:01,340 Let's make it a little cuter. 1238 00:54:01,340 --> 00:54:03,494 And I know that in advance, Scratch happens 1239 00:54:03,494 --> 00:54:05,160 to come with some cute things like this. 1240 00:54:05,160 --> 00:54:07,720 So play sound meow until done. 1241 00:54:07,720 --> 00:54:09,531 So let's do this. 1242 00:54:09,531 --> 00:54:10,380 >> [MEOW] 1243 00:54:10,380 --> 00:54:11,819 >> Aw, that's adorable. 1244 00:54:11,819 --> 00:54:12,860 And if I click it again-- 1245 00:54:12,860 --> 00:54:14,920 >> [MEOW] 1246 00:54:14,920 --> 00:54:15,460 >> And again. 1247 00:54:15,460 --> 00:54:16,740 >> [MEOW] 1248 00:54:16,740 --> 00:54:18,760 >> But I keep having to reanimate Scratch. 1249 00:54:18,760 --> 00:54:20,010 But I can do better than this. 1250 00:54:20,010 --> 00:54:23,060 Why don't I just drag three of these. 1251 00:54:23,060 --> 00:54:24,821 And now it's three times as adorable. 1252 00:54:24,821 --> 00:54:26,264 >> [MEOWING] 1253 00:54:26,264 --> 00:54:28,190 >> OK, actually, it's a little creepy. 1254 00:54:28,190 --> 00:54:31,020 So we need something in between there. 1255 00:54:31,020 --> 00:54:33,870 If I go to Control, it looks like there's actually a wait block. 1256 00:54:33,870 --> 00:54:36,994 And so notice if I hover over there-- and let me make this a little bigger. 1257 00:54:36,994 --> 00:54:38,780 If I hover, it's going to snap into place. 1258 00:54:38,780 --> 00:54:41,660 So wait one second, wait one second. 1259 00:54:41,660 --> 00:54:43,170 Let's hit green flag again. 1260 00:54:43,170 --> 00:54:46,330 >> [MEOWING] 1261 00:54:46,330 --> 00:54:47,695 1262 00:54:47,695 --> 00:54:50,660 >> OK, a little more natural, but not very efficient. 1263 00:54:50,660 --> 00:54:54,300 So this is correct if my program's goal was meow three times. 1264 00:54:54,300 --> 00:54:56,410 But it's not very well-designed. 1265 00:54:56,410 --> 00:54:57,740 I kind of cut some corners. 1266 00:54:57,740 --> 00:54:58,730 I got a little lazy. 1267 00:54:58,730 --> 00:55:05,620 What feels like-- what do I seem to have done poorly, would you say? 1268 00:55:05,620 --> 00:55:07,197 Yeah? 1269 00:55:07,197 --> 00:55:08,030 Yeah, in the middle. 1270 00:55:08,030 --> 00:55:11,208 1271 00:55:11,208 --> 00:55:13,083 AUDIENCE: Used more memory than you needed to 1272 00:55:13,083 --> 00:55:15,005 because you're using so many different line. 1273 00:55:15,005 --> 00:55:16,380 DAVID MALAN: Yeah, so more lines. 1274 00:55:16,380 --> 00:55:19,190 And it wouldn't necessarily be memory, though it could be seen as that way. 1275 00:55:19,190 --> 00:55:20,898 But it's definitely-- there's redundancy. 1276 00:55:20,898 --> 00:55:23,440 And I literally kind of dragged and dropped the same things. 1277 00:55:23,440 --> 00:55:26,564 And if you kind of extrapolate-- if it's not obvious here-- well, how would 1278 00:55:26,564 --> 00:55:27,910 I meow 30 times? 1279 00:55:27,910 --> 00:55:31,450 I would drag and drop, like, 30 more pairs of puzzle pieces. 1280 00:55:31,450 --> 00:55:32,890 And surely, there's a better way. 1281 00:55:32,890 --> 00:55:34,056 And we've seen a better way. 1282 00:55:34,056 --> 00:55:36,870 What intuitively would be the better way? 1283 00:55:36,870 --> 00:55:37,890 Yeah, just use a loop. 1284 00:55:37,890 --> 00:55:38,810 No copy and paste. 1285 00:55:38,810 --> 00:55:40,790 And indeed, anytime this semester if you start 1286 00:55:40,790 --> 00:55:43,890 finding yourself dragging and dropping, or really copying and pasting, 1287 00:55:43,890 --> 00:55:47,050 dangerous habit to get into because this is just not very maintainable. 1288 00:55:47,050 --> 00:55:49,740 For instance, if I want to change the sound to something else, 1289 00:55:49,740 --> 00:55:52,826 I have to change it now in three locations instead of just one. 1290 00:55:52,826 --> 00:55:54,575 Because indeed, if I break this away-- I'm 1291 00:55:54,575 --> 00:55:56,170 just going to decouple it like that. 1292 00:55:56,170 --> 00:56:01,900 Let me grab a repeat block, and then click three, type three, 1293 00:56:01,900 --> 00:56:04,015 throw some of these away by just letting go. 1294 00:56:04,015 --> 00:56:05,890 And then notice it doesn't look like it fits, 1295 00:56:05,890 --> 00:56:08,139 but magnetically, it's going to not only snap in place 1296 00:56:08,139 --> 00:56:09,510 but grow to fit the shape. 1297 00:56:09,510 --> 00:56:10,310 So that's good. 1298 00:56:10,310 --> 00:56:11,530 And now if I click play. 1299 00:56:11,530 --> 00:56:13,870 >> [MEOWING] 1300 00:56:13,870 --> 00:56:14,370 1301 00:56:14,370 --> 00:56:15,620 Very nice. 1302 00:56:15,620 --> 00:56:16,126 All right. 1303 00:56:16,126 --> 00:56:18,500 And now it's very easy to change, too, because I can just 1304 00:56:18,500 --> 00:56:20,670 change one number in one place. 1305 00:56:20,670 --> 00:56:22,500 But this, too, is not all that interesting. 1306 00:56:22,500 --> 00:56:25,350 Let's actually have Scratch not meow, but move. 1307 00:56:25,350 --> 00:56:32,680 Let me go to Motion and move 10 steps inside of-- whoops, let me fix this. 1308 00:56:32,680 --> 00:56:37,460 Let me have it move 10 steps-- actually, let's not do repeat. 1309 00:56:37,460 --> 00:56:40,670 Let me grab a control block, and do the following forever. 1310 00:56:40,670 --> 00:56:42,720 Forever, move 10 steps. 1311 00:56:42,720 --> 00:56:45,070 And click Play. 1312 00:56:45,070 --> 00:56:45,600 >> OK. 1313 00:56:45,600 --> 00:56:46,740 So thankfully, he stops. 1314 00:56:46,740 --> 00:56:49,710 Otherwise, kids would get very upset when they sort of lose their cat. 1315 00:56:49,710 --> 00:56:52,720 But at least I can drag him back into the screen. 1316 00:56:52,720 --> 00:56:56,177 But this is not all that great of a game or animation. 1317 00:56:56,177 --> 00:56:58,260 It would be nice if maybe he bounced off the edge. 1318 00:56:58,260 --> 00:57:00,020 So what do we do? 1319 00:57:00,020 --> 00:57:04,302 What construct do we need to have Scratch decide to bounce, do you think, 1320 00:57:04,302 --> 00:57:06,010 even if you've never seen Scratch before? 1321 00:57:06,010 --> 00:57:06,593 Yeah, in back. 1322 00:57:06,593 --> 00:57:08,359 AUDIENCE: You need an if block or if-then. 1323 00:57:08,359 --> 00:57:10,650 DAVID MALAN: Yeah, so some kind of if block or if-then. 1324 00:57:10,650 --> 00:57:12,275 So actually, we have one of these here. 1325 00:57:12,275 --> 00:57:14,500 So if-- so let me get rid of the movement. 1326 00:57:14,500 --> 00:57:16,070 Let me zoom in so it's bigger. 1327 00:57:16,070 --> 00:57:16,890 So how about this. 1328 00:57:16,890 --> 00:57:21,920 Forever, if Sensing-- we've not seen this before. 1329 00:57:21,920 --> 00:57:23,160 I need a Boolean expression. 1330 00:57:23,160 --> 00:57:25,970 And it turns out if touching what? 1331 00:57:25,970 --> 00:57:29,030 If touching the edge, what do I want to do? 1332 00:57:29,030 --> 00:57:32,030 Well, if I go back to Motion, turns out, oh, I can turn around. 1333 00:57:32,030 --> 00:57:33,350 Let me drag this in here. 1334 00:57:33,350 --> 00:57:36,430 Why don't I go ahead and turn around 180 degrees? 1335 00:57:36,430 --> 00:57:38,190 >> And now, let me just move at the end. 1336 00:57:38,190 --> 00:57:40,500 I could put the movement at the beginning or the end. 1337 00:57:40,500 --> 00:57:44,452 But logically, every time I move, I want to check, am I touching the edge? 1338 00:57:44,452 --> 00:57:45,410 Am I touching the edge? 1339 00:57:45,410 --> 00:57:46,490 Am I touching the edge? 1340 00:57:46,490 --> 00:57:49,200 So that logically I turn around if so. 1341 00:57:49,200 --> 00:57:51,190 So let's hit play. 1342 00:57:51,190 --> 00:57:52,030 >> OK. 1343 00:57:52,030 --> 00:57:53,910 So it's slightly buggy, so to speak. 1344 00:57:53,910 --> 00:57:56,560 And a bug is just a mistake in a computer program. 1345 00:57:56,560 --> 00:57:57,800 But at least it's working. 1346 00:57:57,800 --> 00:57:59,420 And in fact, I can go in here. 1347 00:57:59,420 --> 00:58:03,130 And let me make it not 10 steps at a time, but this is all animation is. 1348 00:58:03,130 --> 00:58:05,310 This is all a cartoon or even a movie is. 1349 00:58:05,310 --> 00:58:07,110 Let me move 20 steps at a time. 1350 00:58:07,110 --> 00:58:11,200 So 20 times as many things are happening once, or twice as many, in this case. 1351 00:58:11,200 --> 00:58:12,600 And he's moving faster. 1352 00:58:12,600 --> 00:58:15,150 Let me change to 30. 1353 00:58:15,150 --> 00:58:17,450 100. 1354 00:58:17,450 --> 00:58:19,406 1,000. 1355 00:58:19,406 --> 00:58:20,530 And it's going really fast. 1356 00:58:20,530 --> 00:58:22,190 And this is-- yeah, OK. 1357 00:58:22,190 --> 00:58:24,130 >> So now we're just messing with it. 1358 00:58:24,130 --> 00:58:24,954 OK, so buggy. 1359 00:58:24,954 --> 00:58:26,620 But we can drag him out of the way here. 1360 00:58:26,620 --> 00:58:28,286 But we can make more fun with this, too. 1361 00:58:28,286 --> 00:58:30,710 How about this-- he's upside down. 1362 00:58:30,710 --> 00:58:32,800 But it turns out Scratch-- and there is actually, 1363 00:58:32,800 --> 00:58:35,510 I have to disclaim, no academic value to what I'm about to do. 1364 00:58:35,510 --> 00:58:40,200 But if I open up the microphone, let's stop him and do something like this. 1365 00:58:40,200 --> 00:58:41,960 Ouch! 1366 00:58:41,960 --> 00:58:42,884 >> [LAUGH] 1367 00:58:42,884 --> 00:58:45,200 1368 00:58:45,200 --> 00:58:45,990 >> That was adorable. 1369 00:58:45,990 --> 00:58:46,740 Thank you. 1370 00:58:46,740 --> 00:58:50,850 Now, this is what my voice looks like when I yell ouch. 1371 00:58:50,850 --> 00:58:52,630 I don't think we caught your laughter. 1372 00:58:52,630 --> 00:58:53,280 That's OK. 1373 00:58:53,280 --> 00:58:56,550 Let me save this as "ouch." 1374 00:58:56,550 --> 00:58:57,915 Let's save this as "ouch". 1375 00:58:57,915 --> 00:58:59,410 And now we'll go back to Scripts. 1376 00:58:59,410 --> 00:59:01,660 And now I need-- let's see, Sound. 1377 00:59:01,660 --> 00:59:03,160 Oh, play sound ouch. 1378 00:59:03,160 --> 00:59:08,180 So if I'm touching the edge, let me first play ouch, and then turn around. 1379 00:59:08,180 --> 00:59:10,191 And now let's put him in the middle. 1380 00:59:10,191 --> 00:59:14,754 >> [SAYING "OUCH"] 1381 00:59:14,754 --> 00:59:15,740 >> Twice as fast. 1382 00:59:15,740 --> 00:59:20,660 1383 00:59:20,660 --> 00:59:21,830 >> OK. 1384 00:59:21,830 --> 00:59:23,780 But it's literally doing what I'm saying. 1385 00:59:23,780 --> 00:59:27,580 So it is in fact correct, it's just a little annoying quickly. 1386 00:59:27,580 --> 00:59:30,330 So let's add something more interesting to this. 1387 00:59:30,330 --> 00:59:32,950 Let me actually open up one that I made in advance, 1388 00:59:32,950 --> 00:59:38,560 aptly called Pet the Cat, that does this. 1389 00:59:38,560 --> 00:59:40,340 Here's the script up here. 1390 00:59:40,340 --> 00:59:44,510 What is this going to do in English terms? 1391 00:59:44,510 --> 00:59:45,820 What's this designed to do? 1392 00:59:45,820 --> 00:59:47,900 Yeah, let's go some-- yeah? 1393 00:59:47,900 --> 00:59:49,665 >> AUDIENCE: When you pet the cat, it meows. 1394 00:59:49,665 --> 00:59:52,290 DAVID MALAN: Yeah, so when you pet the cat, it's going to meow. 1395 00:59:52,290 --> 00:59:55,452 So in other words, there's now a forever loop still, combined 1396 00:59:55,452 --> 00:59:57,660 with a condition, combined with a Boolean expression, 1397 00:59:57,660 --> 01:00:00,140 combined with a couple of functions, the effect 1398 01:00:00,140 --> 01:00:02,610 of which, once I play this program, is nothing 1399 01:00:02,610 --> 01:00:06,820 happens until I move the cursor closer and closer and closer and-- 1400 01:00:06,820 --> 01:00:08,029 >> [MEOW] 1401 01:00:08,029 --> 01:00:09,320 Then it's like petting the cat. 1402 01:00:09,320 --> 01:00:11,210 [MEOW] 1403 01:00:11,210 --> 01:00:14,270 Only once you actually move the cursor over him. 1404 01:00:14,270 --> 01:00:19,964 Now, I also whipped up don't pet the cat, which does this instead. 1405 01:00:19,964 --> 01:00:21,350 >> [MEOWING] 1406 01:00:21,350 --> 01:00:23,485 >> So he's just constantly meowing. 1407 01:00:23,485 --> 01:00:24,455 >> [MEOWING] 1408 01:00:24,455 --> 01:00:27,705 >> But if I get too close-- 1409 01:00:27,705 --> 01:00:29,645 >> [MEOWING] 1410 01:00:29,645 --> 01:00:32,080 >> [ROAR] 1411 01:00:32,080 --> 01:00:33,590 >> So how does this work? 1412 01:00:33,590 --> 01:00:35,880 Now I just have a two-way fork in the road. 1413 01:00:35,880 --> 01:00:38,930 If touching mouse pointer, then play the lion sound. 1414 01:00:38,930 --> 01:00:41,950 Else just play the meow sound, and then wait three seconds so 1415 01:00:41,950 --> 01:00:43,880 that it's kind of doing it very tranquilly. 1416 01:00:43,880 --> 01:00:44,380 All right. 1417 01:00:44,380 --> 01:00:47,290 So that's combining some more ideas still. 1418 01:00:47,290 --> 01:00:50,870 Let's take a look at this example I whipped up called threads. 1419 01:00:50,870 --> 01:00:54,020 And this one is fundamentally different in that it leverages 1420 01:00:54,020 --> 01:00:56,070 a feature of many programming language called 1421 01:00:56,070 --> 01:00:59,970 threads, the ability of a program to literally do two things simultaneously. 1422 01:00:59,970 --> 01:01:03,600 Indeed, these days if you're using Google Docs or Microsoft Word, 1423 01:01:03,600 --> 01:01:09,620 and your document's constantly being spell-checked even as you type-- or you 1424 01:01:09,620 --> 01:01:11,580 hit Command-P or Control-P and print something, 1425 01:01:11,580 --> 01:01:13,380 it's printing while you continue typing. 1426 01:01:13,380 --> 01:01:16,680 Programs today can indeed do multiple things at once, just like in Scratch 1427 01:01:16,680 --> 01:01:17,180 here. 1428 01:01:17,180 --> 01:01:20,400 >> So here, I have two sprites now, a bird and a cat. 1429 01:01:20,400 --> 01:01:22,780 And if I click on each of those characters one at a time, 1430 01:01:22,780 --> 01:01:25,590 I see right now the bird's scripts at top right. 1431 01:01:25,590 --> 01:01:27,270 Now I see the cat's. 1432 01:01:27,270 --> 01:01:28,540 Bird's, cat's. 1433 01:01:28,540 --> 01:01:30,270 So each of them have their own script. 1434 01:01:30,270 --> 01:01:32,700 But notice, what puzzle piece do they both begin with? 1435 01:01:32,700 --> 01:01:34,260 When green flag clicked. 1436 01:01:34,260 --> 01:01:36,890 And bird, when green flag clicked. 1437 01:01:36,890 --> 01:01:40,870 So when I click the green flag, both of those scripts or programs 1438 01:01:40,870 --> 01:01:42,759 are going to run in parallel. 1439 01:01:42,759 --> 01:01:45,800 And you'll notice that the bird is just mindlessly bouncing off the edge. 1440 01:01:45,800 --> 01:01:50,890 The cat clearly has been programmed with a strategic advantage. 1441 01:01:50,890 --> 01:01:52,704 And-- 1442 01:01:52,704 --> 01:01:53,490 >> [ROAR] 1443 01:01:53,490 --> 01:01:53,821 1444 01:01:53,821 --> 01:01:54,320 All right. 1445 01:01:54,320 --> 01:01:57,340 So the cat caught the bird in this case. 1446 01:01:57,340 --> 01:01:58,390 Why is that? 1447 01:01:58,390 --> 01:02:03,310 Well, notice first we just have the bird just mindlessly going 1448 01:02:03,310 --> 01:02:05,120 to this initial location, and then forever, 1449 01:02:05,120 --> 01:02:06,774 if not touching the cat, just move. 1450 01:02:06,774 --> 01:02:08,190 And if you're on the edge, bounce. 1451 01:02:08,190 --> 01:02:08,870 And just move. 1452 01:02:08,870 --> 01:02:10,286 And if you're on the edge, bounce. 1453 01:02:10,286 --> 01:02:12,840 But the cat, meanwhile, has some additional logic 1454 01:02:12,840 --> 01:02:18,250 that says this-- first, just so that this isn't completely biased 1455 01:02:18,250 --> 01:02:21,191 against the bird, notice that I've used a green puzzle piece there 1456 01:02:21,191 --> 01:02:22,690 that actually picks a random number. 1457 01:02:22,690 --> 01:02:26,179 A feature of many languages is to give you random or pseudorandom numbers. 1458 01:02:26,179 --> 01:02:29,220 So in this case, the cat initially chooses a random number between, like, 1459 01:02:29,220 --> 01:02:31,727 90 degrees and 180 degrees, essentially, so 1460 01:02:31,727 --> 01:02:33,310 that there's a little bit of variance. 1461 01:02:33,310 --> 01:02:37,000 And then forever, if touching the bird, play the lion sound. 1462 01:02:37,000 --> 01:02:38,754 Otherwise, just point toward the bird. 1463 01:02:38,754 --> 01:02:39,670 Point toward the bird. 1464 01:02:39,670 --> 01:02:44,199 Point toward the bird, which is a puzzle piece unto itself in this case. 1465 01:02:44,199 --> 01:02:45,740 Well, we can do one other thing here. 1466 01:02:45,740 --> 01:02:49,820 Let me open up the events program here. 1467 01:02:49,820 --> 01:02:53,520 And here we again have two sprites, which look like these two puppets here. 1468 01:02:53,520 --> 01:02:55,710 And what's interesting here is this. 1469 01:02:55,710 --> 01:02:59,140 The orange guy has this set of puzzle pieces here. 1470 01:02:59,140 --> 01:03:01,700 Forever do the following-- if the space bar is pressed, 1471 01:03:01,700 --> 01:03:05,430 then say, Marco, and then broadcast an event. 1472 01:03:05,430 --> 01:03:09,460 And meanwhile, the blue guy here has this-- when you receive the event, 1473 01:03:09,460 --> 01:03:10,540 say Polo. 1474 01:03:10,540 --> 01:03:12,850 So it turns out in Scratch and in other languages, 1475 01:03:12,850 --> 01:03:15,830 there are ways for two programs or two scripts, in this case, 1476 01:03:15,830 --> 01:03:20,310 to intercommunicate so that when I hit the space bar, he says Marco. 1477 01:03:20,310 --> 01:03:23,539 And the other one hears that, so to speak, and says Polo in response. 1478 01:03:23,539 --> 01:03:26,080 So you can write programs that actually interact in this way. 1479 01:03:26,080 --> 01:03:28,630 And if I do this one instead, I can even add variables, 1480 01:03:28,630 --> 01:03:31,287 just using one sprite in this case. 1481 01:03:31,287 --> 01:03:32,578 This one's especially annoying. 1482 01:03:32,578 --> 01:03:36,174 >> [SEAL BARKING] 1483 01:03:36,174 --> 01:03:37,100 1484 01:03:37,100 --> 01:03:42,490 >> Now, notice on the right we've got some additional logic over here. 1485 01:03:42,490 --> 01:03:45,146 How do I stop this seal from barking? 1486 01:03:45,146 --> 01:03:48,320 >> [SEAL BARKING] 1487 01:03:48,320 --> 01:03:52,830 1488 01:03:52,830 --> 01:03:55,630 >> It looks like on the right-hand side is what's playing the sound. 1489 01:03:55,630 --> 01:03:58,500 But it's only playing a sound if what is true? 1490 01:03:58,500 --> 01:04:03,390 If a variable-- orange block-- muted is zero. 1491 01:04:03,390 --> 01:04:07,916 How do I change muted to be 1, meaning true, make this muted? 1492 01:04:07,916 --> 01:04:12,455 Apparently, the other script, I can hit the space bar, and now he stops. 1493 01:04:12,455 --> 01:04:15,080 So we can have this intercommunication across scripts, as well, 1494 01:04:15,080 --> 01:04:18,349 by just sharing a variable across the two like this. 1495 01:04:18,349 --> 01:04:19,890 Now, this isn't all that interesting. 1496 01:04:19,890 --> 01:04:24,360 Let's go ahead and do this and combine a lot of these ideas with this program 1497 01:04:24,360 --> 01:04:25,940 here. 1498 01:04:25,940 --> 01:04:28,100 Before we do that, though, how about one volunteer? 1499 01:04:28,100 --> 01:04:30,558 Let me take the pressure off of me because I don't actually 1500 01:04:30,558 --> 01:04:31,280 play this game. 1501 01:04:31,280 --> 01:04:33,030 Let's have someone we haven't seen before. 1502 01:04:33,030 --> 01:04:36,420 You have to be comfortable coming up on stage here, on camera. 1503 01:04:36,420 --> 01:04:37,430 OK, come on up. 1504 01:04:37,430 --> 01:04:38,130 Very brave. 1505 01:04:38,130 --> 01:04:39,052 What's your name? 1506 01:04:39,052 --> 01:04:39,962 >> IDRIS: Idris. 1507 01:04:39,962 --> 01:04:40,753 DAVID MALAN: Sorry? 1508 01:04:40,753 --> 01:04:41,196 IDRIS: Idris. 1509 01:04:41,196 --> 01:04:42,670 DAVID MALAN: Idris, nice to meet you. 1510 01:04:42,670 --> 01:04:43,170 Come on up. 1511 01:04:43,170 --> 01:04:45,630 And now, on your own mobile phone, do you play Pokemon GO? 1512 01:04:45,630 --> 01:04:46,567 >> IDRIS: No. 1513 01:04:46,567 --> 01:04:47,400 DAVID MALAN: Really? 1514 01:04:47,400 --> 01:04:48,104 IDRIS: Yeah. 1515 01:04:48,104 --> 01:04:48,770 DAVID MALAN: OK. 1516 01:04:48,770 --> 01:04:49,020 All right. 1517 01:04:49,020 --> 01:04:49,978 Well, nice to meet you. 1518 01:04:49,978 --> 01:04:50,820 Come on over. 1519 01:04:50,820 --> 01:04:51,950 I don't either. 1520 01:04:51,950 --> 01:04:55,380 So we'll figure out together how to play this, which someone actually 1521 01:04:55,380 --> 01:05:00,140 went and implemented in Scratch by changing the cat to essentially 1522 01:05:00,140 --> 01:05:02,260 different characters all together. 1523 01:05:02,260 --> 01:05:04,870 And if I fullscreen this here, we're going 1524 01:05:04,870 --> 01:05:06,860 to see the following game together. 1525 01:05:06,860 --> 01:05:09,560 Still loading, still loading. 1526 01:05:09,560 --> 01:05:10,270 Come on. 1527 01:05:10,270 --> 01:05:12,590 Let me do this. 1528 01:05:12,590 --> 01:05:14,520 Come on. 1529 01:05:14,520 --> 01:05:17,200 This game is so big that it crashed. 1530 01:05:17,200 --> 01:05:18,980 Stand by. 1531 01:05:18,980 --> 01:05:22,390 Try this once more. 1532 01:05:22,390 --> 01:05:23,710 Come on. 1533 01:05:23,710 --> 01:05:24,211 All right. 1534 01:05:24,211 --> 01:05:26,840 1535 01:05:26,840 --> 01:05:27,430 >> There we go. 1536 01:05:27,430 --> 01:05:27,929 OK. 1537 01:05:27,929 --> 01:05:29,330 Green flag. 1538 01:05:29,330 --> 01:05:30,190 So here we go. 1539 01:05:30,190 --> 01:05:30,950 >> [MUSIC PLAYING] 1540 01:05:30,950 --> 01:05:32,510 >> Choose the middle level here. 1541 01:05:32,510 --> 01:05:34,200 Click the blue guy there. 1542 01:05:34,200 --> 01:05:34,700 All right. 1543 01:05:34,700 --> 01:05:37,860 And you can use the arrow keys-- up, down, left, right. 1544 01:05:37,860 --> 01:05:42,150 Now, let's consider as we do this-- and then go after the character there. 1545 01:05:42,150 --> 01:05:42,650 Yep. 1546 01:05:42,650 --> 01:05:45,786 And now click him with the mouse. 1547 01:05:45,786 --> 01:05:46,693 Oh, yeah. 1548 01:05:46,693 --> 01:05:47,193 Move. 1549 01:05:47,193 --> 01:05:47,662 Where's the arrow? 1550 01:05:47,662 --> 01:05:48,131 Here you go. 1551 01:05:48,131 --> 01:05:48,600 So click on there. 1552 01:05:48,600 --> 01:05:48,840 Yeah. 1553 01:05:48,840 --> 01:05:49,340 All right. 1554 01:05:49,340 --> 01:05:56,008 So now, I'm told you have a Poke ball, that if click it, it will do that. 1555 01:05:56,008 --> 01:05:57,932 Very good. 1556 01:05:57,932 --> 01:06:00,390 In practicing for today, I found this version of the game's 1557 01:06:00,390 --> 01:06:01,760 actually not very hard. 1558 01:06:01,760 --> 01:06:07,650 So if you want to go again here, walk down to this Poke ball. 1559 01:06:07,650 --> 01:06:08,780 And then go take a right. 1560 01:06:08,780 --> 01:06:11,200 Try clicking on it. 1561 01:06:11,200 --> 01:06:13,120 Oh, actually, that's the store, apparently. 1562 01:06:13,120 --> 01:06:14,170 OK so close that. 1563 01:06:14,170 --> 01:06:15,150 Never done that before. 1564 01:06:15,150 --> 01:06:16,566 Maybe go up to this thing up here. 1565 01:06:16,566 --> 01:06:17,460 Oh, there you go. 1566 01:06:17,460 --> 01:06:18,910 Wait, there's one over there. 1567 01:06:18,910 --> 01:06:20,412 Oh, there's another. 1568 01:06:20,412 --> 01:06:21,285 OK. 1569 01:06:21,285 --> 01:06:21,785 Down. 1570 01:06:21,785 --> 01:06:23,210 Yeah, click. 1571 01:06:23,210 --> 01:06:24,635 >> OK, that's very cute. 1572 01:06:24,635 --> 01:06:27,485 1573 01:06:27,485 --> 01:06:28,810 OK, very well done. 1574 01:06:28,810 --> 01:06:30,010 This game is not very hard. 1575 01:06:30,010 --> 01:06:30,510 OK. 1576 01:06:30,510 --> 01:06:32,150 Congratulations. 1577 01:06:32,150 --> 01:06:34,720 Here, we have a CS50 stress ball for you. 1578 01:06:34,720 --> 01:06:37,680 But consider for just a moment what some of the takeaways are there. 1579 01:06:37,680 --> 01:06:39,263 Easier than the real game, apparently. 1580 01:06:39,263 --> 01:06:41,809 But all we have going on here is a character 1581 01:06:41,809 --> 01:06:44,100 that probably has some kind of loop associated with it. 1582 01:06:44,100 --> 01:06:44,590 It's not a cat. 1583 01:06:44,590 --> 01:06:45,860 It's this character instead. 1584 01:06:45,860 --> 01:06:49,052 And that loop is just constantly saying, if up arrow pressed, 1585 01:06:49,052 --> 01:06:51,260 if down arrow pressed, if left arrow pressed or right 1586 01:06:51,260 --> 01:06:53,960 arrow pressed, move up or down or left or right. 1587 01:06:53,960 --> 01:06:57,870 Or if there's another puzzle piece there that says when touching another sprite, 1588 01:06:57,870 --> 01:07:01,320 when touching one of the characters to the Poke ball, if touching, 1589 01:07:01,320 --> 01:07:02,440 then do this. 1590 01:07:02,440 --> 01:07:04,800 >> So all of the ideas we've been using thus far really 1591 01:07:04,800 --> 01:07:09,130 can just be applied in this particular context to play this game, as well. 1592 01:07:09,130 --> 01:07:13,580 Let me go ahead and pull up one other here, in fact. 1593 01:07:13,580 --> 01:07:17,060 Let me go ahead and pull up, let's say, this. 1594 01:07:17,060 --> 01:07:18,540 This is something we remixed. 1595 01:07:18,540 --> 01:07:20,329 Made by one of our students in Cambridge, 1596 01:07:20,329 --> 01:07:23,370 and then I went through and changed pretty much every instance of Harvard 1597 01:07:23,370 --> 01:07:25,580 to Yale this time. 1598 01:07:25,580 --> 01:07:27,870 Would someone like to compete against the Ivies 1599 01:07:27,870 --> 01:07:31,650 here in another accumulation of all of these ideas? 1600 01:07:31,650 --> 01:07:32,662 Come on down, yes. 1601 01:07:32,662 --> 01:07:33,370 What's your name? 1602 01:07:33,370 --> 01:07:34,190 >> DINA: Dina. 1603 01:07:34,190 --> 01:07:35,015 >> DAVID MALAN: Adina? 1604 01:07:35,015 --> 01:07:35,380 >> DINA: Dina. 1605 01:07:35,380 --> 01:07:36,410 >> DAVID MALAN: Dina, come on down. 1606 01:07:36,410 --> 01:07:37,320 All right, Dina. 1607 01:07:37,320 --> 01:07:40,780 So this game gets harder and harder, because in this game, 1608 01:07:40,780 --> 01:07:43,970 there's variables being used as well that are constantly keeping track 1609 01:07:43,970 --> 01:07:45,930 of what level you are in the game. 1610 01:07:45,930 --> 01:07:47,120 So nice to meet you. 1611 01:07:47,120 --> 01:07:48,250 Come around here. 1612 01:07:48,250 --> 01:07:51,460 And so the goal here is to sort of make your way through a maze 1613 01:07:51,460 --> 01:07:52,710 that this student implemented. 1614 01:07:52,710 --> 01:07:55,334 >> And just to set the stage, each of these pictures on the screen 1615 01:07:55,334 --> 01:07:57,222 is its own sprite, its own character. 1616 01:07:57,222 --> 01:07:59,680 So these were by default cats, but the student changed them 1617 01:07:59,680 --> 01:08:01,480 to the various Ivies logos here. 1618 01:08:01,480 --> 01:08:04,370 And then you'll see that just by using conditions and loops 1619 01:08:04,370 --> 01:08:06,848 and functions and more, you get this. 1620 01:08:06,848 --> 01:08:07,478 >> [MUSIC PLAYING] 1621 01:08:07,478 --> 01:08:09,228 [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1622 01:08:09,228 --> 01:08:13,060 1623 01:08:13,060 --> 01:08:14,018 >> Yeah, OK. 1624 01:08:14,018 --> 01:08:17,371 1625 01:08:17,371 --> 01:08:20,110 Yeah, keep going. 1626 01:08:20,110 --> 01:08:21,180 First level's very easy. 1627 01:08:21,180 --> 01:08:22,554 You've just got to go over there. 1628 01:08:22,554 --> 01:08:25,644 But again, consider, this is just a loop listening for the arrow keys-- 1629 01:08:25,644 --> 01:08:26,560 up, down, left, right. 1630 01:08:26,560 --> 01:08:28,320 And now a sensing block. 1631 01:08:28,320 --> 01:08:29,345 Very nice. 1632 01:08:29,345 --> 01:08:32,600 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1633 01:08:32,600 --> 01:08:40,340 1634 01:08:40,340 --> 01:08:41,288 >> Very nice. 1635 01:08:41,288 --> 01:08:44,550 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1636 01:08:44,550 --> 01:08:55,540 1637 01:08:55,540 --> 01:08:56,430 >> Very nice. 1638 01:08:56,430 --> 01:08:57,975 Pretty easy, Crimson. 1639 01:08:57,975 --> 01:08:59,060 All right. 1640 01:08:59,060 --> 01:09:00,250 Levels-- uh-oh. 1641 01:09:00,250 --> 01:09:02,380 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1642 01:09:02,380 --> 01:09:04,980 1643 01:09:04,980 --> 01:09:07,150 >> And again, in these three Harvard crests, 1644 01:09:07,150 --> 01:09:10,334 you just have logic saying if on edge, bounce. 1645 01:09:10,334 --> 01:09:13,238 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1646 01:09:13,238 --> 01:09:14,690 1647 01:09:14,690 --> 01:09:17,651 >> OK, what you're doing is more interesting than why. 1648 01:09:17,651 --> 01:09:18,150 Very nice. 1649 01:09:18,150 --> 01:09:18,810 Very nice. 1650 01:09:18,810 --> 01:09:20,270 Uh-oh. 1651 01:09:20,270 --> 01:09:23,350 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1652 01:09:23,350 --> 01:09:26,005 1653 01:09:26,005 --> 01:09:27,630 I think you have to sacrifice yourself. 1654 01:09:27,630 --> 01:09:30,372 [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1655 01:09:30,372 --> 01:09:30,872 Quick! 1656 01:09:30,872 --> 01:09:34,848 1657 01:09:34,848 --> 01:09:38,824 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1658 01:09:38,824 --> 01:09:44,288 1659 01:09:44,288 --> 01:09:44,788 Nice. 1660 01:09:44,788 --> 01:09:52,240 1661 01:09:52,240 --> 01:09:52,740 That's OK. 1662 01:09:52,740 --> 01:09:53,770 You'll get it. 1663 01:09:53,770 --> 01:09:56,304 Yes, yes! 1664 01:09:56,304 --> 01:09:58,256 Very nice. 1665 01:09:58,256 --> 01:10:01,184 >> [CHEERING] 1666 01:10:01,184 --> 01:10:02,160 1667 01:10:02,160 --> 01:10:05,576 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1668 01:10:05,576 --> 01:10:09,480 1669 01:10:09,480 --> 01:10:10,940 >> Nice! 1670 01:10:10,940 --> 01:10:14,370 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1671 01:10:14,370 --> 01:10:39,050 1672 01:10:39,050 --> 01:10:39,550 Got it. 1673 01:10:39,550 --> 01:10:41,510 Come on! 1674 01:10:41,510 --> 01:10:43,470 Second to last level. 1675 01:10:43,470 --> 01:10:46,900 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1676 01:10:46,900 --> 01:10:49,588 1677 01:10:49,588 --> 01:10:50,580 >> All right. 1678 01:10:50,580 --> 01:10:54,052 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1679 01:10:54,052 --> 01:11:00,992 1680 01:11:00,992 --> 01:11:01,492 Yes. 1681 01:11:01,492 --> 01:11:06,230 1682 01:11:06,230 --> 01:11:08,020 Good use of variables here. 1683 01:11:08,020 --> 01:11:09,770 [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1684 01:11:09,770 --> 01:11:10,770 Yes. 1685 01:11:10,770 --> 01:11:14,743 [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1686 01:11:14,743 --> 01:11:16,707 1687 01:11:16,707 --> 01:11:17,689 Nice. 1688 01:11:17,689 --> 01:11:21,126 [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1689 01:11:21,126 --> 01:11:23,581 1690 01:11:23,581 --> 01:11:24,570 It's OK. 1691 01:11:24,570 --> 01:11:25,770 We got to get to the end. 1692 01:11:25,770 --> 01:11:26,270 There. 1693 01:11:26,270 --> 01:11:27,010 Oh! 1694 01:11:27,010 --> 01:11:29,980 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1695 01:11:29,980 --> 01:11:32,160 1696 01:11:32,160 --> 01:11:34,866 >> Might run late today, but it's gonna be worth it. 1697 01:11:34,866 --> 01:11:38,200 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1698 01:11:38,200 --> 01:11:39,640 1699 01:11:39,640 --> 01:11:42,520 >> You can do it! 1700 01:11:42,520 --> 01:11:43,480 Yeah! 1701 01:11:43,480 --> 01:11:46,278 >> [CHEERING] 1702 01:11:46,278 --> 01:11:47,230 1703 01:11:47,230 --> 01:11:50,086 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1704 01:11:50,086 --> 01:11:51,470 >> This one's really hard. 1705 01:11:51,470 --> 01:11:54,070 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1706 01:11:54,070 --> 01:11:57,458 1707 01:11:57,458 --> 01:11:59,000 >> We'll give you two more lives. 1708 01:11:59,000 --> 01:11:59,968 Can you do it? 1709 01:11:59,968 --> 01:12:03,356 >> [MUSIC - MC HAMMER, "U CAN'T TOUCH THIS"] 1710 01:12:03,356 --> 01:12:06,744 1711 01:12:06,744 --> 01:12:07,244 >> All right. 1712 01:12:07,244 --> 01:12:09,160 How about a big round of applause nonetheless. 1713 01:12:09,160 --> 01:12:10,800 You got to the second to last level. 1714 01:12:10,800 --> 01:12:11,723 Thank you. 1715 01:12:11,723 --> 01:12:14,964 >> [APPLAUSE] 1716 01:12:14,964 --> 01:12:15,890 1717 01:12:15,890 --> 01:12:19,600 >> So this is only to say how much you can do with these kinds of things. 1718 01:12:19,600 --> 01:12:21,892 And realize, too, that when puzzle pieces don't exist-- 1719 01:12:21,892 --> 01:12:24,891 and indeed, this is going to be one of the powers with the first problem 1720 01:12:24,891 --> 01:12:27,080 sets and beyond-- is to actually create your own. 1721 01:12:27,080 --> 01:12:28,860 And this is just a snippet of one of the examples 1722 01:12:28,860 --> 01:12:30,230 you'll be able to play with online, where 1723 01:12:30,230 --> 01:12:33,380 if you don't have built into Scratch something like a cough puzzle piece, 1724 01:12:33,380 --> 01:12:35,470 you can actually make it yourself. 1725 01:12:35,470 --> 01:12:37,387 >> And so all of this and more awaits. 1726 01:12:37,387 --> 01:12:39,470 And just to paint a final picture of indeed what's 1727 01:12:39,470 --> 01:12:43,120 ahead in store for the class for you, based on some pictures from classmates 1728 01:12:43,120 --> 01:12:46,970 past, allow me to dim the lights one last time and show you CS50. 1729 01:12:46,970 --> 01:12:49,580 1730 01:12:49,580 --> 01:12:53,038 >> [MUSIC PLAYING] 1731 01:12:53,038 --> 01:14:38,210 1732 01:14:38,210 --> 01:14:38,860 >> All right. 1733 01:14:38,860 --> 01:14:41,540 That's it for CS50. 1734 01:14:41,540 --> 01:14:44,964 Cake is now served. 1735 01:14:44,964 --> 01:14:50,610 1736 01:14:50,610 --> 01:14:53,960 >> [MUSIC PLAYING] 1737 01:14:53,960 --> 01:15:07,624