1 00:00:00,000 --> 00:00:10,980 >> [MUSIC PLAYING] 2 00:00:10,980 --> 00:00:13,260 >> -Alright! 3 00:00:13,260 --> 00:00:16,400 >> -This is CS50. 4 00:00:16,400 --> 00:00:18,220 >> -This is CS50. 5 00:00:18,220 --> 00:00:19,324 >> -This is CS50. 6 00:00:19,324 --> 00:00:20,615 [MUSIC -- IGGY AZALEA, "FANCY"] 7 00:00:20,615 --> 00:00:29,925 8 00:00:29,925 --> 00:00:33,570 >> -My favorite memory from CS50 was when I went to Puzzle Day. 9 00:00:33,570 --> 00:00:35,797 >> -Probably just the time spent working on problem sets 10 00:00:35,797 --> 00:00:38,630 with my friends and people who wold eventually become my blockmates. 11 00:00:38,630 --> 00:00:40,421 >> -My best memory from CS50 is the Hackathon. 12 00:00:40,421 --> 00:00:41,630 -The CS50 Hackathon. 13 00:00:41,630 --> 00:00:42,130 >> -Hackathon. 14 00:00:42,130 --> 00:00:42,800 >> -Hackathon. 15 00:00:42,800 --> 00:00:43,300 -Hackathon. 16 00:00:43,300 --> 00:00:43,883 -The Hackathon 17 00:00:43,883 --> 00:00:45,027 -Rob Bowden. 18 00:00:45,027 --> 00:00:46,110 Just everything about him. 19 00:00:46,110 --> 00:00:47,401 >> [MUSIC -- IGGY AZALEA, "FANCY"] 20 00:00:47,401 --> 00:00:56,790 21 00:00:56,790 --> 00:01:02,512 >> -My favorite memory is when I was on stage and I played the prestigious role 22 00:01:02,512 --> 00:01:04,220 of a node [? in the Linked ?] [? List. ?] 23 00:01:04,220 --> 00:01:08,470 >> -When we all got free Dropbox space and David was like, look under your seats. 24 00:01:08,470 --> 00:01:10,520 And it was like, space for everyone! 25 00:01:10,520 --> 00:01:11,811 >> [MUSIC -- IGGY AZALEA, "FANCY"] 26 00:01:11,811 --> 00:01:20,940 27 00:01:20,940 --> 00:01:22,830 >> -My advice for any incoming student would 28 00:01:22,830 --> 00:01:26,170 be to really work on P-sets with friends. 29 00:01:26,170 --> 00:01:27,960 >> -Office hours is very much your friend. 30 00:01:27,960 --> 00:01:30,870 >> -Make the most of your experience and meet as many people as you can. 31 00:01:30,870 --> 00:01:32,390 >> -Don't be afraid to ask for help. 32 00:01:32,390 --> 00:01:33,890 -Start the P-sets early in the week. 33 00:01:33,890 --> 00:01:36,723 -I think the biggest thing is to take advantage of all the resources 34 00:01:36,723 --> 00:01:37,950 that CS50 has. 35 00:01:37,950 --> 00:01:39,960 >> -Go to office hours early in the week. 36 00:01:39,960 --> 00:01:41,430 >> -Definitely watch the shorts. 37 00:01:41,430 --> 00:01:42,989 >> -Don't procrastinate on your P-sets. 38 00:01:42,989 --> 00:01:45,780 -Make sure you find a great group of people to work on P-sets with. 39 00:01:45,780 --> 00:01:48,530 You can have a lot of fun and get work done together. 40 00:01:48,530 --> 00:01:50,370 >> -Don't be afraid to push yourself. 41 00:01:50,370 --> 00:01:52,080 Go for the hacker edition sometimes. 42 00:01:52,080 --> 00:01:55,410 >> -Write things on paper before you ever touch your computer. 43 00:01:55,410 --> 00:01:58,380 >> -CS50 is really great at providing ways to get help. 44 00:01:58,380 --> 00:02:01,134 >> -My one piece of advice is sleep. 45 00:02:01,134 --> 00:02:02,050 Has anybody said that? 46 00:02:02,050 --> 00:02:04,100 Sleep, for sure. 47 00:02:04,100 --> 00:02:08,919 It's easy not to do, but you've got to do it, I think. 48 00:02:08,919 --> 00:02:12,982 >> -I would say really be mentally prepared because you're going to love it. 49 00:02:12,982 --> 00:02:14,273 [MUSIC -- IGGY AZALEA, "FANCY"] 50 00:02:14,273 --> 00:02:17,750 51 00:02:17,750 --> 00:02:18,940 >> -This is CS50. 52 00:02:18,940 --> 00:02:22,090 53 00:02:22,090 --> 00:02:23,066 >> -This is CS50. 54 00:02:23,066 --> 00:02:26,400 55 00:02:26,400 --> 00:02:26,989 >> -This is CS50. 56 00:02:26,989 --> 00:02:28,280 [MUSIC -- IGGY AZALEA, "FANCY"] 57 00:02:28,280 --> 00:02:31,290 58 00:02:31,290 --> 00:02:31,964 >> -This is CS50. 59 00:02:31,964 --> 00:02:36,020 60 00:02:36,020 --> 00:02:42,270 >> [APPLAUSE] 61 00:02:42,270 --> 00:02:46,040 >> DAVID J. MALAN: So this is CS50 and this is the end of Week 0. 62 00:02:46,040 --> 00:02:48,770 And that was just some of CS50's staff who 63 00:02:48,770 --> 00:02:51,100 await you not only in sections and office hours, but, 64 00:02:51,100 --> 00:02:54,390 also, this coming weekend at CS50 Puzzle Day. 65 00:02:54,390 --> 00:02:56,410 Which, again, is not all about programming. 66 00:02:56,410 --> 00:02:59,710 Indeed, it's expected that you won't have to program anything, 67 00:02:59,710 --> 00:03:03,780 but rather solve problems using wits and friends alongside you. 68 00:03:03,780 --> 00:03:06,400 >> We will be joined by some of our friends at Facebook-- 69 00:03:06,400 --> 00:03:08,980 if you register here-- who for the past several years, 70 00:03:08,980 --> 00:03:11,450 have actually been writing these challenges with us. 71 00:03:11,450 --> 00:03:14,822 And so, they will be the ones ultimately running Puzzle Day. 72 00:03:14,822 --> 00:03:17,530 And so, you will be challenged with precisely the kinds of things 73 00:03:17,530 --> 00:03:20,520 and problems that folks at Facebook like to think about. 74 00:03:20,520 --> 00:03:21,860 So that is tomorrow. 75 00:03:21,860 --> 00:03:25,980 Register at cs50.harvard.edu/register. 76 00:03:25,980 --> 00:03:28,120 >> Now a word on a couple of staff in particular. 77 00:03:28,120 --> 00:03:30,090 This here is Ansel Duff, who is actually one 78 00:03:30,090 --> 00:03:33,860 of the co-authors of these binary bulbs that we saw on Wednesday, 79 00:03:33,860 --> 00:03:36,710 in addition to CS50's own Dan Bradley. 80 00:03:36,710 --> 00:03:40,094 Ansel Duff was also a former freshman advisee of mine 3 years ago 81 00:03:40,094 --> 00:03:41,760 and he actually even built this lectern. 82 00:03:41,760 --> 00:03:45,330 He's gone on to do engineering sciences and more. 83 00:03:45,330 --> 00:03:49,279 Now, his picture here is actually Ansel 3 years ago at the CS50 Hackathon 84 00:03:49,279 --> 00:03:51,820 when he borrowed one of our balloons, stuck it to his laptop, 85 00:03:51,820 --> 00:03:55,240 and, for the next 12 some odd hours, focused on his final project, 86 00:03:55,240 --> 00:03:59,150 taking breaks only to open bags of candy at the Hackathon. 87 00:03:59,150 --> 00:04:02,210 >> But he went on more recently to spend this past summer with us, 88 00:04:02,210 --> 00:04:05,270 since CS50 for its staff, and now students this semester, 89 00:04:05,270 --> 00:04:06,770 has its own 3D printer. 90 00:04:06,770 --> 00:04:10,180 And in a nutshell a 3D printers is a device that looks quite like this. 91 00:04:10,180 --> 00:04:15,700 You fill it with a plastic spool that is melted down by the device 92 00:04:15,700 --> 00:04:18,940 and you build things literally from nothing. 93 00:04:18,940 --> 00:04:22,660 Much like an inkjet printer, you start spitting out little dots of plastic 94 00:04:22,660 --> 00:04:24,990 that form together to form whole objects. 95 00:04:24,990 --> 00:04:28,430 And so Ansel for instance, earlier this summer, has an iPhone 5 96 00:04:28,430 --> 00:04:30,722 and decided he really wanted to prop it up on his desk. 97 00:04:30,722 --> 00:04:32,638 But he didn't want to go out and buy something 98 00:04:32,638 --> 00:04:36,030 from the Apple store or the like, so he sat down and started drawing something. 99 00:04:36,030 --> 00:04:38,280 He took a few measurements as to how thick 100 00:04:38,280 --> 00:04:41,270 and how wide his iPhone was, he drew this image here, 101 00:04:41,270 --> 00:04:43,870 he decided that he wanted to have a 75 degree tilt 102 00:04:43,870 --> 00:04:46,150 as it was staring at him on his desk there. 103 00:04:46,150 --> 00:04:50,440 He then turned this, using software, into a 3D CAD model 104 00:04:50,440 --> 00:04:52,400 that looked a little something like this. 105 00:04:52,400 --> 00:04:55,940 And then he proceeded, ultimately, to actually create it. 106 00:04:55,940 --> 00:05:00,250 So in fact, if any of you here, perhaps in a row that I can throw to, have 107 00:05:00,250 --> 00:05:06,780 an-- there we have folks with iPhone 5 , and here we have two more. 108 00:05:06,780 --> 00:05:10,650 109 00:05:10,650 --> 00:05:17,037 >> Now, not to be outdone, CS50's own Cheng Gong also set out this summer 110 00:05:17,037 --> 00:05:19,870 to build quite a few things and, in fact, for reasons that are still 111 00:05:19,870 --> 00:05:23,970 unclear, has been slowly printing an army of elephants 112 00:05:23,970 --> 00:05:27,250 with articulating arms and trunks. 113 00:05:27,250 --> 00:05:32,515 A couple of which are actually here if anyone would now like-- an elephant. 114 00:05:32,515 --> 00:05:35,650 115 00:05:35,650 --> 00:05:40,522 All right, . but what Cheng also did for us is he very kindly set up a camera 116 00:05:40,522 --> 00:05:42,230 because that elephant, believe it or not, 117 00:05:42,230 --> 00:05:44,690 takes some two and a half hours to print. 118 00:05:44,690 --> 00:05:47,840 Even the iPhone stand took an hour and a half to print. 119 00:05:47,840 --> 00:05:51,490 And what Cheng went ahead and did was set up a nice camera in front 120 00:05:51,490 --> 00:05:55,580 of this 3D printer, filmed for an hour and a half as Ansel's design printed. 121 00:05:55,580 --> 00:05:58,090 We overlaid some sexy music to it in order 122 00:05:58,090 --> 00:06:00,570 to give you this to look at how 3D printing works. 123 00:06:00,570 --> 00:06:02,494 And even though this is actually in plastic, 124 00:06:02,494 --> 00:06:05,160 realize that if this is an area of interest to you academically, 125 00:06:05,160 --> 00:06:07,120 there are folks, among them Jennifer Lewis here 126 00:06:07,120 --> 00:06:09,036 at the School of Engineering, who are actually 127 00:06:09,036 --> 00:06:10,920 working on 3D printing of plastic objects. 128 00:06:10,920 --> 00:06:14,150 But even, increasingly, biological materials to solve 129 00:06:14,150 --> 00:06:16,530 physiological problems for humans. 130 00:06:16,530 --> 00:06:19,944 But here is a little something from CS50. 131 00:06:19,944 --> 00:06:31,625 >> [LOUD MECHANICAL NOISES] 132 00:06:31,625 --> 00:06:34,250 DAVID J. MALAN: It doesn't sound anything like that in reality, 133 00:06:34,250 --> 00:06:37,240 but it's much cooler to watch it at that speed, and with that sound. 134 00:06:37,240 --> 00:06:40,000 >> Now, on Wednesday, how did we first get here? 135 00:06:40,000 --> 00:06:43,345 We started talking about computer science and we asked what it was. 136 00:06:43,345 --> 00:06:46,470 And it's about a number of things, and there's so many different directions 137 00:06:46,470 --> 00:06:48,477 in which you can head after a course like CS50. 138 00:06:48,477 --> 00:06:50,810 In fact, if you picked up one of those unofficial guides 139 00:06:50,810 --> 00:06:54,080 to CS outside, the booklet that we've provided, whether you're 140 00:06:54,080 --> 00:06:57,150 thinking of taking just CS50, or maybe doing a secondary, 141 00:06:57,150 --> 00:06:59,557 or maybe even concentrating in CS, do flip through that. 142 00:06:59,557 --> 00:07:01,390 And you'll see a diagram toward the end that 143 00:07:01,390 --> 00:07:04,950 shows you the many different directions in CS that you can go off in. 144 00:07:04,950 --> 00:07:09,030 >> But for today, we'll focus, again, on really one of the fundamental views, 145 00:07:09,030 --> 00:07:11,500 perhaps, where you have inputs to problems, 146 00:07:11,500 --> 00:07:13,430 you have outputs from problems, and you have 147 00:07:13,430 --> 00:07:17,420 algorithms with which to create those outputs from those inputs. 148 00:07:17,420 --> 00:07:20,330 And one such example, was of course, this phone book here. 149 00:07:20,330 --> 00:07:24,180 And we used as an example to go through an algorithm that was correct. 150 00:07:24,180 --> 00:07:26,490 And then another one was correct, but a little faster. 151 00:07:26,490 --> 00:07:29,448 And then another one that was a little more dramatic, but fundamentally 152 00:07:29,448 --> 00:07:30,000 faster. 153 00:07:30,000 --> 00:07:32,720 >> Right, this phone book we claimed had about 1,000 pages. 154 00:07:32,720 --> 00:07:36,200 And how many times did I have to tear the phone book in half 155 00:07:36,200 --> 00:07:39,930 to find someone like Mike Smith, maximally, in 1,000 page book? 156 00:07:39,930 --> 00:07:41,040 So, 10 give or take. 157 00:07:41,040 --> 00:07:45,050 And so once I tore this thing in half, or simply, more maturely, 158 00:07:45,050 --> 00:07:48,490 divided in half, it's only 10 pages out of 1,000. 159 00:07:48,490 --> 00:07:51,470 And if you extrapolate, a little unrealistically for a phone book, 160 00:07:51,470 --> 00:07:56,540 but if this phone book had some 4 billion pages in it, so completely 161 00:07:56,540 --> 00:07:59,680 unwieldy physically, how many times do you divide a 4 billion 162 00:07:59,680 --> 00:08:01,460 page phone book in half? 163 00:08:01,460 --> 00:08:03,035 So it's actually 32, give or take. 164 00:08:03,035 --> 00:08:07,090 And so 32 times only, out of 4 billion pages, can 165 00:08:07,090 --> 00:08:08,700 you find someone like Mike Smith. 166 00:08:08,700 --> 00:08:09,740 And that's efficiency. 167 00:08:09,740 --> 00:08:12,130 That's a good algorithm, daresay. 168 00:08:12,130 --> 00:08:14,480 >> But then we moved from that to try to formalize it. 169 00:08:14,480 --> 00:08:16,100 And I proposed this pseudocode code. 170 00:08:16,100 --> 00:08:17,800 Pseudocode code is not anything formal. 171 00:08:17,800 --> 00:08:18,880 It's not something you memorize. 172 00:08:18,880 --> 00:08:21,588 It's just something you express fairly intuitively using English, 173 00:08:21,588 --> 00:08:24,990 or any language really, that conveys your ideas succinctly. 174 00:08:24,990 --> 00:08:26,990 But what's key about pseudocode code is that you 175 00:08:26,990 --> 00:08:30,331 try to anticipate all of the possible cases that might happen. 176 00:08:30,331 --> 00:08:33,080 And indeed, in this pseudocode code, there were really three cases 177 00:08:33,080 --> 00:08:34,700 every time I divided the phone book. 178 00:08:34,700 --> 00:08:36,006 Mike might be to the left. 179 00:08:36,006 --> 00:08:37,130 Mike might be to the right. 180 00:08:37,130 --> 00:08:39,240 Or he might be right on the page I'm on. 181 00:08:39,240 --> 00:08:42,110 Or a fourth corner case, so to speak. 182 00:08:42,110 --> 00:08:46,470 A bad scenario might be one which-- what is happening? 183 00:08:46,470 --> 00:08:48,860 Mike's just not in the phone book at all. 184 00:08:48,860 --> 00:08:52,720 >> And when programs crash-- when Mac and PC software that you guys run 185 00:08:52,720 --> 00:08:56,400 on your computers sometimes hangs or quits unexpectedly, 186 00:08:56,400 --> 00:08:59,770 that generally means that some programmer, some human like you soon, 187 00:08:59,770 --> 00:09:01,650 just screwed up and made some mistake. 188 00:09:01,650 --> 00:09:05,207 Maybe didn't anticipate that maybe there is no Mike Smith in the phone book. 189 00:09:05,207 --> 00:09:08,040 And if you don't actually write code to handle situations like that, 190 00:09:08,040 --> 00:09:09,890 generally unpredictable things can happen. 191 00:09:09,890 --> 00:09:10,960 Your machine can freeze. 192 00:09:10,960 --> 00:09:11,730 It can reboot. 193 00:09:11,730 --> 00:09:12,889 The program can quit. 194 00:09:12,889 --> 00:09:14,722 And so all of these stupidities that you may 195 00:09:14,722 --> 00:09:18,030 have encountered in your actual life just using computers, 196 00:09:18,030 --> 00:09:20,710 will increasingly be just explained away by this intuition 197 00:09:20,710 --> 00:09:24,920 and this understanding of what is actually going on underneath the hood. 198 00:09:24,920 --> 00:09:27,329 >> Now let's try to take a look at a more general problem. 199 00:09:27,329 --> 00:09:29,120 Rather than take attendance in a place like 200 00:09:29,120 --> 00:09:32,230 this, which would be quite slow to do one, two, three, four. 201 00:09:32,230 --> 00:09:34,070 Or maybe two, four, six, eight. 202 00:09:34,070 --> 00:09:36,080 Let's focus, instead, on how we might formalize 203 00:09:36,080 --> 00:09:39,400 the algorithm of the process by which we could take attendance. 204 00:09:39,400 --> 00:09:42,290 And along the way, let's start to apply some nomenclature 205 00:09:42,290 --> 00:09:47,130 that we'll use today when we actually start programming in a language. 206 00:09:47,130 --> 00:09:50,910 So I give you now, a four minute video that we put together with our friends 207 00:09:50,910 --> 00:09:52,820 from TED, the organization. 208 00:09:52,820 --> 00:09:56,380 Whereby we supplied a script and they brought their animators to bear, 209 00:09:56,380 --> 00:10:00,970 and actually created a 2D animation of what an algorithm is. 210 00:10:00,970 --> 00:10:02,776 If we could dim the lights. 211 00:10:02,776 --> 00:10:06,664 >> [MUSIC PLAYING] 212 00:10:06,664 --> 00:10:17,890 213 00:10:17,890 --> 00:10:19,140 NARRATOR: What's an algorithm? 214 00:10:19,140 --> 00:10:21,620 In computer science, an algorithm is a set 215 00:10:21,620 --> 00:10:24,840 of instructions resolving some problem step-by-step. 216 00:10:24,840 --> 00:10:27,310 Typically, algorithms are executed by computers, 217 00:10:27,310 --> 00:10:29,365 but we humans have algorithms as well. 218 00:10:29,365 --> 00:10:31,240 For instance, how would you go about counting 219 00:10:31,240 --> 00:10:32,990 the number of people in a room? 220 00:10:32,990 --> 00:10:36,840 Well, if you're like me, you'd probably point at each person one at a time 221 00:10:36,840 --> 00:10:38,370 and count up from zero. 222 00:10:38,370 --> 00:10:41,200 One, two, three, four, and so forth. 223 00:10:41,200 --> 00:10:42,410 Well, that's an algorithm. 224 00:10:42,410 --> 00:10:45,820 In fact, let's try to express it a bit more formally in pseudocode code. 225 00:10:45,820 --> 00:10:48,940 English-like syntax that resembles a programming language. 226 00:10:48,940 --> 00:10:50,880 >> Let n equal 0. 227 00:10:50,880 --> 00:10:55,210 For each person in room, set n equal to n plus 1. 228 00:10:55,210 --> 00:10:56,790 How to interpret the pseudocode? 229 00:10:56,790 --> 00:10:59,490 Well line one declares, so to speak, a variable 230 00:10:59,490 --> 00:11:02,880 called n and initializes its value to 0 This just 231 00:11:02,880 --> 00:11:05,080 means that at the beginning of our algorithm, 232 00:11:05,080 --> 00:11:07,910 the thing with which we're counting has a value of 0. 233 00:11:07,910 --> 00:11:10,860 After all, before we start counting we haven't counted anything yet. 234 00:11:10,860 --> 00:11:13,580 Calling this variable n is just a convention. 235 00:11:13,580 --> 00:11:15,130 I could have called it most anything. 236 00:11:15,130 --> 00:11:17,460 Now line two demarks the start of a loop, 237 00:11:17,460 --> 00:11:20,550 a sequence of steps that will repeat some number of times. 238 00:11:20,550 --> 00:11:24,130 So in our example, the step we're taking is counting people in the room. 239 00:11:24,130 --> 00:11:26,260 Beneath line two is line three which describes 240 00:11:26,260 --> 00:11:28,400 exactly how we'll go about counting. 241 00:11:28,400 --> 00:11:31,720 The indentation implies that it's line three that will repeat. 242 00:11:31,720 --> 00:11:35,190 So with the pseudocode code is saying is that after starting at 0 243 00:11:35,190 --> 00:11:38,940 for each person in the room we'll increase n by 1 244 00:11:38,940 --> 00:11:41,310 Now is this algorithm correct? 245 00:11:41,310 --> 00:11:42,820 Well let's bang on it a bit. 246 00:11:42,820 --> 00:11:45,520 >> Does it work if there are two people in the room? 247 00:11:45,520 --> 00:11:46,420 Let's see. 248 00:11:46,420 --> 00:11:48,500 In line one we initialize n to 0. 249 00:11:48,500 --> 00:11:51,910 For each of these two people, we then increment n by 1. 250 00:11:51,910 --> 00:11:55,570 So in the first trip through the loop, we update n from 0 to 1. 251 00:11:55,570 --> 00:11:59,320 On the second trip through that same loop, we update n from 1 to 2. 252 00:11:59,320 --> 00:12:02,850 And so, by this algorithm's end, n is 2, which 253 00:12:02,850 --> 00:12:04,950 indeed matches the number of people in the room. 254 00:12:04,950 --> 00:12:06,040 So far, so good. 255 00:12:06,040 --> 00:12:07,870 >> How about a corner case though? 256 00:12:07,870 --> 00:12:11,090 Suppose that there are 0 people in the room-- besides me, who's 257 00:12:11,090 --> 00:12:12,420 doing counting. 258 00:12:12,420 --> 00:12:15,380 In line one, we again initialize n to 0. 259 00:12:15,380 --> 00:12:17,810 This time though, line three doesn't execute at all 260 00:12:17,810 --> 00:12:19,610 since there isn't a person in the room. 261 00:12:19,610 --> 00:12:23,540 And so n remains 0, which indeed matches the number of people in the room. 262 00:12:23,540 --> 00:12:24,670 Pretty simple, right? 263 00:12:24,670 --> 00:12:27,880 But counting people one at a time is pretty inefficient, too, no? 264 00:12:27,880 --> 00:12:29,160 Surely we can do better. 265 00:12:29,160 --> 00:12:33,440 Why not count two people at a time, instead of counting one, two, three, 266 00:12:33,440 --> 00:12:36,470 four, five, six, seven, eight, and so forth. 267 00:12:36,470 --> 00:12:39,106 Why not count two, four, six, eight, and so on? 268 00:12:39,106 --> 00:12:40,670 It even sounds faster. 269 00:12:40,670 --> 00:12:41,940 And it surely is. 270 00:12:41,940 --> 00:12:44,490 >> Let's express this optimization in pseudocode code. 271 00:12:44,490 --> 00:12:46,040 Let n equal 0. 272 00:12:46,040 --> 00:12:50,760 For each pair of people in room, set n equal to n plus 2. 273 00:12:50,760 --> 00:12:52,360 Pretty simple change, right? 274 00:12:52,360 --> 00:12:56,560 Rather than count people one at a time, we instead count them two at a time. 275 00:12:56,560 --> 00:12:59,240 This algorithm's, thus, twice as fast as the last. 276 00:12:59,240 --> 00:13:00,530 But is it correct? 277 00:13:00,530 --> 00:13:01,160 Let's see. 278 00:13:01,160 --> 00:13:03,580 Does it work if there are two people in the room? 279 00:13:03,580 --> 00:13:05,800 In line one, we initialize n to 0. 280 00:13:05,800 --> 00:13:09,160 For that one pair of people, we then increment n by 2. 281 00:13:09,160 --> 00:13:11,910 And so by this algorithm's end n is 2, which 282 00:13:11,910 --> 00:13:13,910 indeed matches the number of people in the room. 283 00:13:13,910 --> 00:13:16,610 >> Suppose next that there are zero people in the room. 284 00:13:16,610 --> 00:13:19,080 In line one we initialize n to 0. 285 00:13:19,080 --> 00:13:21,260 As before, line three doesn't execute it all 286 00:13:21,260 --> 00:13:25,270 since there aren't any pairs of people in the room, and so n remains 0. 287 00:13:25,270 --> 00:13:27,840 Which indeed matches the number of people in the room. 288 00:13:27,840 --> 00:13:30,520 But what if there are three people in the room? 289 00:13:30,520 --> 00:13:32,380 How does this algorithm fare? 290 00:13:32,380 --> 00:13:35,710 Let's see, in line one, we initialize n to 0. 291 00:13:35,710 --> 00:13:39,140 For a pair of those people, we then increment n by 2. 292 00:13:39,140 --> 00:13:40,050 But then what? 293 00:13:40,050 --> 00:13:42,340 There isn't another full pair of people in the room, 294 00:13:42,340 --> 00:13:44,430 so line two no longer applies. 295 00:13:44,430 --> 00:13:48,790 And so by this algorithm's end, n is still 2 which isn't correct. 296 00:13:48,790 --> 00:13:52,070 Indeed this algorithm's said to be buggy because it has a mistake. 297 00:13:52,070 --> 00:13:54,070 >> Let's redress with some new pseudocode code. 298 00:13:54,070 --> 00:13:56,110 Let n equal 0. 299 00:13:56,110 --> 00:14:00,790 For each pair of people in room, set N equal to n plus 2. 300 00:14:00,790 --> 00:14:05,410 If one person remains unpaired, set N equal to n plus 1. 301 00:14:05,410 --> 00:14:09,340 To solve this particular problem, we've introduced in line four a condition, 302 00:14:09,340 --> 00:14:12,120 otherwise known as a branch, that only executes 303 00:14:12,120 --> 00:14:14,890 if there's one person we could not pair with another. 304 00:14:14,890 --> 00:14:17,140 And so now, whether there's one, or three, 305 00:14:17,140 --> 00:14:21,550 or any odd number of people in the room, this algorithm will now count them. 306 00:14:21,550 --> 00:14:22,810 Can we do even better? 307 00:14:22,810 --> 00:14:25,890 Well, we could count in threes, or fours, or even fives and tens, 308 00:14:25,890 --> 00:14:29,390 but beyond that, it's going to get a little bit difficult to point. 309 00:14:29,390 --> 00:14:32,900 >> At the end of the day, whether executed by computers or humans, 310 00:14:32,900 --> 00:14:34,870 algorithms are just a set of instructions 311 00:14:34,870 --> 00:14:36,560 with which to solve problems. 312 00:14:36,560 --> 00:14:38,360 These were just three. 313 00:14:38,360 --> 00:14:41,860 What problem would you solve with an algorithm? 314 00:14:41,860 --> 00:14:44,261 >> DAVID J. MALAN: So deliberately, a very simple program, 315 00:14:44,261 --> 00:14:46,260 a very simple algorithm, for achieving something 316 00:14:46,260 --> 00:14:48,280 very simple, counting the number of people in the room. 317 00:14:48,280 --> 00:14:50,370 >> But let's tease apart some of the representative 318 00:14:50,370 --> 00:14:52,870 features here that are actually going to be useful even when 319 00:14:52,870 --> 00:14:54,880 implementing the most complex of software. 320 00:14:54,880 --> 00:14:58,060 So for instance, in this first line, we have what we call the variable, 321 00:14:58,060 --> 00:15:01,040 and from algebra, you're generally familiar using x and y 322 00:15:01,040 --> 00:15:02,930 and z sometimes, and so forth. 323 00:15:02,930 --> 00:15:05,770 But in programming, variables are still, at the end of the day, 324 00:15:05,770 --> 00:15:06,680 very similar to that. 325 00:15:06,680 --> 00:15:09,910 But it's perhaps simpler to think of a variable as just a container. 326 00:15:09,910 --> 00:15:13,520 And, in fact, it's some number of bits implemented somehow in your hard disk 327 00:15:13,520 --> 00:15:16,410 or in your computer's memory, but more on that in the future. 328 00:15:16,410 --> 00:15:17,670 It's just a container. 329 00:15:17,670 --> 00:15:20,310 And if you say something like let n equal 0, 330 00:15:20,310 --> 00:15:24,310 well that's like calling this glass bowl here n, just an arbitrary name, 331 00:15:24,310 --> 00:15:26,230 and putting nothing in it initially. 332 00:15:26,230 --> 00:15:28,940 So the value of this bowl right now is zero. 333 00:15:28,940 --> 00:15:31,380 And of course if you perceive in a subsequent line, 334 00:15:31,380 --> 00:15:35,070 to actually increment some line of code, as in this third line here, 335 00:15:35,070 --> 00:15:39,857 by 1, that's like saying what's the current value of n, it's 0, plus 1, 336 00:15:39,857 --> 00:15:41,690 put something like a ping pong ball in here. 337 00:15:41,690 --> 00:15:45,140 Now the value of this variable is quite simply 1. 338 00:15:45,140 --> 00:15:50,064 And you could very quickly extrapolate, but now it's 2, now it's 3, and so on. 339 00:15:50,064 --> 00:15:51,230 So that's all a variable is. 340 00:15:51,230 --> 00:15:53,740 It's a piece of storage to actually store some data. 341 00:15:53,740 --> 00:15:55,050 For now it's a ping pong ball. 342 00:15:55,050 --> 00:15:55,883 There it's a number. 343 00:15:55,883 --> 00:15:58,910 But it could be words in a dictionary, like the spell checker 344 00:15:58,910 --> 00:16:02,300 I alluded to on Wednesday for one of last year's problem sets. 345 00:16:02,300 --> 00:16:05,640 >> Now another key idea, that similarly is pretty intuitive I would claim, 346 00:16:05,640 --> 00:16:06,690 is that of a loop. 347 00:16:06,690 --> 00:16:08,930 And the loop in the process of counting everyone 348 00:16:08,930 --> 00:16:12,540 is, of course, doing the same thing again and again-- either one 349 00:16:12,540 --> 00:16:14,140 at a time or two at a time. 350 00:16:14,140 --> 00:16:17,690 And you can express this in English, or pseudocode code, in any number of ways, 351 00:16:17,690 --> 00:16:21,560 but using this preposition "for" is a very common way of doing that. 352 00:16:21,560 --> 00:16:24,460 For each person in the room, do this. 353 00:16:24,460 --> 00:16:25,350 Again and again. 354 00:16:25,350 --> 00:16:27,700 And the fact that it's indented, line three, 355 00:16:27,700 --> 00:16:29,840 just means that what you're supposed to do 356 00:16:29,840 --> 00:16:33,490 is the stuff that's indented below the line two itself. 357 00:16:33,490 --> 00:16:35,590 Just a human convention, but a common one 358 00:16:35,590 --> 00:16:39,010 as we'll see in actual higher level programming languages. 359 00:16:39,010 --> 00:16:41,870 >> Now little more interesting is when you get in a corner case. 360 00:16:41,870 --> 00:16:43,970 For instance, a corner case was when there 361 00:16:43,970 --> 00:16:48,060 were three people, or five, or seven, or any odd number of people in the room, 362 00:16:48,060 --> 00:16:51,630 because doing that by twos brakes eventually because your going 363 00:16:51,630 --> 00:16:54,265 to miss someone, either at the very beginning or the very end 364 00:16:54,265 --> 00:16:55,390 depending on how you do it. 365 00:16:55,390 --> 00:16:59,800 And so, now, I have this branch, or condition, if one person remains, 366 00:16:59,800 --> 00:17:04,490 then go ahead and handle that one lonesome person who didn't get 367 00:17:04,490 --> 00:17:05,690 paired with someone else. 368 00:17:05,690 --> 00:17:09,030 So that's what we would call a condition, or a branch. 369 00:17:09,030 --> 00:17:11,500 >> Now pseudocode code more generally can be 370 00:17:11,500 --> 00:17:13,730 written to solve any number of problems. 371 00:17:13,730 --> 00:17:16,490 And what I thought we'd do here is take a moment 372 00:17:16,490 --> 00:17:20,089 to invite shall we say CS50's own Rob Bowden on stage 373 00:17:20,089 --> 00:17:25,040 to be joined by two volunteers, who have no idea what awaits. 374 00:17:25,040 --> 00:17:26,890 A hand went down as soon as I said that. 375 00:17:26,890 --> 00:17:28,700 How about you on the end here, come on up. 376 00:17:28,700 --> 00:17:33,040 And how about from farther away, how about way in the back. 377 00:17:33,040 --> 00:17:35,200 Back row, come on up with your hands up. 378 00:17:35,200 --> 00:17:36,475 Alright, and what's your name? 379 00:17:36,475 --> 00:17:36,960 >> ANITA: Anita. 380 00:17:36,960 --> 00:17:37,655 >> DAVID J. MALAN: Anita. 381 00:17:37,655 --> 00:17:38,613 Okay, nice to meet you. 382 00:17:38,613 --> 00:17:41,010 Let me introduce you to Rob Bowden. 383 00:17:41,010 --> 00:17:42,890 This is Anita. 384 00:17:42,890 --> 00:17:44,033 And what is your name? 385 00:17:44,033 --> 00:17:44,800 >> KIERSTEN: Kiersten 386 00:17:44,800 --> 00:17:46,020 >> DAVID J. MALAN: Kiersten. 387 00:17:46,020 --> 00:17:49,790 Kiersten, come on up and meet Rob Bowden and Anita. 388 00:17:49,790 --> 00:17:51,036 Nice to meet you. 389 00:17:51,036 --> 00:17:52,160 KIERSTEN: Nice to meet you. 390 00:17:52,160 --> 00:17:53,368 DAVID J. MALAN: Alright, Rob. 391 00:17:53,368 --> 00:17:54,650 ROB BOWDEN: Nice to meet you. 392 00:17:54,650 --> 00:17:55,566 DAVID J. MALAN: Anita. 393 00:17:55,566 --> 00:17:56,520 KIERSTEN: Hi Anita. 394 00:17:56,520 --> 00:17:58,686 DAVID J. MALAN: And your several hundred classmates. 395 00:17:58,686 --> 00:18:02,490 So, now let me go ahead and pull up just a simple program here 396 00:18:02,490 --> 00:18:05,690 on Mac OS that'll let me actually jot some notes down. 397 00:18:05,690 --> 00:18:09,570 And if you guys want to each take a position at one of those schools there, 398 00:18:09,570 --> 00:18:16,360 let me go ahead and starts a list of pseudocode code, if you will. 399 00:18:16,360 --> 00:18:19,970 And what I want to do here, ultimately is type for you 400 00:18:19,970 --> 00:18:22,470 some instructions that our audience members are actually 401 00:18:22,470 --> 00:18:23,569 going to recite for us. 402 00:18:23,569 --> 00:18:25,860 Let me go ahead and just change this to a numbered list 403 00:18:25,860 --> 00:18:27,720 to match what we were doing up there. 404 00:18:27,720 --> 00:18:30,990 And what I'm going to do with your help, is write a program 405 00:18:30,990 --> 00:18:34,620 in pseudocode, with which these guys are going 406 00:18:34,620 --> 00:18:38,150 to implement a peanut butter and jelly sandwich. 407 00:18:38,150 --> 00:18:40,880 So it's perhaps apropos to show something some of you 408 00:18:40,880 --> 00:18:44,560 might have seen on the internet for just a brief annoying moment. 409 00:18:44,560 --> 00:18:47,650 >> [MUSIC BUCKEWHEAT BOYS, "PEANUT BUTTER JELLY TIME"] 410 00:18:47,650 --> 00:19:08,119 411 00:19:08,119 --> 00:19:08,910 DAVID J. MALAN: OK. 412 00:19:08,910 --> 00:19:10,050 That's enough of that. 413 00:19:10,050 --> 00:19:12,690 So here meanwhile, I have a pair of Google Glasses which 414 00:19:12,690 --> 00:19:16,500 we'll put on CS50's own Rob Bowden to see the world through his eyes. 415 00:19:16,500 --> 00:19:19,140 And we'll do our best in post production to actually weave 416 00:19:19,140 --> 00:19:23,100 the footage of what Rob is seeing now, into this actual lecture 417 00:19:23,100 --> 00:19:26,420 video with our two volunteers beside him. 418 00:19:26,420 --> 00:19:28,480 So what I'm going to do is, I'll be the typist. 419 00:19:28,480 --> 00:19:31,849 We have the goal here of actually writing a program 420 00:19:31,849 --> 00:19:34,640 with which to make, ultimately, a peanut butter and jelly sandwich, 421 00:19:34,640 --> 00:19:37,680 but these three are going to behave as though they are computers. 422 00:19:37,680 --> 00:19:40,638 And computers, at the end of the day, are actually pretty dumb devices. 423 00:19:40,638 --> 00:19:44,432 They're super fast, but they can only do, literally, what they are told. 424 00:19:44,432 --> 00:19:46,890 You can't just say make a peanut butter and jelly sandwich. 425 00:19:46,890 --> 00:19:48,640 You have to program them to do that. 426 00:19:48,640 --> 00:19:51,420 You have to tell them with precision what to do, 427 00:19:51,420 --> 00:19:54,400 less things go horribly and, hopefully, amusingly awry. 428 00:19:54,400 --> 00:19:57,460 >> So with that said, we need one call-out from the audience 429 00:19:57,460 --> 00:19:59,440 for what should step one be, if the goal here 430 00:19:59,440 --> 00:20:01,356 is to make a peanut butter and jelly sandwich. 431 00:20:01,356 --> 00:20:01,910 Yes? 432 00:20:01,910 --> 00:20:03,647 >> AUDIENCE: [INAUDIBLE] the bag of bread. 433 00:20:03,647 --> 00:20:05,230 DAVID J. MALAN: Open the bag of bread. 434 00:20:05,230 --> 00:20:08,360 So if the three contestants would like to proceed to do that literally. 435 00:20:08,360 --> 00:20:12,394 Open the bag of bread. 436 00:20:12,394 --> 00:20:15,810 >> [AUDIENCE LAUGHING] 437 00:20:15,810 --> 00:20:20,717 438 00:20:20,717 --> 00:20:22,300 DAVID J. MALAN: So let's work on that. 439 00:20:22,300 --> 00:20:23,180 All right. 440 00:20:23,180 --> 00:20:25,400 So step two, how-- let's take this further. 441 00:20:25,400 --> 00:20:26,480 Yeah, in the front. 442 00:20:26,480 --> 00:20:27,240 >> AUDIENCE: [INAUDIBLE] the bread. 443 00:20:27,240 --> 00:20:27,735 >> DAVID J. MALAN: What's that? 444 00:20:27,735 --> 00:20:28,836 >> AUDIENCE:Remove the bread. 445 00:20:28,836 --> 00:20:30,210 DAVID J. MALAN: Remove the bread. 446 00:20:30,210 --> 00:20:31,190 Similarly succinct. 447 00:20:31,190 --> 00:20:33,667 Thank you. 448 00:20:33,667 --> 00:20:43,777 >> [APPLAUSE] 449 00:20:43,777 --> 00:20:44,860 DAVID J. MALAN: That's it? 450 00:20:44,860 --> 00:20:48,830 OK, so step two is going to be remove the bread. 451 00:20:48,830 --> 00:20:51,790 Alright, someone want to write us a longer sentence? 452 00:20:51,790 --> 00:20:52,640 Someone else? 453 00:20:52,640 --> 00:20:53,920 A little more [INAUDIBLE]. 454 00:20:53,920 --> 00:20:54,810 No, nothing now. 455 00:20:54,810 --> 00:20:56,094 Yes? 456 00:20:56,094 --> 00:20:58,900 >> AUDIENCE: Place two slices next to each other. 457 00:20:58,900 --> 00:21:03,575 >> DAVID J. MALAN: Place two slices next to each other. 458 00:21:03,575 --> 00:21:06,420 >> [AUDIENCE LAUGHING] 459 00:21:06,420 --> 00:21:09,590 >> DAVID J. MALAN: Place two slices next to each other. 460 00:21:09,590 --> 00:21:11,334 Step four. 461 00:21:11,334 --> 00:21:12,816 Yes? 462 00:21:12,816 --> 00:21:14,792 >> AUDIENCE: Take your hand and set it lightly 463 00:21:14,792 --> 00:21:17,756 on top of the peanut butter lid. 464 00:21:17,756 --> 00:21:19,710 >> [AUDIENCE LAUGHING] 465 00:21:19,710 --> 00:21:21,710 AUDIENCE: [INAUDIBLE] next to the peanut butter. 466 00:21:21,710 --> 00:21:21,870 DAVID J. MALAN: What? 467 00:21:21,870 --> 00:21:22,520 Say that again. 468 00:21:22,520 --> 00:21:26,308 >> AUDIENCE: Unscrew the lid and put it gently next to the peanut butter. 469 00:21:26,308 --> 00:21:31,490 >> DAVID J. MALAN: Put it gently next to the peanut butter. 470 00:21:31,490 --> 00:21:37,770 471 00:21:37,770 --> 00:21:40,090 OK, progress. 472 00:21:40,090 --> 00:21:41,080 Step five. 473 00:21:41,080 --> 00:21:42,380 Excellent. 474 00:21:42,380 --> 00:21:43,261 Yes? 475 00:21:43,261 --> 00:21:44,163 >> Pick up knife. 476 00:21:44,163 --> 00:21:46,380 477 00:21:46,380 --> 00:21:47,630 DAVID J. MALAN: Pick up knife. 478 00:21:47,630 --> 00:21:52,320 479 00:21:52,320 --> 00:21:53,631 OK, step six. 480 00:21:53,631 --> 00:21:54,130 Yeah? 481 00:21:54,130 --> 00:21:56,237 >> AUDIENCE: Hold knife by the handle. 482 00:21:56,237 --> 00:21:57,945 DAVID J. MALAN: Hold knife by the handle. 483 00:21:57,945 --> 00:22:00,710 484 00:22:00,710 --> 00:22:03,230 Hold knife by the handle. 485 00:22:03,230 --> 00:22:04,880 Step seven. 486 00:22:04,880 --> 00:22:05,692 Yes? 487 00:22:05,692 --> 00:22:10,030 >> AUDIENCE: [INAUDIBLE] knife in peanut butter and as little out [INAUDIBLE]. 488 00:22:10,030 --> 00:22:13,070 >> DAVID J. MALAN: Put knife in-- I heard "put knife in peanut butter 489 00:22:13,070 --> 00:22:19,500 and take as little out as possible." 490 00:22:19,500 --> 00:22:22,480 By the way, remove the paper first. 491 00:22:22,480 --> 00:22:29,320 492 00:22:29,320 --> 00:22:31,890 All right, step nine. 493 00:22:31,890 --> 00:22:34,910 Step nine. 494 00:22:34,910 --> 00:22:35,624 Step nine. 495 00:22:35,624 --> 00:22:37,290 We haven't actually made a sandwich yet. 496 00:22:37,290 --> 00:22:37,790 Yes? 497 00:22:37,790 --> 00:22:41,570 AUDIENCE: Using knife in peanut butter, apply peanut butter on said bread. 498 00:22:41,570 --> 00:22:47,440 >> DAVID J. MALAN: Using knife in peanut butter, apply peanut butter on 499 00:22:47,440 --> 00:22:48,736 said bread. 500 00:22:48,736 --> 00:22:56,030 >> [AUDIENCE LAUGHING] 501 00:22:56,030 --> 00:22:59,480 DAVID J. MALAN: All right step 10. 502 00:22:59,480 --> 00:23:01,762 Step 10. 503 00:23:01,762 --> 00:23:02,750 Yes? 504 00:23:02,750 --> 00:23:05,220 >> AUDIENCE: Taste peanut butter to ensure quality. 505 00:23:05,220 --> 00:23:15,960 >> [AUDIENCE LAUGHING] 506 00:23:15,960 --> 00:23:16,960 DAVID J. MALAN: Step 11. 507 00:23:16,960 --> 00:23:19,500 508 00:23:19,500 --> 00:23:21,340 Step 11. 509 00:23:21,340 --> 00:23:22,101 Step 11. 510 00:23:22,101 --> 00:23:22,600 Come on. 511 00:23:22,600 --> 00:23:23,099 Yeah? 512 00:23:23,099 --> 00:23:24,208 Right there. 513 00:23:24,208 --> 00:23:25,840 >> AUDIENCE: Carefully pick up jelly. 514 00:23:25,840 --> 00:23:28,220 >> DAVID J. MALAN: Carefully pick up jelly. 515 00:23:28,220 --> 00:23:29,970 OK, and then another hand was up. 516 00:23:29,970 --> 00:23:32,812 517 00:23:32,812 --> 00:23:33,520 Right behind you. 518 00:23:33,520 --> 00:23:35,761 Yeah, in blue. 519 00:23:35,761 --> 00:23:40,671 >> AUDIENCE: All right, remove lid from [INAUDIBLE], yeah, 520 00:23:40,671 --> 00:23:42,635 remove lid from the jelly. 521 00:23:42,635 --> 00:23:43,617 >> [AUDIENCE LAUGHING] 522 00:23:43,617 --> 00:23:44,742 >> DAVID J. MALAN: From jelly. 523 00:23:44,742 --> 00:23:45,581 Ha ha. 524 00:23:45,581 --> 00:23:48,967 >> [AUDIENCE LAUGHING] 525 00:23:48,967 --> 00:23:49,800 DAVID J. MALAN: And? 526 00:23:49,800 --> 00:23:52,490 AUDIENCE: And barely sweep any [INAUDIBLE]. 527 00:23:52,490 --> 00:23:59,536 [AUDIENCE LAUGHING] 528 00:23:59,536 --> 00:24:04,456 AUDIENCE: Of course, before [INAUDIBLE], remove the paper from jelly. 529 00:24:04,456 --> 00:24:06,940 DAVID J. MALAN: Remove paper from jelly. 530 00:24:06,940 --> 00:24:08,229 Step 14. 531 00:24:08,229 --> 00:24:09,020 We're almost there. 532 00:24:09,020 --> 00:24:09,857 Yes? 533 00:24:09,857 --> 00:24:12,600 >> AUDIENCE: Invert jelly bottle before everything falls out. 534 00:24:12,600 --> 00:24:16,515 >> DAVID J. MALAN: Invert jelly bottle before jelly falls out. 535 00:24:16,515 --> 00:24:19,070 536 00:24:19,070 --> 00:24:19,890 Step 15. 537 00:24:19,890 --> 00:24:21,130 >> AUDIENCE: Replace the cap. 538 00:24:21,130 --> 00:24:22,463 >> DAVID J. MALAN: Replace the cap. 539 00:24:22,463 --> 00:24:25,880 540 00:24:25,880 --> 00:24:28,190 Step 16. 541 00:24:28,190 --> 00:24:28,931 Yeah? 542 00:24:28,931 --> 00:24:29,806 >> AUDIENCE: [INAUDIBLE] 543 00:24:29,806 --> 00:24:34,109 544 00:24:34,109 --> 00:24:35,400 DAVID J. MALAN: Say that again. 545 00:24:35,400 --> 00:24:38,100 AUDIENCE: Take cap off of your jelly. 546 00:24:38,100 --> 00:24:39,650 DAVID J. MALAN: Off your jelly. 547 00:24:39,650 --> 00:24:43,720 548 00:24:43,720 --> 00:24:49,510 So really-- Oops. 549 00:24:49,510 --> 00:24:50,420 Come on. 550 00:24:50,420 --> 00:24:51,740 Replace the cap. 551 00:24:51,740 --> 00:24:56,660 Put cap-- You said remove cap from jelly. 552 00:24:56,660 --> 00:24:58,950 Feel like we're in a bit of a loop. 553 00:24:58,950 --> 00:24:59,640 Step 17. 554 00:24:59,640 --> 00:25:00,398 Yes? 555 00:25:00,398 --> 00:25:02,639 >> AUDIENCE: [INAUDIBLE] 556 00:25:02,639 --> 00:25:03,930 DAVID J. MALAN: Say that again. 557 00:25:03,930 --> 00:25:05,150 AUDIENCE: [INAUDIBLE] 558 00:25:05,150 --> 00:25:07,835 DAVID J. MALAN: Go back to step-- 559 00:25:07,835 --> 00:25:10,110 AUDIENCE: [INAUDIBLE] 560 00:25:10,110 --> 00:25:13,760 DAVID J. MALAN: Remove cap from peanut butter. 561 00:25:13,760 --> 00:25:14,492 Yes? 562 00:25:14,492 --> 00:25:16,430 >> AUDIENCE: Drop all the jelly on the bread. 563 00:25:16,430 --> 00:25:19,040 >> DAVID J. MALAN: Drop all the jelly on the bread. 564 00:25:19,040 --> 00:25:25,372 565 00:25:25,372 --> 00:25:26,830 DAVID J. MALAN: We're almost there. 566 00:25:26,830 --> 00:25:27,800 Step 19. 567 00:25:27,800 --> 00:25:30,250 >> AUDIENCE: Remove excess jelly. 568 00:25:30,250 --> 00:25:31,720 >> DAVID J. MALAN: Haha, jelly. 569 00:25:31,720 --> 00:25:36,615 >> [APPLAUSE] 570 00:25:36,615 --> 00:25:39,240 DAVID J. MALAN: Why don't we-- one more step to take this home. 571 00:25:39,240 --> 00:25:41,720 One more step and then we'll serve sandwiches. 572 00:25:41,720 --> 00:25:42,900 Yes? 573 00:25:42,900 --> 00:25:45,570 >> AUDIENCE: [INAUDIBLE] 574 00:25:45,570 --> 00:25:50,704 >> DAVID J. MALAN: While any sandwich remains-- let's indent this-- eat. 575 00:25:50,704 --> 00:25:56,400 >> [AUDIENCE LAUGHTER] 576 00:25:56,400 --> 00:26:00,395 >> DAVID J. MALAN: All right, thank you to our volunteers here. 577 00:26:00,395 --> 00:26:06,150 >> [APPLAUSE} 578 00:26:06,150 --> 00:26:08,940 >> DAVID J. MALAN: We have some nice parting gifts for each of you. 579 00:26:08,940 --> 00:26:14,350 Your own peanut butter, jelly, and bread to bring back home. 580 00:26:14,350 --> 00:26:15,774 Thank you. 581 00:26:15,774 --> 00:26:17,118 >> KIERSTEN: Thank you. 582 00:26:17,118 --> 00:26:18,618 DAVID J. MALAN: [INAUDIBLE] welcome. 583 00:26:18,618 --> 00:26:21,849 [APPLAUSE] 584 00:26:21,849 --> 00:26:24,390 DAVID J. MALAN: So, this is, of course, a ridiculous example. 585 00:26:24,390 --> 00:26:24,890 Right? 586 00:26:24,890 --> 00:26:28,890 But it does kind of reveal how we humans just take clarity for granted. 587 00:26:28,890 --> 00:26:30,890 And the fact I've been talking to another human, 588 00:26:30,890 --> 00:26:33,300 he or she just knows what you mean. 589 00:26:33,300 --> 00:26:35,220 >> Computers are not going to know what you mean, 590 00:26:35,220 --> 00:26:37,430 even when using, as we're about to do today, 591 00:26:37,430 --> 00:26:42,300 programming something in Scratch, a drag and drop, puzzle piece style language. 592 00:26:42,300 --> 00:26:44,310 Even designed for young children, you have 593 00:26:44,310 --> 00:26:48,726 to be so explicit and so literal with what you want your program to do. 594 00:26:48,726 --> 00:26:50,600 Now ultimately, we're going to be programming 595 00:26:50,600 --> 00:26:53,550 not in pseudocode code, English like syntax, 596 00:26:53,550 --> 00:26:56,370 but code or, more properly, source code. 597 00:26:56,370 --> 00:26:59,260 Source code is just the fancy way for describing code you actually 598 00:26:59,260 --> 00:27:01,730 write with a keyboard that's not in English per se. 599 00:27:01,730 --> 00:27:06,480 It's in C or Java or C++ or something like that, as we'll soon see. 600 00:27:06,480 --> 00:27:09,510 >> And in fact, just to scare a few of you, at first glance, 601 00:27:09,510 --> 00:27:13,769 this is a program written in a language called C. But to un-scare a few of you, 602 00:27:13,769 --> 00:27:15,560 you will completely understand what's going 603 00:27:15,560 --> 00:27:18,980 on come next Monday when it comes to something like this. 604 00:27:18,980 --> 00:27:20,510 Frankly, this is an older language. 605 00:27:20,510 --> 00:27:22,430 It's fairly arcane, but it's representative 606 00:27:22,430 --> 00:27:26,120 of a lot of languages these days that have lots of parentheses and curly 607 00:27:26,120 --> 00:27:28,630 braces and quote marks and semicolons. 608 00:27:28,630 --> 00:27:30,780 And a lot of this syntactic stuff that is not 609 00:27:30,780 --> 00:27:32,450 at all intellectually interesting. 610 00:27:32,450 --> 00:27:35,790 Indeed, it's an utter distraction from the very simple ideas 611 00:27:35,790 --> 00:27:37,370 that are staring us in the face. 612 00:27:37,370 --> 00:27:41,760 This program, as you might just guess, prints to someone's computer screen 613 00:27:41,760 --> 00:27:44,070 the words "Hello comma world." 614 00:27:44,070 --> 00:27:44,860 That's it. 615 00:27:44,860 --> 00:27:46,580 So clearly, there's a lot of stuff that's 616 00:27:46,580 --> 00:27:48,970 getting in the way of some obviousness there, 617 00:27:48,970 --> 00:27:52,490 but it's going to very quickly slip away and be completely intuitive. 618 00:27:52,490 --> 00:27:55,617 >> Indeed, what we're going to do today is distill this fairly complex 619 00:27:55,617 --> 00:27:58,950 looking program, which again you'll come to understand quickly, but to something 620 00:27:58,950 --> 00:27:59,710 much simpler. 621 00:27:59,710 --> 00:28:01,640 Let's just say what we mean. 622 00:28:01,640 --> 00:28:05,590 Let's draw a picture of what we mean, by way of these puzzle pieces here. 623 00:28:05,590 --> 00:28:09,110 >> So this is a programming language known as Scratch. 624 00:28:09,110 --> 00:28:11,080 It was developed by MIT's Media Lab. 625 00:28:11,080 --> 00:28:14,830 And what you'll see in problem set zero, which will be released later tonight, 626 00:28:14,830 --> 00:28:18,980 we'll have you go to this URL here scratch.mit.edu. 627 00:28:18,980 --> 00:28:20,940 And they have a web based interface via which 628 00:28:20,940 --> 00:28:22,540 you will write your first program. 629 00:28:22,540 --> 00:28:25,330 Or those of you with prior experience, your second programs, 630 00:28:25,330 --> 00:28:28,090 but in an environment that's probably a little unfamiliar and that 631 00:28:28,090 --> 00:28:32,930 will push you to create something using this very visual environment. 632 00:28:32,930 --> 00:28:35,940 >> Now, what I'm going to do here is open up the program itself. 633 00:28:35,940 --> 00:28:41,911 It exists not only as a web browser, but also as a downloadable program 634 00:28:41,911 --> 00:28:44,660 so that you can actually use it if you don't have internet access. 635 00:28:44,660 --> 00:28:46,743 And I'm going to do that in here, in Sanders, just 636 00:28:46,743 --> 00:28:49,580 in case the Wi-Fi doesn't cooperate super well. 637 00:28:49,580 --> 00:28:52,640 And what I'm going to do is point out a few features of this program. 638 00:28:52,640 --> 00:28:55,720 So, to be clear, I have just double clicked the icon on my desktop, 639 00:28:55,720 --> 00:28:59,830 or equivalently gone to scratch.mit.edu, and it's pulled up this window. 640 00:28:59,830 --> 00:29:01,650 This is a programming environment. 641 00:29:01,650 --> 00:29:04,110 It's a piece of software that some of our friends at MIT 642 00:29:04,110 --> 00:29:08,850 wrote that let's us and you write programs in a language called Scratch. 643 00:29:08,850 --> 00:29:12,010 >> Now this happens to be a cat who's also named Scratch 644 00:29:12,010 --> 00:29:13,890 and this is his world in which he lives. 645 00:29:13,890 --> 00:29:17,175 This is the stage, so to speak, that rectangle on the top left hand corner. 646 00:29:17,175 --> 00:29:18,800 And he doesn't have to look like a cat. 647 00:29:18,800 --> 00:29:20,591 You can make him look like anything and you 648 00:29:20,591 --> 00:29:23,700 can have many such sprites, or characters, in a program. 649 00:29:23,700 --> 00:29:27,450 Meanwhile, over here on the far right, is a big blank slate. 650 00:29:27,450 --> 00:29:30,260 And this is where, in a moment, we are going to start programming 651 00:29:30,260 --> 00:29:32,750 by dragging and dropping these graphical puzzle 652 00:29:32,750 --> 00:29:35,300 pieces that are right here in the middle. 653 00:29:35,300 --> 00:29:38,140 And there's way more of them than we'll spend time on here in class 654 00:29:38,140 --> 00:29:40,080 because you'll find that they're all fairly intuitive. 655 00:29:40,080 --> 00:29:41,788 Again, it's designed for children, but we 656 00:29:41,788 --> 00:29:45,759 use it to tease apart some of those fundamental ideas of variables, loops, 657 00:29:45,759 --> 00:29:48,050 conditions, and, soon, things like functions and events 658 00:29:48,050 --> 00:29:51,810 and threads and other fancy things we'll get to before long to actually create 659 00:29:51,810 --> 00:29:53,840 something from Scratch. 660 00:29:53,840 --> 00:29:54,810 Pun intended. 661 00:29:54,810 --> 00:29:58,740 >> Now, what I'm going to do here is click on not motion, but control. 662 00:29:58,740 --> 00:30:01,400 And this is just a categorization of here-- 663 00:30:01,400 --> 00:30:03,150 and I see a different color set of blocks. 664 00:30:03,150 --> 00:30:05,030 But notice a few familiar words. 665 00:30:05,030 --> 00:30:07,830 "If" and "else if" and "repeat." 666 00:30:07,830 --> 00:30:10,440 And you can probably guess that's reminiscent of the branch, 667 00:30:10,440 --> 00:30:12,870 or the conditions we saw, and even the looping construct. 668 00:30:12,870 --> 00:30:14,760 So we have similar blocks here. 669 00:30:14,760 --> 00:30:16,720 But the most interesting one is this one here. 670 00:30:16,720 --> 00:30:20,690 When this green flag is clicked, this, for those with prior programing 671 00:30:20,690 --> 00:30:23,110 experience, is equivalent to a main function. 672 00:30:23,110 --> 00:30:25,300 But for those unfamiliar, this is the puzzle piece 673 00:30:25,300 --> 00:30:27,320 that will kick start our entire program. 674 00:30:27,320 --> 00:30:31,350 It literally means when I go, in this program, and click a green flag-- 675 00:30:31,350 --> 00:30:35,560 which you can see up here in the top left hand corner of the UI, 676 00:30:35,560 --> 00:30:38,570 so see the green flag next to the red stop sign? 677 00:30:38,570 --> 00:30:41,475 When I click that, my program is going to run. 678 00:30:41,475 --> 00:30:43,850 Now, I'm going to do something super simple with Scratch. 679 00:30:43,850 --> 00:30:46,640 I'm going to go ahead and go to the looks panel 680 00:30:46,640 --> 00:30:50,010 here, where I have a bunch of purple puzzle pieces, 681 00:30:50,010 --> 00:30:53,887 and I'm going to go ahead and do something super simple like, say. 682 00:30:53,887 --> 00:30:55,720 And then-- notice this text in the white box 683 00:30:55,720 --> 00:30:59,290 is editable-- I'm going to say "Hello world," just like we 684 00:30:59,290 --> 00:31:01,470 did in that textual version a moment ago. 685 00:31:01,470 --> 00:31:05,920 And now if I go and click this green flag, I have now programmed. 686 00:31:05,920 --> 00:31:07,810 It's not a particularly interesting program, 687 00:31:07,810 --> 00:31:09,760 but I made the computer do something. 688 00:31:09,760 --> 00:31:13,120 I started a program and it did what I told it to do. 689 00:31:13,120 --> 00:31:16,170 Now, I can continue to drag and drop more and more of these puzzle pieces 690 00:31:16,170 --> 00:31:19,220 and they're going to interlock, but let's slap some terminology on here 691 00:31:19,220 --> 00:31:21,680 that we'll see recurring throughout the course, 692 00:31:21,680 --> 00:31:24,610 and really throughout computer science and programming more generally. 693 00:31:24,610 --> 00:31:27,990 >> This "say" block, in purple, let's just start calling a statement. 694 00:31:27,990 --> 00:31:29,240 It's like a statement of fact. 695 00:31:29,240 --> 00:31:30,380 Do this. 696 00:31:30,380 --> 00:31:32,590 So, it's a category of instructions that you 697 00:31:32,590 --> 00:31:36,760 might feed a computer as part of a program or an algorithm. 698 00:31:36,760 --> 00:31:39,270 And to be clear, you've probably taken for granted 699 00:31:39,270 --> 00:31:41,930 that you have programs on your computer. 700 00:31:41,930 --> 00:31:45,850 And they're kind of algorithms, but a program is really a bunch of algorithms 701 00:31:45,850 --> 00:31:47,160 that some humans wrote. 702 00:31:47,160 --> 00:31:49,040 They packaged it up and they sold it so you, 703 00:31:49,040 --> 00:31:51,330 or they posted on a website for you to download. 704 00:31:51,330 --> 00:31:54,930 So, a program is just a whole bunch of zeros and ones 705 00:31:54,930 --> 00:31:56,970 that, somehow, humans created. 706 00:31:56,970 --> 00:32:00,080 And those patterns of zeros and ones represent things, ultimately, 707 00:32:00,080 --> 00:32:04,030 like "say hello world" or "play this music" or "play this video" 708 00:32:04,030 --> 00:32:05,129 or "send an email." 709 00:32:05,129 --> 00:32:06,920 But we'll come back in way more detail what 710 00:32:06,920 --> 00:32:08,780 a program is when you, yourself, write them. 711 00:32:08,780 --> 00:32:11,320 >> Here's another statement-- "Wait for one second." 712 00:32:11,320 --> 00:32:14,330 I didn't use this yet, but if I want my program to pause for a moment 713 00:32:14,330 --> 00:32:16,540 to do something, I can tell it to do so. 714 00:32:16,540 --> 00:32:18,450 Wait one second. 715 00:32:18,450 --> 00:32:20,150 Now another one might be "play sound." 716 00:32:20,150 --> 00:32:23,270 So, this is unique to Scratch, it has the ability to play sounds. 717 00:32:23,270 --> 00:32:26,130 So, a statement I might use is, here, "play sound." 718 00:32:26,130 --> 00:32:29,530 Meanwhile, Boolean expression, so this is a fancier word 719 00:32:29,530 --> 00:32:34,490 named after just a guy named Mr. Bool, and this is all about a question. 720 00:32:34,490 --> 00:32:37,470 True or false-- is the mouse down? 721 00:32:37,470 --> 00:32:41,100 A Boolean expression is just some expression in English 722 00:32:41,100 --> 00:32:42,860 that is either true or false. 723 00:32:42,860 --> 00:32:44,140 Either on or off. 724 00:32:44,140 --> 00:32:45,130 Either one or zero. 725 00:32:45,130 --> 00:32:46,960 You can think of it in any number of ways, 726 00:32:46,960 --> 00:32:49,220 but it's either true or this false, ultimately. 727 00:32:49,220 --> 00:32:52,540 So "mouse down question mark," that would be a Boolean expression. 728 00:32:52,540 --> 00:32:54,300 And you can think of others, perhaps. 729 00:32:54,300 --> 00:32:57,510 For instance, "is the left number less than the right number?" 730 00:32:57,510 --> 00:32:59,410 That, too, would be a Boolean expression. 731 00:32:59,410 --> 00:33:01,540 "Less than" is a Boolean expression. 732 00:33:01,540 --> 00:33:03,280 >> This one, too, "touching mouse pointer." 733 00:33:03,280 --> 00:33:05,196 I'm not sure why they called it mouse pointer. 734 00:33:05,196 --> 00:33:08,430 It just means, is the cursor, is the arrow on the screen, touching the cat, 735 00:33:08,430 --> 00:33:09,022 for instance. 736 00:33:09,022 --> 00:33:10,480 Or some other aspect of the screen. 737 00:33:10,480 --> 00:33:13,710 And it's a question, again, and that denotes a Boolean expression. 738 00:33:13,710 --> 00:33:17,130 Something that you might want to use in a condition. 739 00:33:17,130 --> 00:33:19,100 So we'll come to that in just a moment. 740 00:33:19,100 --> 00:33:20,350 You can "and" things together. 741 00:33:20,350 --> 00:33:23,099 So, if you want to check if this is the case AND that is the case, 742 00:33:23,099 --> 00:33:25,580 you can use an "and" block like this. 743 00:33:25,580 --> 00:33:26,850 And here's that condition. 744 00:33:26,850 --> 00:33:31,290 Notice the shape of the little opening in the top of this yellow puzzle piece, 745 00:33:31,290 --> 00:33:34,480 it's reminiscent of the shape that we just saw a moment ago. 746 00:33:34,480 --> 00:33:37,920 Each of these Boolean expressions have these pointed edges 747 00:33:37,920 --> 00:33:39,030 on the left and right. 748 00:33:39,030 --> 00:33:43,140 And that's because MIT folks decided that by visually conveying shapes, 749 00:33:43,140 --> 00:33:45,780 you can kind of help people, students and children alike, 750 00:33:45,780 --> 00:33:47,650 to kind of fill in the blanks literally. 751 00:33:47,650 --> 00:33:49,780 >> Now that puzzle-- that opening is a little small, 752 00:33:49,780 --> 00:33:52,750 and as we'll see in the program, in Scratch, it will grow to fit. 753 00:33:52,750 --> 00:33:54,830 It will maintain its shape, ultimately. 754 00:33:54,830 --> 00:33:58,350 So a condition let's you decide "should I do something or not?" 755 00:33:58,350 --> 00:34:00,470 A Boolean expression is the actual question 756 00:34:00,470 --> 00:34:04,100 you're using to decide do I go to the left OR do I go to the right 757 00:34:04,100 --> 00:34:06,710 when I encounter this so-called fork in the road? 758 00:34:06,710 --> 00:34:07,980 You can have two branches. 759 00:34:07,980 --> 00:34:10,909 IF something is true, do this, else go that way, 760 00:34:10,909 --> 00:34:14,590 or you can just do nothing at all, as this block implied. 761 00:34:14,590 --> 00:34:16,360 Similarly, we can nest these things. 762 00:34:16,360 --> 00:34:20,204 So if you want to triple fork in the road, either do this or this or that, 763 00:34:20,204 --> 00:34:21,870 you can just nest these things together. 764 00:34:21,870 --> 00:34:24,520 And it starts to get a little ugly, eventually, for sure, 765 00:34:24,520 --> 00:34:26,120 but the logic is still the same. 766 00:34:26,120 --> 00:34:28,000 You can literally read this top to bottom 767 00:34:28,000 --> 00:34:33,290 and it says what it means-- if this is true, do this, else if else. 768 00:34:33,290 --> 00:34:36,179 >> A loop doesn't get simpler in Scratch. 769 00:34:36,179 --> 00:34:37,422 Forever do the following. 770 00:34:37,422 --> 00:34:39,880 Now you might not think you can do much because there's not 771 00:34:39,880 --> 00:34:42,839 much space between the top and the bottom of this puzzle piece opening. 772 00:34:42,839 --> 00:34:45,671 But you'll see Scratch is going to grow to fit as many puzzle pieces 773 00:34:45,671 --> 00:34:47,060 as you want to cram in there. 774 00:34:47,060 --> 00:34:48,960 Another loop might be expressed with repeats. 775 00:34:48,960 --> 00:34:51,590 If you know in advance, "I want to do something 10 times," 776 00:34:51,590 --> 00:34:54,010 you can just tell Scratch to do something 10 times. 777 00:34:54,010 --> 00:34:57,260 And, meanwhile, we can have variables. 778 00:34:57,260 --> 00:34:59,572 So here's an arbitrary one, it's orange in this case, 779 00:34:59,572 --> 00:35:00,780 and this is a whirlwind tour. 780 00:35:00,780 --> 00:35:04,540 Again, you'll find this very accessible once you start pointing and clicking. 781 00:35:04,540 --> 00:35:07,930 I've named my variable n, but I could have named it anything I want, 782 00:35:07,930 --> 00:35:11,280 and I'm setting it here, in this arbitrary example, to zero. 783 00:35:11,280 --> 00:35:14,250 >> Now seeing a program like hello world is not all that compelling, 784 00:35:14,250 --> 00:35:17,900 so let's actually open up something that a former student made. 785 00:35:17,900 --> 00:35:23,100 Let me go ahead and open up, for instance, this one here, 786 00:35:23,100 --> 00:35:26,780 for which I would love to have a volunteer. 787 00:35:26,780 --> 00:35:28,450 All right, how about-- let's go farther. 788 00:35:28,450 --> 00:35:29,240 Yes, come on up. 789 00:35:29,240 --> 00:35:30,056 What's your name? 790 00:35:30,056 --> 00:35:30,635 >> ABBY: Abby. 791 00:35:30,635 --> 00:35:32,010 DAVID J. MALAN: Abby, come on up. 792 00:35:32,010 --> 00:35:35,930 So have you ever played this game before? 793 00:35:35,930 --> 00:35:36,430 ABBY: No. 794 00:35:36,430 --> 00:35:37,370 DAVID J. MALAN: All right. 795 00:35:37,370 --> 00:35:38,380 David, nice to meet you. 796 00:35:38,380 --> 00:35:39,620 Come on over. 797 00:35:39,620 --> 00:35:42,300 And what is your programming background, if any. 798 00:35:42,300 --> 00:35:43,914 >> ABBY: I've learned some C++. 799 00:35:43,914 --> 00:35:45,580 DAVID J. MALAN: You've learned some C++. 800 00:35:45,580 --> 00:35:48,382 And what is your game playing background? 801 00:35:48,382 --> 00:35:49,505 >> ABBY: Not a lot. 802 00:35:49,505 --> 00:35:51,130 DAVID J. MALAN: OK, so we'll take that. 803 00:35:51,130 --> 00:35:52,700 So here's how the game is going to work. 804 00:35:52,700 --> 00:35:54,510 I'm going to go ahead and click the green flag, which 805 00:35:54,510 --> 00:35:55,830 is up here at the top right. 806 00:35:55,830 --> 00:35:59,710 Now your predecessor in the class has given you some instructions here. 807 00:35:59,710 --> 00:36:02,306 And in just a moment, it says "space to begin." 808 00:36:02,306 --> 00:36:03,680 So go ahead and hit the spacebar. 809 00:36:03,680 --> 00:36:05,507 >> COMPUTER GAME: Pikachu. 810 00:36:05,507 --> 00:36:08,340 DAVID J. MALAN: And the goal is to catch the food, as depicted there 811 00:36:08,340 --> 00:36:09,320 on the left. 812 00:36:09,320 --> 00:36:11,388 And to [INAUDIBLE] 813 00:36:11,388 --> 00:36:15,356 >> [GAME MUSIC PLAYING] 814 00:36:15,356 --> 00:36:27,280 815 00:36:27,280 --> 00:36:29,610 >> DAVID J. MALAN: Aww, well, thank you for playing. 816 00:36:29,610 --> 00:36:32,800 We have here a little parting gift for you. 817 00:36:32,800 --> 00:36:35,574 We have CS50 stress ball, if you'd like to choose. 818 00:36:35,574 --> 00:36:36,820 All right, good to meet you. 819 00:36:36,820 --> 00:36:39,680 Thank you for coming and challenging. 820 00:36:39,680 --> 00:36:42,410 821 00:36:42,410 --> 00:36:46,910 So we have more stress balls, so let's do one more example to motivate. 822 00:36:46,910 --> 00:36:48,150 A volunteer? 823 00:36:48,150 --> 00:36:50,510 All right, how about right here in front. 824 00:36:50,510 --> 00:36:51,250 What's your name? 825 00:36:51,250 --> 00:36:51,660 >> PHILLIP: Phillip. 826 00:36:51,660 --> 00:36:52,660 >> DAVID J. MALAN: Phillip. 827 00:36:52,660 --> 00:36:54,530 Come on up, Phillip. 828 00:36:54,530 --> 00:36:57,340 So, Phillip is going to be challenged with another game 829 00:36:57,340 --> 00:37:00,840 that one of your predecessors wrote as part of problem set zero, 830 00:37:00,840 --> 00:37:03,510 called Ivy's Hardest Game. 831 00:37:03,510 --> 00:37:05,980 And we'll see in just a moment what's meant by this. 832 00:37:05,980 --> 00:37:07,400 Phillip, nice to meet you. 833 00:37:07,400 --> 00:37:09,060 What is your background? 834 00:37:09,060 --> 00:37:10,310 PHILLIP: Done a lot of coding. 835 00:37:10,310 --> 00:37:11,110 Done a little gaming, too. 836 00:37:11,110 --> 00:37:11,570 >> DAVID J. MALAN: OK. 837 00:37:11,570 --> 00:37:12,620 Got a lot of gaming, too. 838 00:37:12,620 --> 00:37:14,230 And have you played this game before? 839 00:37:14,230 --> 00:37:14,730 >> PHILLIP: No 840 00:37:14,730 --> 00:37:16,438 DAVID J. MALAN: All right, so here we go. 841 00:37:16,438 --> 00:37:18,434 I'm going to go ahead and click the green flag. 842 00:37:18,434 --> 00:37:24,160 >> [GAME MUSIC] 843 00:37:24,160 --> 00:37:27,770 >> [MUSIC MC HAMMER, "U CAN'T TOUCH THIS"] 844 00:37:27,770 --> 00:38:39,790 845 00:38:39,790 --> 00:38:41,635 >> PHILLIP: [INAUDIBLE] 846 00:38:41,635 --> 00:38:42,760 DAVID J. MALAN: [INAUDIBLE] 847 00:38:42,760 --> 00:38:44,740 PHILLIP: [INAUDIBLE] 848 00:38:44,740 --> 00:38:49,056 [LAUGHING] 849 00:38:49,056 --> 00:38:50,680 [MUSIC MC HAMMER, "U CAN'T TOUCH THIS"] 850 00:38:50,680 --> 00:38:52,660 DAVID J. MALAN: [INAUDIBLE] Plow through it. 851 00:38:52,660 --> 00:38:54,094 PHILLIP: [INAUDIBLE] 852 00:38:54,094 --> 00:38:55,135 DAVID J. MALAN: Go ahead. 853 00:38:55,135 --> 00:39:01,570 [MUSIC MC HAMMER, "U CAN'T TOUCH THIS"] 854 00:39:01,570 --> 00:39:15,832 855 00:39:15,832 --> 00:39:16,915 DAVID J. MALAN: All right. 856 00:39:16,915 --> 00:39:18,400 Congratulations. 857 00:39:18,400 --> 00:39:25,150 >> [APPLAUSE] 858 00:39:25,150 --> 00:39:27,330 >> DAVID J. MALAN: We will post that online later so 859 00:39:27,330 --> 00:39:29,820 that you can procrastinate with it as well. 860 00:39:29,820 --> 00:39:32,550 Princeton comes up next, after that. 861 00:39:32,550 --> 00:39:35,470 >> So now let's actually proceed to start from scratch, 862 00:39:35,470 --> 00:39:39,310 so to speak, and actually build up until we can tease apart some of these ideas 863 00:39:39,310 --> 00:39:41,970 and get to something even more complex by the end. 864 00:39:41,970 --> 00:39:45,240 I'm going to go over here and I'm going to go ahead and create a new file. 865 00:39:45,240 --> 00:39:47,460 So again, the problem set will walk you through some of these steps. 866 00:39:47,460 --> 00:39:49,300 But, all I did was go to the File menu and I 867 00:39:49,300 --> 00:39:52,760 said "new," so much like Microsoft Word, or any program like that. 868 00:39:52,760 --> 00:39:56,630 >> And let's go ahead now-- and we implemented "Hello world" a moment ago, 869 00:39:56,630 --> 00:39:58,410 but let's do something a little cuter. 870 00:39:58,410 --> 00:40:00,150 I'm going to go up to events. 871 00:40:00,150 --> 00:40:02,350 And I'm going to do "when green flag clicked." 872 00:40:02,350 --> 00:40:05,830 And then I'm going to use, shall we say, a branch. 873 00:40:05,830 --> 00:40:07,610 So I'm going to use an "if" condition. 874 00:40:07,610 --> 00:40:10,940 And notice how as soon as I get close to it, it wants to snap together. 875 00:40:10,940 --> 00:40:13,020 So I let go and it snaps together. 876 00:40:13,020 --> 00:40:15,150 And now I can do something interesting. 877 00:40:15,150 --> 00:40:19,150 If I scroll through here, I'm going to see a whole bunch of blocks. 878 00:40:19,150 --> 00:40:22,620 If I go to "data"-- let me zoom in-- there is something about variables. 879 00:40:22,620 --> 00:40:26,160 If I go to "motion," you can apparently turn things around. 880 00:40:26,160 --> 00:40:28,760 If I go to "operators"-- oh, this is interesting, 881 00:40:28,760 --> 00:40:31,000 I can pick a random number. 882 00:40:31,000 --> 00:40:34,119 So let me do something with only some probability, just because. 883 00:40:34,119 --> 00:40:36,160 I'm going to go ahead and drag this puzzle piece, 884 00:40:36,160 --> 00:40:37,910 this is that less than block, so it's just 885 00:40:37,910 --> 00:40:39,480 "is this number less than that one?" 886 00:40:39,480 --> 00:40:42,438 But I don't want a hard code a number because that be pretty pointless. 887 00:40:42,438 --> 00:40:46,270 So I'm going to drag this piece here, and notice how it snaps in, 888 00:40:46,270 --> 00:40:49,480 and now let me go ahead and say "if the number that's picked randomly 889 00:40:49,480 --> 00:40:51,820 is less than six, do the following." 890 00:40:51,820 --> 00:40:52,790 Now why less than six? 891 00:40:52,790 --> 00:40:56,400 What probability is this effectively going to give me, just intuitively? 892 00:40:56,400 --> 00:40:57,440 About 50%, right? 893 00:40:57,440 --> 00:41:01,190 If the number that's guess randomly between 1 and 10 is less than six, 894 00:41:01,190 --> 00:41:03,480 clearly it's one, two, three, four, or five. 895 00:41:03,480 --> 00:41:06,740 And so that's going to give me a 50% probability of what happening? 896 00:41:06,740 --> 00:41:09,890 >> Well let's do something like this, "play sound meow." 897 00:41:09,890 --> 00:41:11,750 And notice, again, the puzzle piece grows 898 00:41:11,750 --> 00:41:13,700 to fit, so long as the shapes match. 899 00:41:13,700 --> 00:41:14,910 That's what's important. 900 00:41:14,910 --> 00:41:18,000 Let me go over to Scratch here and click "play." 901 00:41:18,000 --> 00:41:19,300 Nothing happens. 902 00:41:19,300 --> 00:41:21,160 Is that a bug? 903 00:41:21,160 --> 00:41:21,999 No, not necessary. 904 00:41:21,999 --> 00:41:24,040 It could just be that a bigger number was chosen. 905 00:41:24,040 --> 00:41:25,762 So let's do it again. 906 00:41:25,762 --> 00:41:27,550 Nothing. 907 00:41:27,550 --> 00:41:28,344 >> [MEOW] 908 00:41:28,344 --> 00:41:29,510 DAVID J. MALAN: There it is. 909 00:41:29,510 --> 00:41:30,280 [MEOW] 910 00:41:30,280 --> 00:41:31,690 DAVID J. MALAN: Again. 911 00:41:31,690 --> 00:41:32,300 No. 912 00:41:32,300 --> 00:41:32,922 >> [MEOWING] 913 00:41:32,922 --> 00:41:35,380 DAVID J. MALAN: So if you've ever played a game, of course, 914 00:41:35,380 --> 00:41:38,500 where stuff is happening randomly, like the bad guys are coming or not 915 00:41:38,500 --> 00:41:41,350 coming on to the screen, or things are falling or not falling, 916 00:41:41,350 --> 00:41:43,610 that's just because something super simple like this is happening. 917 00:41:43,610 --> 00:41:46,010 Pick a random number, and if it's less than some value, 918 00:41:46,010 --> 00:41:49,100 maybe do this or maybe do that. 919 00:41:49,100 --> 00:41:51,340 We can incorporate that into a condition. 920 00:41:51,340 --> 00:41:52,600 Let's do something different. 921 00:41:52,600 --> 00:41:53,559 >> Let me throw that away. 922 00:41:53,559 --> 00:41:56,058 You can get rid of stuff by just dragging it off to the left 923 00:41:56,058 --> 00:41:56,810 and letting go. 924 00:41:56,810 --> 00:42:00,310 Let me go ahead and do a forever block and very quickly do something annoying. 925 00:42:00,310 --> 00:42:03,010 Let me go ahead and say "play sound meow." 926 00:42:03,010 --> 00:42:06,620 But I don't want this to be too annoying, so let me grab this block, 927 00:42:06,620 --> 00:42:09,090 "wait one second," and notice there's no more room for it. 928 00:42:09,090 --> 00:42:11,310 But if you go close enough, it wants to go there. 929 00:42:11,310 --> 00:42:14,100 So I let go and it will grow to fill the block. 930 00:42:14,100 --> 00:42:15,932 So now, this is a loop. 931 00:42:15,932 --> 00:42:16,432 [MEOWING] 932 00:42:16,432 --> 00:42:18,473 DAVID J. MALAN: I'm literally doing this forever. 933 00:42:18,473 --> 00:42:19,360 Again and again. 934 00:42:19,360 --> 00:42:21,510 That is just not natural sounding. 935 00:42:21,510 --> 00:42:24,800 Let me go ahead and change this to not one second, to two seconds 936 00:42:24,800 --> 00:42:25,854 and hit Enter. 937 00:42:25,854 --> 00:42:28,770 And what's nice about Scratch is that you could program interactively. 938 00:42:28,770 --> 00:42:32,450 Make a change, maybe hit Enter or Play again, and it will just keep going. 939 00:42:32,450 --> 00:42:34,962 Well, now why don't we do something a little cuter? 940 00:42:34,962 --> 00:42:39,680 Rather than do everything from scratch, let me go ahead and open up an advance 941 00:42:39,680 --> 00:42:43,180 made one, that I pre-baked, called "Pet the Cat." 942 00:42:43,180 --> 00:42:44,920 And we'll post all of these files online, 943 00:42:44,920 --> 00:42:48,464 and problem set zero will tell you how to access them and open them up. 944 00:42:48,464 --> 00:42:49,880 And notice, this is pretty simple. 945 00:42:49,880 --> 00:42:53,860 But in advance, I seem to have grabbed a "forever" block, so I've got a loop. 946 00:42:53,860 --> 00:42:55,500 And then I've got an "if" condition. 947 00:42:55,500 --> 00:42:57,410 I've got a Boolean expression. 948 00:42:57,410 --> 00:43:00,100 >> So in English, just glancing at this, especially if you've never 949 00:43:00,100 --> 00:43:04,278 programmed before, just intuitively, what is this going to do, this program? 950 00:43:04,278 --> 00:43:06,910 >> [AUDIENCE CHATTER] 951 00:43:06,910 --> 00:43:09,960 >> DAVID J. MALAN: If you pet the cat, the cat is going to meow, right? 952 00:43:09,960 --> 00:43:14,560 Because "forever unchecking" is the mouse pointer touching the cat. 953 00:43:14,560 --> 00:43:17,630 So to be clear, and I didn't say this before, all of these puzzle 954 00:43:17,630 --> 00:43:20,750 pieces and the script that we have combined them into, 955 00:43:20,750 --> 00:43:25,510 so to speak, a script is synonymous with program, really, belongs to this cat. 956 00:43:25,510 --> 00:43:30,110 And the reason is-- because notice how this same cat here is highlighted, 957 00:43:30,110 --> 00:43:32,710 down here you can create a second cat or dog or really 958 00:43:32,710 --> 00:43:33,970 anything you want graphically. 959 00:43:33,970 --> 00:43:35,900 You can import something from Photoshop, or the like, 960 00:43:35,900 --> 00:43:38,300 and integrate something if you want to make it for a project. 961 00:43:38,300 --> 00:43:40,174 And what you'll find, ultimately, is that you 962 00:43:40,174 --> 00:43:44,800 can add scripts, add puzzle pieces, to individual characters. 963 00:43:44,800 --> 00:43:47,210 So these all belong to this particular cat. 964 00:43:47,210 --> 00:43:51,770 So now if I go ahead and play this program, nothing's happening. 965 00:43:51,770 --> 00:43:52,970 But it is running. 966 00:43:52,970 --> 00:43:56,364 The program is in this forever loop, kind of waiting for what to happen? 967 00:43:56,364 --> 00:43:57,230 >> [AUDIENCE CHATTER] 968 00:43:57,230 --> 00:43:58,130 >> DAVID J. MALAN: To pet the cat. 969 00:43:58,130 --> 00:43:59,800 So if I move my mouse toward him-- 970 00:43:59,800 --> 00:44:02,420 >> [MEOWING] 971 00:44:02,420 --> 00:44:04,450 >> DAVID J. MALAN: So now I'm petting the cat. 972 00:44:04,450 --> 00:44:07,330 Meanwhile, we can have a double branch. 973 00:44:07,330 --> 00:44:10,370 Let me go ahead and open up don't pet the cat. 974 00:44:10,370 --> 00:44:12,160 We'll post this online as well. 975 00:44:12,160 --> 00:44:16,760 This is a little more complex, but without saying 976 00:44:16,760 --> 00:44:18,780 you can guess perhaps what's going to happen. 977 00:44:18,780 --> 00:44:20,160 >> [MEOWING] 978 00:44:20,160 --> 00:44:23,900 >> DAVID J. MALAN: Cat is meowing, grand old time. 979 00:44:23,900 --> 00:44:26,690 But this program is of course called "Don't Pet the Cat," 980 00:44:26,690 --> 00:44:29,350 so clearly, I want to pet the cat. 981 00:44:29,350 --> 00:44:30,490 >> [ROARING] 982 00:44:30,490 --> 00:44:31,940 >> DAVID J. MALAN: Don't pet the cat. 983 00:44:31,940 --> 00:44:34,230 Now, let's take a look at another example here. 984 00:44:34,230 --> 00:44:38,035 This one will be called "Hi, Hi, Hi," for reasons 985 00:44:38,035 --> 00:44:40,410 that will be clear, because as soon as I run this thing-- 986 00:44:40,410 --> 00:44:41,401 >> [SEAL BARKING] 987 00:44:41,401 --> 00:44:43,942 DAVID J. MALAN: Very easy to write annoying Scratch programs. 988 00:44:43,942 --> 00:44:45,300 [SEAL BARKING] 989 00:44:45,300 --> 00:44:48,540 DAVID J. MALAN: Now we won't go into great detail with all of these, 990 00:44:48,540 --> 00:44:51,150 but notice there is a couple of new features here. 991 00:44:51,150 --> 00:44:55,540 There's a variable, called "muted," and then there's a bunch of conditions. 992 00:44:55,540 --> 00:44:57,900 And for now, let me just tease you by saying 993 00:44:57,900 --> 00:45:03,170 that if this guy gets too annoying, I can hit the spacebar and he stops. 994 00:45:03,170 --> 00:45:05,880 Because the role being played by these two scripts is as follows. 995 00:45:05,880 --> 00:45:08,510 One of them is doing the barking every few seconds. 996 00:45:08,510 --> 00:45:11,305 The other one is just waiting for me to hit the spacebar. 997 00:45:11,305 --> 00:45:14,780 And if I do hit the spacebar, it's going to change 998 00:45:14,780 --> 00:45:18,096 the state of this variable, the value of this variable, that's apparently 999 00:45:18,096 --> 00:45:20,470 called "muted," I didn't call it something boring like n, 1000 00:45:20,470 --> 00:45:22,370 I called it an English word, "muted." 1001 00:45:22,370 --> 00:45:24,740 From 1 to 0 or 0 to 1. 1002 00:45:24,740 --> 00:45:26,830 From true to false or false to true. 1003 00:45:26,830 --> 00:45:28,930 And so you can actually see now, that you 1004 00:45:28,930 --> 00:45:31,720 could have two scripts, two programs running simultaneously, 1005 00:45:31,720 --> 00:45:34,360 and both of them might be sitting in a loop doing something. 1006 00:45:34,360 --> 00:45:38,067 Waiting for the human to do something like hitting spacebar. 1007 00:45:38,067 --> 00:45:38,650 [SEAL BARKING] 1008 00:45:38,650 --> 00:45:40,566 DAVID J. MALAN: And now he's on his way again. 1009 00:45:40,566 --> 00:45:41,640 [SEAL BARKING] 1010 00:45:41,640 --> 00:45:45,220 DAVID J. MALAN: So what else might we do with these examples? 1011 00:45:45,220 --> 00:45:50,920 Well, let's go ahead and do an example with counting sheep. 1012 00:45:50,920 --> 00:45:59,210 We'll continue this along the lines here of-- let's open up the sheep example. 1013 00:45:59,210 --> 00:46:02,460 And notice, much like before, this one, thankfully, is a little less annoying. 1014 00:46:02,460 --> 00:46:06,940 Once I hit play here-- Oh no, this is annoying. 1015 00:46:06,940 --> 00:46:10,130 He is going to baa with some probability. 1016 00:46:10,130 --> 00:46:11,050 Let's play this again. 1017 00:46:11,050 --> 00:46:15,221 >> [SHEEP BLEETING] 1018 00:46:15,221 --> 00:46:18,470 DAVID J. MALAN: The only difference is we've changed the costume, so to speak, 1019 00:46:18,470 --> 00:46:21,710 and we're halving and say what that actual number is. 1020 00:46:21,710 --> 00:46:24,680 Well let's go ahead and take this one step further. 1021 00:46:24,680 --> 00:46:28,190 And let me tease you with one other feature here. 1022 00:46:28,190 --> 00:46:31,800 Let's go ahead and open up a program called Threads. 1023 00:46:31,800 --> 00:46:36,620 So much like you can have one sprite, having multiple scripts, 1024 00:46:36,620 --> 00:46:41,250 you can have two sprites, a bird in a cat, each having their own script. 1025 00:46:41,250 --> 00:46:43,976 And each of them can operate simultaneously. 1026 00:46:43,976 --> 00:46:45,980 If you've ever heard the word "multithreading" 1027 00:46:45,980 --> 00:46:49,240 a computer is "multithreaded" means it can do multiple things at once, 1028 00:46:49,240 --> 00:46:50,880 and, indeed, so can Scratch. 1029 00:46:50,880 --> 00:46:52,690 >> And now notice the bird is kind of dumb. 1030 00:46:52,690 --> 00:46:55,100 It's just doing things randomly, bouncing off the screen. 1031 00:46:55,100 --> 00:46:59,460 Clearly the cat has been programmed to kind of have seeking capabilities 1032 00:46:59,460 --> 00:47:02,680 to home in on the bird because he's always pointing at him. 1033 00:47:02,680 --> 00:47:06,176 Until finally, he catches the actual bird. 1034 00:47:06,176 --> 00:47:08,550 So I won't dwell on the details here, but you can kind of 1035 00:47:08,550 --> 00:47:12,160 glimpse the same shapes, some "if" conditions, some variables, 1036 00:47:12,160 --> 00:47:15,740 maybe some loops, are ultimately doing the same thing. 1037 00:47:15,740 --> 00:47:18,400 >> Now let me go ahead and open up something else altogether, 1038 00:47:18,400 --> 00:47:20,920 to tease some of you, particularly those more comfortable, 1039 00:47:20,920 --> 00:47:22,760 what you can actually do with this. 1040 00:47:22,760 --> 00:47:26,080 I'm going to go ahead and open up Button here. 1041 00:47:26,080 --> 00:47:28,740 And this is a super simple-seeming program, 1042 00:47:28,740 --> 00:47:34,190 but watch what happens when I-- Watch what 1043 00:47:34,190 --> 00:47:39,860 happens when I open this version of it, here in the browser, scratch.mit.edu. 1044 00:47:39,860 --> 00:47:43,460 And when I click this big red button, notice what happens. 1045 00:47:43,460 --> 00:47:46,110 1046 00:47:46,110 --> 00:47:47,647 So what's going on here? 1047 00:47:47,647 --> 00:47:50,480 There's actually a lot more complexity going on underneath the hood, 1048 00:47:50,480 --> 00:47:52,896 even though I've implemented this, or frankly, Dan Bradley 1049 00:47:52,896 --> 00:47:54,660 has implemented this so simply. 1050 00:47:54,660 --> 00:47:59,540 He has designed a custom Scratch puzzle piece, known as a Scratch extension, 1051 00:47:59,540 --> 00:48:01,300 he called it Toggle. 1052 00:48:01,300 --> 00:48:06,332 >> And what Toggle does is it sends a message over the internet. 1053 00:48:06,332 --> 00:48:08,290 And that message itself looks a little cryptic. 1054 00:48:08,290 --> 00:48:10,248 But this, too, you'll understand by term's end. 1055 00:48:10,248 --> 00:48:14,930 The message he's actually sending looks a little something like this. 1056 00:48:14,930 --> 00:48:15,921 It's just text. 1057 00:48:15,921 --> 00:48:16,420 Cryptic. 1058 00:48:16,420 --> 00:48:19,130 You'll understand it by the time we get the problem set seven. 1059 00:48:19,130 --> 00:48:22,180 It's just sending a textual message over the internet to a server. 1060 00:48:22,180 --> 00:48:24,330 And that server is, ultimately, talking to this light bulb, which 1061 00:48:24,330 --> 00:48:27,240 has one of those fancy light bulbs in it that, itself, is talking 1062 00:48:27,240 --> 00:48:30,760 to the Wi-Fi in the network here, where a local device down here-- 1063 00:48:30,760 --> 00:48:34,400 and, ultimately, it's actually turning that light on and off. 1064 00:48:34,400 --> 00:48:36,240 But we can do more interesting things still. 1065 00:48:36,240 --> 00:48:38,270 Notice what Dan also did for us. 1066 00:48:38,270 --> 00:48:42,210 He made multiple sprites, each of which has a script waiting for a click. 1067 00:48:42,210 --> 00:48:44,030 And if I click red, it goes red. 1068 00:48:44,030 --> 00:48:46,780 If I get blue, it goes blueish. 1069 00:48:46,780 --> 00:48:49,854 Green, yellow, orange. 1070 00:48:49,854 --> 00:48:52,520 And all of this is happening by going way out onto the internet, 1071 00:48:52,520 --> 00:48:54,690 back down here to the light bulb, on and off. 1072 00:48:54,690 --> 00:48:57,981 >> And if you can believe it-- and this is perhaps one of the most complex Scratch 1073 00:48:57,981 --> 00:49:00,930 projects someone has implemented-- he did it, in fairness, in a day. 1074 00:49:00,930 --> 00:49:04,180 And that was the challenge we threw down to Dan when we saw have binary bulbs, 1075 00:49:04,180 --> 00:49:05,810 we have Scratch, how can we combine them? 1076 00:49:05,810 --> 00:49:08,410 And, indeed, this is absolutely something anyone in this room 1077 00:49:08,410 --> 00:49:14,250 could do by semester's end-- Is he reimplemented binary bulbs using 1078 00:49:14,250 --> 00:49:18,310 the same interface that was on our iPad on Wednesday. 1079 00:49:18,310 --> 00:49:22,000 So that now, if I actually click the plus over here, 1080 00:49:22,000 --> 00:49:25,250 we have one, two, three. 1081 00:49:25,250 --> 00:49:27,550 I can hit the 16 and turn that one on. 1082 00:49:27,550 --> 00:49:29,440 128, and so forth. 1083 00:49:29,440 --> 00:49:31,250 >> Now if that alone has and blown your mind, 1084 00:49:31,250 --> 00:49:35,680 you could do things far more accessible, not involving any hardware certainly. 1085 00:49:35,680 --> 00:49:38,320 Just things on the screen itself. 1086 00:49:38,320 --> 00:49:41,110 And, indeed, what most students end up doing is some kind of game, 1087 00:49:41,110 --> 00:49:44,600 some piece of artistic work, or some kind of interactive animation. 1088 00:49:44,600 --> 00:49:47,352 And I will say one of our favorites has been this one. 1089 00:49:47,352 --> 00:49:49,060 And I thought if we could dim the lights, 1090 00:49:49,060 --> 00:49:52,960 we'll take a glimpse at this final Scratch project in conclusion. 1091 00:49:52,960 --> 00:49:57,460 But what you'll should keep in mind, as I can tease you with one last detail, 1092 00:49:57,460 --> 00:49:59,140 sectioning will begin next week. 1093 00:49:59,140 --> 00:50:00,830 Office hours will begin next week. 1094 00:50:00,830 --> 00:50:04,410 Problem set zero will be posted CS50.harvard.edu later today. 1095 00:50:04,410 --> 00:50:06,430 And you will be greeted in problem set zero 1096 00:50:06,430 --> 00:50:10,070 to CS50's own Zamyla Chan, who guides most of our walkthroughs. 1097 00:50:10,070 --> 00:50:11,952 These are embedded videos in the problem sets 1098 00:50:11,952 --> 00:50:15,160 that will hold your hand through a lot of the initial set up and through many 1099 00:50:15,160 --> 00:50:16,570 of the possible design decisions. 1100 00:50:16,570 --> 00:50:19,570 So if you've ever had that emotion when picking up a homework assignment 1101 00:50:19,570 --> 00:50:21,030 and wondering, where do I begin? 1102 00:50:21,030 --> 00:50:23,510 She will have that answer for you. 1103 00:50:23,510 --> 00:50:27,720 And now, a final program from one of your predecessors 1104 00:50:27,720 --> 00:50:30,659 in answer to the question "What does the fox say?" 1105 00:50:30,659 --> 00:50:32,242 [MUSIC YLVIS, "WHAT DOES THE FOX SAY?] 1106 00:50:32,242 --> 00:50:40,178 1107 00:50:40,178 --> 00:50:41,666 >> YLVIS: (SINGING) Dog goes woof. 1108 00:50:41,666 --> 00:50:43,650 Cat goes meow. 1109 00:50:43,650 --> 00:50:47,520 Bird goes tweet and mouse goes squeak. 1110 00:50:47,520 --> 00:50:49,240 Cow goes moo. 1111 00:50:49,240 --> 00:50:51,690 Frog goes croak. 1112 00:50:51,690 --> 00:50:54,630 And the elephant goes toot. 1113 00:50:54,630 --> 00:50:59,040 Ducks say quack and fish go blub. 1114 00:50:59,040 --> 00:51:07,370 And the seal goes ow ow ow, but there's one sound that no one knows, 1115 00:51:07,370 --> 00:51:10,330 what does the fox say? 1116 00:51:10,330 --> 00:51:11,020 And 1117 00:51:11,020 --> 00:51:12,478 >> DAVID J. MALAN: That's it for CS50. 1118 00:51:12,478 --> 00:51:15,436 We will see you at Puzzle Day and on Monday. 1119 00:51:15,436 --> 00:51:16,424 >> [APPLAUSE] 1120 00:51:16,424 --> 00:51:19,882 >> [MUSIC YLVIS, "WHAT DOES THE FOX SAY?"] 1121 00:51:19,882 --> 00:51:24,840 1122 00:51:24,840 --> 00:51:28,820 >> NARRATOR: And now deep thoughts, by Daven Farnham. 1123 00:51:28,820 --> 00:51:31,770 1124 00:51:31,770 --> 00:51:34,570 Today I got hit in the face with a phone book. 1125 00:51:34,570 --> 00:51:38,160 Confusing, as I'm at home watching online. 1126 00:51:38,160 --> 00:51:42,528