So, [COUGH] let's do a couple more little exercises
that get you sort of in the mind set
of being a programmer, and how programmers tend to
have to think about problems a little bit differently.
So, here we go.
This I call this An Animated Short Story.
And your job, I'm going to just give you a differ, several sets of numbers.
And I want you to find the largest number in a list of numbers.
Now, it's not so important to know what the large
number is, but also to think about how your mind
attacks the problem.
What your eyes are doing.
What your mind is doing.
How you break a bigger problem down into smaller problems.
How a human solves this problem.
And then we'll focus on how a computer
might have to look at the problem differently, okay?
So don't just, like, get the answer.
That's not so important.
Think about how you get the answer.
So, don't just like scroll ahead in your YouTube and cheat and go get the answer.
Think about actually solving the problem, and then
monitor what your brain is thinking as it goes.
So, here we go.
So, I'm going to give you a list of numbers,
and you are to tell me what the largest number is.
Ready?
Set, go.
[BLANK_AUDIO]
[SOUND] I didn't make it easy, you're looking for the largest number.
[BLANK_AUDIO]
Did you get it?
Did you have to go back a couple of times?
Actually I don't care what the answer is.
The question is
How was your brain solving?
Okay, you probably want to know what it is.
The answer is 198, that was the largest number.
Of course what I was doing is I was moving it to make it difficult.
But here's the thing, how do humans look at this?
Like, do humans, like, did you look at 25, then you looked at 1, then you looked
at 114, and then did you just look at them slowly one at a time, like this?
Or no, I doubt it.
If you are, maybe you're a computer.
Maybe I'm talking to computers, maybe you're all computers.
I'm certainly not a computer, maybe you're all computers.
Okay, enough of that.
No, that's probably not how you did it.
What you probably did was you had your
eyes move around the whole thing very rapidly.
And the first thing that you figured out is that there
were one-digit blobs, there were small, medium, and large blobs of purple.
And the first thing you knew, right away, was there
was no point at looking at any of the small blobs.
Your brain just threw the blobs away really quick.
Then you say, okay, given that it,
there's no four-digit numbers, they're three-digit numbers.
Then what you probably did is you started looking for the first digit.
You say, look, there's some ones.
Is there any twos?
Quickly, you decided there are no twos.
So you knew that you had to look for the big blobs.
And the second digit was probably the thing that mattered.
Then you start getting to the nine, you say, okay, there's some nines.
So that means it's, it's one, nine, something.
Then that was the part that you probably had to go
check to find the, oh, where the heck was the 190, aah!
Oh, 198 right there, [LAUGH] yeah I color
coded it, and I couldn't even see it, okay?
But the point is, is, humans are great
at eliminating sort of bad solutions, really fast.
And you probably looked at how big, how much purple was on
the screen, eliminating the areas that were less purple, because you knew that
your brain quickly and instinctively knew that
the more purple meant a larger number.
Computers don't do any of that, they don't do any of that.
So, in order to make you feel a little more like a computer, I have another test.
And again, the goal is not just to find the largest number.
But to monitor as you go, what your brain is thinking, while you're doing this, okay?
Do you get it?
How are you attacking the problem, what is
your feeling as you're attacking the problem?
Are you a computer or not?
Here we go.
I'm only going to give you a few seconds.
[BLANK_AUDIO]
[SOUND]
So, what did
you get?
My guess is that most of you just said, I don't care.
This is such a hard problem.
It's a stupid problem.
Or I'll try and turn my head upside down, or something.
It's a really hard problem.
The other one was kind of easy.
Not that you, you might not have got it, but you
had this natural instinct that allowed you to approach the problem.
Okay, I'll show you what the right answer is.
The right answer is.
Right there is 197.
Yay.
Right.
I, you can't even, even if I tell you to
you know there you are you know, what is this?
Is this 500 or two zero zero.
Actually, the only way I can do this is I flip it to find it.
I mean it's just not what humans are good at.
This is a little bit more like how computers see the world.
But the fact that the data's frontwards or
backwards should sort of make no difference, right?
Computers need a strategy, we need to give them a strategy.
Okay.
So here we go.
[COUGH] One last experiment.
Now I'm going to show you numbers one at a time.
And at the end, I want you to tell me what the largest number that you saw was.
Ready?
Here we go.
First number.
What was the largest number?
As a matter of fact,
how did you solve that problem?
You solved that problem most likely because you didn't, you couldn't look
at all the numbers at the same time, so you probably created
a variable in your head without even knowing.
And you put into that variable.
You call the variable, the largest number I've seen so far.
And you haven't seen any, so let's say the
largest number you've seen so far is negative 1.
Then I show you 3 and you said to yourself.
Well.
Negative 1 is no longer the largest number I've seen.
So I'm going to keep that one, I'll keep 3.
That's the largest I've seen so far.
And now I see 41, 41 is larger than 3 so I will keep that.
And now I see 12, now 12 is crap because it's nowhere near as good as 41.
So I'm keeping 41.
74. Oh, 9.
9, not nearly as good as 41, so I'm gonna throw that one away.
74, better, better.
Keep it.
Keep that one.
So I'll keep 74.
And the last number is 15.
Don't even know it's the last number, but, we don't want to keep that one.
And so now, we're done.
So we know that at the end, what was during the loop the largest so far is
the actual largest of all the numbers, and
we don't remember exactly how many numbers there were.
So that's kind of like thinking like a
program, you know, this kind of sliding window.
Didn't matter if I gave you a billion numbers or five numbers.
I think there were five numbers, actually.
This notion of the largest so far is a powerful notion.
As a matter of fact, it's central to the program I've been showing you.
And I don't want you to try to understand this, but this part in the purple.
This part in the purple is really saying,
I'm going to loop through the counts of all the words.
So it's got a word like "the" is 15 times, and "clown" is four times.
And it's going to look through all the pairs of word-value combinations.
And it's going to basically say, I'm
going to go through the counts that I have.
And I'm going to check to see if the count I'm looking at
is bigger than the biggest count I've seen so far.
And if it is, I'm going to remember it.
Now, don't worry about this.
We haven't even covered any of this stuff.
That's what chapter two, three, four, five, six.
But this is an algorithm, a paragraph, a pattern.
That allows you to find the largest number, and we'll
look at this again in great detail in upcoming chapters.
So this is kind of thinking like
a computer, having a sliding window across the
long list of numbers, and coming up with
something that is the answer that you need.
Okay, so that's the end of this lecture.
Read Chapter One, write your Hello World program.
Make sure if you haven't, get Python installed.
As you read this chapter and even as you
install Python, and even as you write the first program,
don't get too stuck on the details.
I was confused for like eight weeks or six
weeks in my first programming class; you'll be confused too.
Just sort of wander through with me, keep at it.
It will start making sense at some point that's up
to you, I can't tell you when it's going to make sense.
So, if, don't sort of stare at everything until you get it.
Just kind of keep digging in, and keep understanding, and keep playing and
sooner or later this'll make a lot of sense to you, I promise you.
See you next lecture.