1 00:00:02,190 --> 00:00:05,260 So, [COUGH] let's do a couple more little exercises 2 00:00:05,260 --> 00:00:07,800 that get you sort of in the mind set 3 00:00:07,800 --> 00:00:10,560 of being a programmer, and how programmers tend to 4 00:00:10,560 --> 00:00:14,270 have to think about problems a little bit differently. 5 00:00:14,270 --> 00:00:15,410 So, here we go. 6 00:00:15,410 --> 00:00:19,250 This I call this An Animated Short Story. 7 00:00:19,250 --> 00:00:23,440 And your job, I'm going to just give you a differ, several sets of numbers. 8 00:00:23,440 --> 00:00:27,340 And I want you to find the largest number in a list of numbers. 9 00:00:28,530 --> 00:00:31,960 Now, it's not so important to know what the large 10 00:00:31,960 --> 00:00:36,150 number is, but also to think about how your mind 11 00:00:36,150 --> 00:00:37,660 attacks the problem. 12 00:00:37,660 --> 00:00:39,040 What your eyes are doing. 13 00:00:39,040 --> 00:00:40,040 What your mind is doing. 14 00:00:40,040 --> 00:00:43,440 How you break a bigger problem down into smaller problems. 15 00:00:43,440 --> 00:00:45,840 How a human solves this problem. 16 00:00:45,840 --> 00:00:48,000 And then we'll focus on how a computer 17 00:00:48,000 --> 00:00:50,230 might have to look at the problem differently, okay? 18 00:00:50,230 --> 00:00:52,590 So don't just, like, get the answer. 19 00:00:52,590 --> 00:00:53,760 That's not so important. 20 00:00:53,760 --> 00:00:55,650 Think about how you get the answer. 21 00:00:55,650 --> 00:00:59,900 So, don't just like scroll ahead in your YouTube and cheat and go get the answer. 22 00:00:59,900 --> 00:01:02,480 Think about actually solving the problem, and then 23 00:01:02,480 --> 00:01:05,480 monitor what your brain is thinking as it goes. 24 00:01:05,480 --> 00:01:06,450 So, here we go. 25 00:01:06,450 --> 00:01:09,380 So, I'm going to give you a list of numbers, 26 00:01:09,380 --> 00:01:13,020 and you are to tell me what the largest number is. 27 00:01:13,020 --> 00:01:13,424 Ready? 28 00:01:13,424 --> 00:01:15,176 Set, go. 29 00:01:15,176 --> 00:01:25,176 [BLANK_AUDIO] 30 00:01:26,334 --> 00:01:30,615 [SOUND] I didn't make it easy, you're looking for the largest number. 31 00:01:30,615 --> 00:01:40,535 [BLANK_AUDIO] 32 00:01:40,535 --> 00:01:43,832 Did you get it? 33 00:01:43,832 --> 00:01:47,220 Did you have to go back a couple of times? 34 00:01:47,220 --> 00:01:49,190 Actually I don't care what the answer is. 35 00:01:49,190 --> 00:01:51,030 The question is 36 00:01:51,030 --> 00:01:52,650 How was your brain solving? 37 00:01:52,650 --> 00:01:54,890 Okay, you probably want to know what it is. 38 00:01:54,890 --> 00:01:58,340 The answer is 198, that was the largest number. 39 00:01:58,340 --> 00:02:00,770 Of course what I was doing is I was moving it to make it difficult. 40 00:02:01,900 --> 00:02:07,060 But here's the thing, how do humans look at this? 41 00:02:07,060 --> 00:02:11,270 Like, do humans, like, did you look at 25, then you looked at 1, then you looked 42 00:02:11,270 --> 00:02:16,090 at 114, and then did you just look at them slowly one at a time, like this? 43 00:02:16,090 --> 00:02:17,540 Or no, I doubt it. 44 00:02:17,540 --> 00:02:20,410 If you are, maybe you're a computer. 45 00:02:20,410 --> 00:02:23,080 Maybe I'm talking to computers, maybe you're all computers. 46 00:02:23,080 --> 00:02:25,210 I'm certainly not a computer, maybe you're all computers. 47 00:02:25,210 --> 00:02:27,160 Okay, enough of that. 48 00:02:27,160 --> 00:02:28,930 No, that's probably not how you did it. 49 00:02:30,150 --> 00:02:32,010 What you probably did was you had your 50 00:02:32,010 --> 00:02:35,290 eyes move around the whole thing very rapidly. 51 00:02:35,290 --> 00:02:38,550 And the first thing that you figured out is that there 52 00:02:38,550 --> 00:02:43,110 were one-digit blobs, there were small, medium, and large blobs of purple. 53 00:02:44,250 --> 00:02:47,660 And the first thing you knew, right away, was there 54 00:02:47,660 --> 00:02:52,230 was no point at looking at any of the small blobs. 55 00:02:52,230 --> 00:02:55,680 Your brain just threw the blobs away really quick. 56 00:02:55,680 --> 00:02:57,340 Then you say, okay, given that it, 57 00:02:57,340 --> 00:03:00,200 there's no four-digit numbers, they're three-digit numbers. 58 00:03:00,200 --> 00:03:03,390 Then what you probably did is you started looking for the first digit. 59 00:03:03,390 --> 00:03:05,170 You say, look, there's some ones. 60 00:03:05,170 --> 00:03:06,830 Is there any twos? 61 00:03:06,830 --> 00:03:09,930 Quickly, you decided there are no twos. 62 00:03:09,930 --> 00:03:12,580 So you knew that you had to look for the big blobs. 63 00:03:12,580 --> 00:03:15,460 And the second digit was probably the thing that mattered. 64 00:03:15,460 --> 00:03:19,410 Then you start getting to the nine, you say, okay, there's some nines. 65 00:03:19,410 --> 00:03:21,470 So that means it's, it's one, nine, something. 66 00:03:22,570 --> 00:03:24,270 Then that was the part that you probably had to go 67 00:03:24,270 --> 00:03:29,520 check to find the, oh, where the heck was the 190, aah! 68 00:03:31,360 --> 00:03:34,200 Oh, 198 right there, [LAUGH] yeah I color 69 00:03:34,200 --> 00:03:37,250 coded it, and I couldn't even see it, okay? 70 00:03:37,250 --> 00:03:40,850 But the point is, is, humans are great 71 00:03:40,850 --> 00:03:45,500 at eliminating sort of bad solutions, really fast. 72 00:03:45,500 --> 00:03:48,850 And you probably looked at how big, how much purple was on 73 00:03:48,850 --> 00:03:52,980 the screen, eliminating the areas that were less purple, because you knew that 74 00:03:52,980 --> 00:03:56,350 your brain quickly and instinctively knew that 75 00:03:56,350 --> 00:03:59,840 the more purple meant a larger number. 76 00:04:01,110 --> 00:04:05,610 Computers don't do any of that, they don't do any of that. 77 00:04:05,610 --> 00:04:12,229 So, in order to make you feel a little more like a computer, I have another test. 78 00:04:13,960 --> 00:04:18,430 And again, the goal is not just to find the largest number. 79 00:04:18,430 --> 00:04:25,620 But to monitor as you go, what your brain is thinking, while you're doing this, okay? 80 00:04:25,620 --> 00:04:27,450 Do you get it? 81 00:04:28,660 --> 00:04:31,160 How are you attacking the problem, what is 82 00:04:31,160 --> 00:04:33,470 your feeling as you're attacking the problem? 83 00:04:33,470 --> 00:04:35,970 Are you a computer or not? 84 00:04:35,970 --> 00:04:37,931 Here we go. 85 00:04:37,931 --> 00:04:39,347 I'm only going to give you a few seconds. 86 00:04:39,347 --> 00:04:47,142 [BLANK_AUDIO] 87 00:04:47,142 --> 00:04:50,153 [SOUND] 88 00:04:56,153 --> 00:04:59,606 So, what did 89 00:04:59,606 --> 00:05:02,860 you get? 90 00:05:05,230 --> 00:05:10,090 My guess is that most of you just said, I don't care. 91 00:05:11,110 --> 00:05:13,490 This is such a hard problem. 92 00:05:13,490 --> 00:05:14,870 It's a stupid problem. 93 00:05:14,870 --> 00:05:17,950 Or I'll try and turn my head upside down, or something. 94 00:05:17,950 --> 00:05:19,660 It's a really hard problem. 95 00:05:19,660 --> 00:05:21,550 The other one was kind of easy. 96 00:05:21,550 --> 00:05:23,130 Not that you, you might not have got it, but you 97 00:05:23,130 --> 00:05:26,910 had this natural instinct that allowed you to approach the problem. 98 00:05:26,910 --> 00:05:29,300 Okay, I'll show you what the right answer is. 99 00:05:29,300 --> 00:05:30,400 The right answer is. 100 00:05:33,810 --> 00:05:37,870 Right there is 197. 101 00:05:37,870 --> 00:05:39,290 Yay. 102 00:05:39,290 --> 00:05:41,790 Right. 103 00:05:41,950 --> 00:05:42,780 I, you can't even, even if I tell you to 104 00:05:42,780 --> 00:05:45,610 you know there you are you know, what is this? 105 00:05:45,610 --> 00:05:52,120 Is this 500 or two zero zero. 106 00:05:52,120 --> 00:05:54,780 Actually, the only way I can do this is I flip it to find it. 107 00:05:54,780 --> 00:05:56,820 I mean it's just not what humans are good at. 108 00:05:58,460 --> 00:06:01,530 This is a little bit more like how computers see the world. 109 00:06:01,530 --> 00:06:03,910 But the fact that the data's frontwards or 110 00:06:03,910 --> 00:06:07,060 backwards should sort of make no difference, right? 111 00:06:07,060 --> 00:06:12,700 Computers need a strategy, we need to give them a strategy. 112 00:06:12,700 --> 00:06:13,200 Okay. 113 00:06:14,470 --> 00:06:15,075 So here we go. 114 00:06:15,075 --> 00:06:23,727 [COUGH] One last experiment. 115 00:06:23,727 --> 00:06:27,320 Now I'm going to show you numbers one at a time. 116 00:06:27,320 --> 00:06:32,304 And at the end, I want you to tell me what the largest number that you saw was. 117 00:06:32,304 --> 00:06:34,963 Ready? 118 00:06:34,963 --> 00:06:36,823 Here we go. 119 00:06:36,823 --> 00:06:38,890 First number. 120 00:06:49,890 --> 00:06:51,469 What was the largest number? 121 00:06:55,100 --> 00:06:55,600 As a matter of fact, 122 00:06:59,290 --> 00:07:01,550 how did you solve that problem? 123 00:07:02,820 --> 00:07:07,560 You solved that problem most likely because you didn't, you couldn't look 124 00:07:07,560 --> 00:07:10,980 at all the numbers at the same time, so you probably created 125 00:07:10,980 --> 00:07:13,280 a variable in your head without even knowing. 126 00:07:14,430 --> 00:07:17,050 And you put into that variable. 127 00:07:17,050 --> 00:07:20,390 You call the variable, the largest number I've seen so far. 128 00:07:22,100 --> 00:07:24,520 And you haven't seen any, so let's say the 129 00:07:24,520 --> 00:07:26,920 largest number you've seen so far is negative 1. 130 00:07:26,920 --> 00:07:31,460 Then I show you 3 and you said to yourself. 131 00:07:31,460 --> 00:07:31,960 Well. 132 00:07:33,260 --> 00:07:36,160 Negative 1 is no longer the largest number I've seen. 133 00:07:36,160 --> 00:07:37,900 So I'm going to keep that one, I'll keep 3. 134 00:07:37,900 --> 00:07:39,370 That's the largest I've seen so far. 135 00:07:39,370 --> 00:07:44,730 And now I see 41, 41 is larger than 3 so I will keep that. 136 00:07:44,730 --> 00:07:51,090 And now I see 12, now 12 is crap because it's nowhere near as good as 41. 137 00:07:51,090 --> 00:07:52,600 So I'm keeping 41. 138 00:07:52,600 --> 00:07:53,475 74. Oh, 9. 139 00:07:53,475 --> 00:08:00,160 9, not nearly as good as 41, so I'm gonna throw that one away. 140 00:08:00,160 --> 00:08:01,570 74, better, better. 141 00:08:01,570 --> 00:08:02,190 Keep it. 142 00:08:02,190 --> 00:08:03,120 Keep that one. 143 00:08:03,120 --> 00:08:04,130 So I'll keep 74. 144 00:08:04,130 --> 00:08:06,310 And the last number is 15. 145 00:08:06,310 --> 00:08:10,120 Don't even know it's the last number, but, we don't want to keep that one. 146 00:08:10,120 --> 00:08:11,470 And so now, we're done. 147 00:08:12,600 --> 00:08:18,970 So we know that at the end, what was during the loop the largest so far is 148 00:08:18,970 --> 00:08:20,850 the actual largest of all the numbers, and 149 00:08:20,850 --> 00:08:23,980 we don't remember exactly how many numbers there were. 150 00:08:23,980 --> 00:08:26,380 So that's kind of like thinking like a 151 00:08:26,380 --> 00:08:28,200 program, you know, this kind of sliding window. 152 00:08:29,230 --> 00:08:32,580 Didn't matter if I gave you a billion numbers or five numbers. 153 00:08:32,580 --> 00:08:34,920 I think there were five numbers, actually. 154 00:08:34,920 --> 00:08:37,320 This notion of the largest so far is a powerful notion. 155 00:08:37,320 --> 00:08:41,900 As a matter of fact, it's central to the program I've been showing you. 156 00:08:41,900 --> 00:08:47,280 And I don't want you to try to understand this, but this part in the purple. 157 00:08:49,470 --> 00:08:53,710 This part in the purple is really saying, 158 00:08:53,710 --> 00:08:56,410 I'm going to loop through the counts of all the words. 159 00:08:56,410 --> 00:09:02,310 So it's got a word like "the" is 15 times, and "clown" is four times. 160 00:09:02,310 --> 00:09:06,590 And it's going to look through all the pairs of word-value combinations. 161 00:09:06,590 --> 00:09:08,000 And it's going to basically say, I'm 162 00:09:08,000 --> 00:09:10,860 going to go through the counts that I have. 163 00:09:10,860 --> 00:09:12,590 And I'm going to check to see if the count I'm looking at 164 00:09:12,590 --> 00:09:16,730 is bigger than the biggest count I've seen so far. 165 00:09:16,730 --> 00:09:19,330 And if it is, I'm going to remember it. 166 00:09:19,330 --> 00:09:20,490 Now, don't worry about this. 167 00:09:20,490 --> 00:09:21,960 We haven't even covered any of this stuff. 168 00:09:21,960 --> 00:09:24,700 That's what chapter two, three, four, five, six. 169 00:09:24,700 --> 00:09:30,250 But this is an algorithm, a paragraph, a pattern. 170 00:09:30,250 --> 00:09:33,430 That allows you to find the largest number, and we'll 171 00:09:33,430 --> 00:09:37,270 look at this again in great detail in upcoming chapters. 172 00:09:37,270 --> 00:09:39,680 So this is kind of thinking like 173 00:09:39,680 --> 00:09:42,960 a computer, having a sliding window across the 174 00:09:42,960 --> 00:09:45,970 long list of numbers, and coming up with 175 00:09:45,970 --> 00:09:49,370 something that is the answer that you need. 176 00:09:52,090 --> 00:09:55,570 Okay, so that's the end of this lecture. 177 00:09:55,570 --> 00:09:59,080 Read Chapter One, write your Hello World program. 178 00:09:59,080 --> 00:10:02,560 Make sure if you haven't, get Python installed. 179 00:10:02,560 --> 00:10:05,470 As you read this chapter and even as you 180 00:10:05,470 --> 00:10:08,930 install Python, and even as you write the first program, 181 00:10:08,930 --> 00:10:11,240 don't get too stuck on the details. 182 00:10:12,340 --> 00:10:15,410 I was confused for like eight weeks or six 183 00:10:15,410 --> 00:10:19,490 weeks in my first programming class; you'll be confused too. 184 00:10:19,490 --> 00:10:21,870 Just sort of wander through with me, keep at it. 185 00:10:22,880 --> 00:10:25,690 It will start making sense at some point that's up 186 00:10:25,690 --> 00:10:28,900 to you, I can't tell you when it's going to make sense. 187 00:10:28,900 --> 00:10:32,430 So, if, don't sort of stare at everything until you get it. 188 00:10:32,430 --> 00:10:37,090 Just kind of keep digging in, and keep understanding, and keep playing and 189 00:10:37,090 --> 00:10:41,240 sooner or later this'll make a lot of sense to you, I promise you. 190 00:10:41,240 --> 00:10:42,010 See you next lecture.