WEBVTT

00:00:06.400 --> 00:00:08.760
SRINI DEVADAS: All right,
good morning, everyone.

00:00:08.760 --> 00:00:11.170
Oh, do we have a
treat for you today.

00:00:11.170 --> 00:00:16.210
I'm going to publicize, for
the first time, my hidden

00:00:16.210 --> 00:00:18.430
talent of mind reading.

00:00:18.430 --> 00:00:21.220
And since this is a
magic trick, you know,

00:00:21.220 --> 00:00:23.710
every magician
needs an assistant.

00:00:23.710 --> 00:00:27.100
And I want to introduce
Billy Moses to you.

00:00:27.100 --> 00:00:28.810
Billy is a PhD student.

00:00:28.810 --> 00:00:30.520
He already has three
degrees from MIT,

00:00:30.520 --> 00:00:32.840
but he wants a fourth, I guess.

00:00:32.840 --> 00:00:35.800
And so I'm going to turn
it over to Billy, here.

00:00:35.800 --> 00:00:39.580
And Billy is going to
sort of set things up.

00:00:39.580 --> 00:00:44.130
I'm just going to do my thing,
which is read your minds, OK?

00:00:44.130 --> 00:00:44.990
So go ahead, Billy.

00:00:44.990 --> 00:00:47.365
BILLY MOSES: So what's going
to happen is, I'm going to--

00:00:47.365 --> 00:00:48.460
I have this card
deck right here,

00:00:48.460 --> 00:00:50.290
normal card deck,
perfectly normal cards.

00:00:50.290 --> 00:00:51.680
They're not in any weird order.

00:00:51.680 --> 00:00:53.830
You can see them.

00:00:53.830 --> 00:00:57.044
I'm going to give five people
the opportunity to pull a card

00:00:57.044 --> 00:00:58.210
and then give it back to me.

00:00:58.210 --> 00:00:59.332
They can look at the card.

00:00:59.332 --> 00:01:00.790
Then what's going
to happen is, I'm

00:01:00.790 --> 00:01:05.470
going to turn over four of these
cards, show you the final card.

00:01:05.470 --> 00:01:08.425
And then Srini is trying-- going
to try to guess the fifth card.

00:01:08.425 --> 00:01:10.360
SRINI DEVADAS: Well, but
what I need you to do

00:01:10.360 --> 00:01:13.720
is, when I'm going to
guess, I need all of you

00:01:13.720 --> 00:01:16.950
to really focus on that hidden
card, I mean, in your heads,

00:01:16.950 --> 00:01:17.560
right?

00:01:17.560 --> 00:01:19.600
So I can't do individual
mind reading, just

00:01:19.600 --> 00:01:21.070
in case you guys were worried.

00:01:21.070 --> 00:01:23.380
So if you think I'm wearing
a terrible-colored shirt,

00:01:23.380 --> 00:01:25.510
I'm not going to know, OK?

00:01:25.510 --> 00:01:28.746
But if you all think
of this hidden card,

00:01:28.746 --> 00:01:30.120
I'm going to be
able to guess it.

00:01:30.120 --> 00:01:32.470
But so I need some
help, all right?

00:01:32.470 --> 00:01:36.190
BILLY MOSES: OK, anyone wants to
try pulling some of the cards?

00:01:36.190 --> 00:01:36.970
OK.

00:01:36.970 --> 00:01:37.490
SRINI DEVADAS: And I guess--

00:01:37.490 --> 00:01:37.950
BILLY MOSES: Take
your favorite card.

00:01:37.950 --> 00:01:38.192
SRINI DEVADAS:
--I can step out--

00:01:38.192 --> 00:01:38.483
BILLY MOSES: --it
can be anywhere.

00:01:38.483 --> 00:01:39.420
SRINI DEVADAS: --here, right?

00:01:39.420 --> 00:01:39.910
BILLY MOSES: Yeah.

00:01:39.910 --> 00:01:40.730
SRINI DEVADAS: All right.

00:01:40.730 --> 00:01:42.010
BILLY MOSES: And look at it.

00:01:42.010 --> 00:01:44.230
Give it back to me once you've--

00:01:44.230 --> 00:01:45.210
cool.

00:01:45.210 --> 00:01:46.600
Anyone else want to pick a card?

00:01:46.600 --> 00:01:47.433
Want to pick a card?

00:01:47.433 --> 00:01:47.967
Here you go.

00:01:47.967 --> 00:01:50.550
You can look at the full deck,
look at whatever card you want,

00:01:50.550 --> 00:01:52.880
pick it, cool.

00:01:52.880 --> 00:01:54.630
SRINI DEVADAS: We're
doing a little trick.

00:01:54.630 --> 00:01:55.352
BILLY MOSES: Anyone else
want to pick a card?

00:01:55.352 --> 00:01:56.352
You want to pick a card?

00:02:02.223 --> 00:02:05.760
OK, anyone else
want to pick a card?

00:02:05.760 --> 00:02:06.975
Want to pick a card?

00:02:11.340 --> 00:02:13.030
Cool, want to pick a card?

00:02:17.270 --> 00:02:25.030
Cool, OK, I've got my
cards all nice together.

00:02:38.240 --> 00:02:40.782
OK, so five cards, I'm
going to show you first.

00:02:40.782 --> 00:02:43.240
And then we're going to present
them in a fun way for Srini

00:02:43.240 --> 00:02:43.740
to see.

00:02:43.740 --> 00:02:45.450
So the five cards
are as follows.

00:02:45.450 --> 00:02:48.350
We have this wonderful
Seven of Clubs.

00:02:48.350 --> 00:02:52.640
We have a Jack of Hearts.

00:02:52.640 --> 00:02:56.860
We have Seven of Hearts.

00:02:56.860 --> 00:02:59.570
We have Queen of Spades.

00:02:59.570 --> 00:03:01.674
And we have Ten of Clubs.

00:03:01.674 --> 00:03:03.340
Now, for the people
who pulled the card,

00:03:03.340 --> 00:03:06.340
these are indeed the cards
that you gave me, right?

00:03:06.340 --> 00:03:08.840
No one missed their
card in the deck?

00:03:08.840 --> 00:03:10.390
OK, I'll go get Srini.

00:03:13.916 --> 00:03:15.540
SRINI DEVADAS: All
right, ready for me?

00:03:15.540 --> 00:03:16.248
BILLY MOSES: Yup.

00:03:18.630 --> 00:03:25.350
OK, the first card is
the Seven of Clubs.

00:03:25.350 --> 00:03:31.500
The second card is
the Jack of Hearts.

00:03:31.500 --> 00:03:37.890
The third card is
the Seven of Hearts.

00:03:37.890 --> 00:03:40.590
The fourth card is-- and this is
the final card that Srini will

00:03:40.590 --> 00:03:42.960
be able to see--

00:03:42.960 --> 00:03:45.330
the Queen of Spades.

00:03:45.330 --> 00:03:46.770
Now, everyone think to yourself.

00:03:46.770 --> 00:03:48.784
You've got to see the
card, the fifth card,

00:03:48.784 --> 00:03:49.950
that Srini is going to have.

00:03:49.950 --> 00:03:52.560
Think it very closely
in your mind, think.

00:03:52.560 --> 00:03:55.090
SRINI DEVADAS: All right,
definitely a clubs, definitely

00:03:55.090 --> 00:03:56.400
a clubs--

00:03:56.400 --> 00:03:59.325
OK, see-- and I'm getting--

00:04:03.360 --> 00:04:05.580
I'm getting at Ten of Clubs.

00:04:05.580 --> 00:04:08.310
BILLY MOSES: And it
is a Ten of Clubs.

00:04:08.310 --> 00:04:10.370
SRINI DEVADAS: All
right, thank you.

00:04:14.350 --> 00:04:20.690
All right, so I guess
I'll have to confess.

00:04:20.690 --> 00:04:24.650
I'm not a mind reader, but
I also did not cheat, OK?

00:04:24.650 --> 00:04:27.230
So there's an algorithm here.

00:04:27.230 --> 00:04:29.600
And do you guys want to
know what the algorithm is

00:04:29.600 --> 00:04:32.200
so you can go and try
this out, I guess,

00:04:32.200 --> 00:04:36.530
when you go back home next,
or whatever, at your dorms,

00:04:36.530 --> 00:04:39.680
or with your classmates?

00:04:39.680 --> 00:04:45.380
So it's not as easy as
it might seem, simply

00:04:45.380 --> 00:04:49.580
because the combinations aren't
really in our favor, right?

00:04:49.580 --> 00:04:53.540
So if you think about
it, there's 52 cards.

00:04:53.540 --> 00:04:55.870
So this is a regular
deck of cards.

00:04:55.870 --> 00:04:58.660
You know, it's as I said,
there's no cheating here.

00:04:58.660 --> 00:05:01.765
Billy showed me four cards.

00:05:06.680 --> 00:05:18.439
So which means the fifth
card could be 1 of 48, right?

00:05:18.439 --> 00:05:19.730
I mean, it's completely random.

00:05:19.730 --> 00:05:23.070
You guys picked these five
cards completely at random,

00:05:23.070 --> 00:05:25.880
so there's no way that
that fifth card could

00:05:25.880 --> 00:05:28.220
be anything specific, OK?

00:05:28.220 --> 00:05:33.590
So what Billy had to do
was, in the four cards

00:05:33.590 --> 00:05:40.010
that he showed me, he really
had to communicate one of--

00:05:40.010 --> 00:05:44.470
specifically, one
of 48 possibilities,

00:05:44.470 --> 00:05:46.000
which is kind of--
you know, if you

00:05:46.000 --> 00:05:48.374
look-- if you think about it,
then the math doesn't quite

00:05:48.374 --> 00:05:50.016
work out, right?

00:05:50.016 --> 00:05:52.170
And so if you just say--

00:05:52.170 --> 00:05:54.270
so what are the ways--

00:05:54.270 --> 00:05:57.600
how much information
could you imagine

00:05:57.600 --> 00:06:00.880
communicating, in terms of
bits of information, right?

00:06:00.880 --> 00:06:03.210
You know, in terms of
possibilities or bits,

00:06:03.210 --> 00:06:06.990
how much information do
you think that Billy could

00:06:06.990 --> 00:06:09.766
communicate in these
four cards, which

00:06:09.766 --> 00:06:10.890
were also picked at random.

00:06:10.890 --> 00:06:12.931
Obviously, they have to
be specific cards, right?

00:06:12.931 --> 00:06:14.760
He just put them
up there, right?

00:06:14.760 --> 00:06:17.010
So if I have four
cards, what are the ways

00:06:17.010 --> 00:06:19.260
that Billy could
communicate information.

00:06:19.260 --> 00:06:21.900
I mean, you saw what he did.

00:06:21.900 --> 00:06:22.540
Any ideas?

00:06:26.120 --> 00:06:27.820
Yeah, Ganatra?

00:06:27.820 --> 00:06:29.704
AUDIENCE: The order
the cards are placed.

00:06:29.704 --> 00:06:31.620
SRINI DEVADAS: The order
the cards are placed,

00:06:31.620 --> 00:06:33.422
so that's a great answer.

00:06:33.422 --> 00:06:35.880
But if you look at the order
in which the cards are placed,

00:06:35.880 --> 00:06:38.780
how many different
orderings are there?

00:06:38.780 --> 00:06:42.230
Four cards, how many
different orderings?

00:06:42.230 --> 00:06:46.370
4 factorial, right, and that is?

00:06:46.370 --> 00:06:50.750
24, so I'm not quite
at 48 yet, right?

00:06:50.750 --> 00:06:53.330
So that's a bit of a problem.

00:06:53.330 --> 00:06:56.020
So is there something else going
on other than the ordering?

00:06:58.680 --> 00:06:59.205
Yeah?

00:06:59.205 --> 00:07:01.080
AUDIENCE: The time rate
at which he put them.

00:07:04.294 --> 00:07:05.710
SRINI DEVADAS: So
you mean the way

00:07:05.710 --> 00:07:09.700
he put them up, you know,
slowly versus quickly?

00:07:09.700 --> 00:07:12.930
Or did you mean something
with which was--

00:07:12.930 --> 00:07:16.502
the time in terms of
exposure of the cards, or?

00:07:16.502 --> 00:07:17.328
AUDIENCE: Have some variations,
for example, whether the red is

00:07:17.328 --> 00:07:17.869
before black.

00:07:30.085 --> 00:07:32.460
SRINI DEVADAS: Well, but that's
all part of the ordering.

00:07:32.460 --> 00:07:36.660
I mean, you have to be
careful here, in that, I mean,

00:07:36.660 --> 00:07:38.550
you can't do both, right?

00:07:38.550 --> 00:07:40.650
I mean, you can't
constrain the ordering

00:07:40.650 --> 00:07:44.040
and then say that there's
24 different orderings.

00:07:44.040 --> 00:07:46.350
The moment you constrain
orderings, the number

00:07:46.350 --> 00:07:48.570
of orderings shrinks, right?

00:07:48.570 --> 00:07:53.144
So I will say that, as I said,
this is a very legit trick.

00:07:53.144 --> 00:07:54.310
It's completely algorithmic.

00:07:54.310 --> 00:07:56.268
We're going to write code
for it-- or I'm going

00:07:56.268 --> 00:07:58.350
to show you code for it.

00:07:58.350 --> 00:08:03.120
But there's nothing else
other than the ordering, OK?

00:08:03.120 --> 00:08:05.680
He is-- there's no
sleight of hand.

00:08:05.680 --> 00:08:08.046
There's no hidden communication.

00:08:08.046 --> 00:08:09.420
You know, he didn't
stress words,

00:08:09.420 --> 00:08:12.000
you know, Clubs meant
something, or you know,

00:08:12.000 --> 00:08:13.870
Spades meant something else.

00:08:13.870 --> 00:08:16.210
It was just the ordering, OK?

00:08:16.210 --> 00:08:21.854
And so there's a gap here in
terms of 24 and 48, right?

00:08:21.854 --> 00:08:24.270
And so what's cool about this
trick is that we're actually

00:08:24.270 --> 00:08:29.000
going to be able to do
this original trick,

00:08:29.000 --> 00:08:31.980
where the fifth card
could be one of 48,

00:08:31.980 --> 00:08:36.330
because we're going to do
one thing that you probably

00:08:36.330 --> 00:08:40.630
didn't notice, because we only
did the trick once, all right?

00:08:40.630 --> 00:08:43.890
And so let me explain how
this is going to work,

00:08:43.890 --> 00:08:45.660
with just sort of
randomly picking--

00:08:45.660 --> 00:08:47.160
I'm just going pick
the top 5 cards,

00:08:47.160 --> 00:08:48.870
assuming these are shuffled.

00:08:48.870 --> 00:08:51.520
And you can assume these things
that are at random, right?

00:08:51.520 --> 00:08:55.000
So I have five cards
that I've picked here.

00:08:55.000 --> 00:08:58.600
And can you all see them?

00:08:58.600 --> 00:09:02.355
OK, what do you notice
about these five cards?

00:09:05.130 --> 00:09:07.625
Anything-- yup, Fadi.

00:09:07.625 --> 00:09:09.500
AUDIENCE: There are four
types and five cards

00:09:09.500 --> 00:09:11.208
so there's at least
one that is repeated.

00:09:16.010 --> 00:09:17.260
SRINI DEVADAS: Right, so the--

00:09:17.260 --> 00:09:20.270
so you're saying
the suit, right?

00:09:20.270 --> 00:09:21.500
So it is clear.

00:09:21.500 --> 00:09:22.250
This is true here.

00:09:22.250 --> 00:09:25.790
You have the Seven of Clubs
and the Ten of Clubs, right?

00:09:25.790 --> 00:09:29.340
Oh are these the cards that
you pulled out, or close?

00:09:29.340 --> 00:09:33.010
Anyway, so they look pretty
similar to the ones we used,

00:09:33.010 --> 00:09:36.500
but that's probably just because
we didn't shuffle the deck.

00:09:36.500 --> 00:09:39.800
But obviously, if
you have five cards,

00:09:39.800 --> 00:09:43.640
and you only have
four suits, I guess

00:09:43.640 --> 00:09:47.450
you could call it the
pigeonhole principle from 6.042,

00:09:47.450 --> 00:09:50.120
but you're definitely
going to have

00:09:50.120 --> 00:09:54.650
a pair of cards that are going
to be of the same suit, right?

00:09:54.650 --> 00:09:58.030
I mean, there may be more than
two cards of the same suit,

00:09:58.030 --> 00:10:00.990
but you're guaranteed,
for any five cards--

00:10:00.990 --> 00:10:02.435
let me just pick another five--

00:10:02.435 --> 00:10:05.390
that two of them are going to
be of the same suit, right?

00:10:05.390 --> 00:10:06.930
That's pretty much guaranteed.

00:10:06.930 --> 00:10:09.660
And so we ended up
getting clubs again here.

00:10:09.660 --> 00:10:14.580
And so you have Two and
Four of the same suit.

00:10:14.580 --> 00:10:17.420
So the first thing that
happens in this trick

00:10:17.420 --> 00:10:22.710
is, we use the first card
to give away the suit.

00:10:22.710 --> 00:10:26.840
Or Billy used the first
card to give away the suit.

00:10:26.840 --> 00:10:32.090
Doesn't quite finish
the story here,

00:10:32.090 --> 00:10:34.370
because let's just
say that I'm going

00:10:34.370 --> 00:10:41.990
to use the first card
to signify the suit.

00:10:47.090 --> 00:10:54.780
So in this case, let's just
say I am going to do Clubs.

00:10:54.780 --> 00:10:58.260
Now, I have a choice here.

00:10:58.260 --> 00:11:04.850
I could-- Billy could
have hidden Two,

00:11:04.850 --> 00:11:08.570
and showed me the Four of
Clubs as the first card, right,

00:11:08.570 --> 00:11:09.804
or vice versa.

00:11:09.804 --> 00:11:11.720
And keep that in mind,
because that's actually

00:11:11.720 --> 00:11:14.270
incredibly important.

00:11:14.270 --> 00:11:17.030
But if you just say
that the first card is

00:11:17.030 --> 00:11:20.450
going to signify
the suit, then let's

00:11:20.450 --> 00:11:22.520
say the suit is now
out of the picture,

00:11:22.520 --> 00:11:25.730
so I know the suit of the card.

00:11:25.730 --> 00:11:32.100
How many-- so I have three
cards left, all right?

00:11:32.100 --> 00:11:34.920
And I got a hidden card.

00:11:34.920 --> 00:11:41.250
I know the suit of the hidden
card, but that card could be--

00:11:41.250 --> 00:11:46.030
the hidden card-- how many
possibilities are there

00:11:46.030 --> 00:11:47.870
for the hidden card now?

00:11:50.560 --> 00:11:51.970
How many possibilities?

00:11:51.970 --> 00:11:55.410
I mean, this is all at random.

00:11:55.410 --> 00:11:56.708
Well, 13.

00:11:56.708 --> 00:11:58.142
AUDIENCE: 12

00:11:58.142 --> 00:12:00.660
SRINI DEVADAS: Oh, good
point, good, good, good--

00:12:00.660 --> 00:12:03.510
see, this is exactly why
I need attentive students.

00:12:03.510 --> 00:12:09.790
OK, good, so there's 12
possibilities since one of them

00:12:09.790 --> 00:12:10.510
was--

00:12:10.510 --> 00:12:12.590
one of them was shown, right?

00:12:12.590 --> 00:12:15.650
So did that help us?

00:12:15.650 --> 00:12:18.460
There are three cards left,
and so how many different--

00:12:18.460 --> 00:12:20.830
I mean, the first card
is the first card,

00:12:20.830 --> 00:12:23.950
so it's no longer part
of this permutation.

00:12:23.950 --> 00:12:25.900
I can't count it in terms
of the permutations.

00:12:25.900 --> 00:12:27.305
There's only three cards left.

00:12:27.305 --> 00:12:28.930
And those-- certainly
those three cards

00:12:28.930 --> 00:12:32.440
could be ordered
in a certain way,

00:12:32.440 --> 00:12:34.600
but how many combinations
or permutations

00:12:34.600 --> 00:12:37.380
are there of three cards?

00:12:37.380 --> 00:12:41.850
Only six permutations, so again,
I seem to have a problem here.

00:12:41.850 --> 00:12:46.020
I don't seem to have solved
the original problem of the 24

00:12:46.020 --> 00:12:47.200
to 48.

00:12:47.200 --> 00:12:50.100
I still have a 6-12 gap, right?

00:12:50.100 --> 00:12:53.940
So we're going to have to
somehow cover that gap.

00:12:53.940 --> 00:12:56.790
And any thoughts?

00:12:56.790 --> 00:12:58.170
I gave you a little
bit of a hint

00:12:58.170 --> 00:13:01.290
as to how this gap is going
to be covered when I talked

00:13:01.290 --> 00:13:03.630
about the Two and the Four.

00:13:03.630 --> 00:13:08.520
How am I going to cover
this gap, the 6-12 gap?

00:13:15.870 --> 00:13:17.086
Yeah, Kanishka.

00:13:17.086 --> 00:13:17.783
AUDIENCE: Possibly by
saying odd or even.

00:13:17.783 --> 00:13:20.408
So if the next card you can say
odd or even you shrink it down.

00:13:24.047 --> 00:13:25.630
SRINI DEVADAS: But
you mean-- say, you

00:13:25.630 --> 00:13:27.171
mean Billy is going
to say something?

00:13:27.171 --> 00:13:29.280
AUDIENCE: No, he's going
to present the next card.

00:13:29.280 --> 00:13:29.764
SRINI DEVADAS: Yeah.

00:13:29.764 --> 00:13:30.316
AUDIENCE: Whether it is thinking
that the final card you have

00:13:30.316 --> 00:13:30.657
to guess is odd or even
and you can shrink down

00:13:30.657 --> 00:13:31.407
the possibilities.

00:13:37.467 --> 00:13:39.800
SRINI DEVADAS: So, I mean,
he-- the only thing he can do

00:13:39.800 --> 00:13:44.570
is give me an ordering of the
remaining three cards, right?

00:13:44.570 --> 00:13:45.759
Yeah, go ahead.

00:13:45.759 --> 00:13:46.300
Kevin, right?

00:13:46.300 --> 00:13:47.966
AUDIENCE: Yeah, maybe
you used the cards

00:13:47.966 --> 00:13:52.700
to make a low-to-high
limit on the range.

00:13:52.700 --> 00:13:55.820
SRINI DEVADAS: That's good, and
low-a-high limit on the range,

00:13:55.820 --> 00:13:57.990
exactly right.

00:13:57.990 --> 00:14:03.770
So what's happening here is, not
only do I have the first card--

00:14:03.770 --> 00:14:07.240
and it's not the first card
is just giving me the suit.

00:14:07.240 --> 00:14:09.170
I mean, that's the
way I said it, right?

00:14:09.170 --> 00:14:11.930
But the first card also
has a number on it, right?

00:14:11.930 --> 00:14:13.770
The first card has
a number on it.

00:14:13.770 --> 00:14:16.880
So that number
could be an anchor

00:14:16.880 --> 00:14:21.950
that is going to help me figure
out what the hidden card is,

00:14:21.950 --> 00:14:22.760
right?

00:14:22.760 --> 00:14:24.710
And what's important
to understand,

00:14:24.710 --> 00:14:28.730
and this is really the
last interesting point

00:14:28.730 --> 00:14:30.980
with respect to shrinking
these possibilities

00:14:30.980 --> 00:14:37.190
or these permutations down, is
you want to think about your--

00:14:37.190 --> 00:14:42.680
let me draw this out properly
in a nice little circle.

00:14:42.680 --> 00:14:49.470
You don't want to think about
just a ascending sequence

00:14:49.470 --> 00:14:52.780
of cards or numbers.

00:14:52.780 --> 00:14:57.310
You want to think about this as
being circular, as you'll see,

00:14:57.310 --> 00:14:58.660
for the following reason.

00:15:08.084 --> 00:15:11.382
All right, so let's
just say the ace is a 1.

00:15:11.382 --> 00:15:12.840
And so we're going
to think of that

00:15:12.840 --> 00:15:18.540
as being the smallest number,
so you go 1 through 13,

00:15:18.540 --> 00:15:19.350
in this case.

00:15:19.350 --> 00:15:21.040
The king is a 13.

00:15:21.040 --> 00:15:22.750
All right, so
that's your number.

00:15:22.750 --> 00:15:25.474
And so you could imagine
you'd go 1 through 13.

00:15:25.474 --> 00:15:26.640
So let's just do that first.

00:15:26.640 --> 00:15:29.490
And then I'll explain to you
why I drew it in a circle.

00:15:29.490 --> 00:15:34.830
And the first thing
that happens is,

00:15:34.830 --> 00:15:38.320
I'm going to take
some card here.

00:15:38.320 --> 00:15:42.160
And I'm going to make
that the first card,

00:15:42.160 --> 00:15:44.420
so I don't care
about suits anymore.

00:15:44.420 --> 00:15:47.490
And if I just picked this--

00:15:47.490 --> 00:15:48.320
another five cards.

00:15:48.320 --> 00:15:52.060
Let's just do this again, but
with another set of five cards.

00:15:52.060 --> 00:15:53.580
And what do I have here?

00:15:53.580 --> 00:15:57.170
Oh, I've got mostly hearts, OK.

00:15:57.170 --> 00:16:00.300
So let me do something
more interesting.

00:16:00.300 --> 00:16:02.940
This is too many hearts here.

00:16:02.940 --> 00:16:05.040
Right, let's do this.

00:16:05.040 --> 00:16:10.200
So now, I got a Two and a Jack.

00:16:10.200 --> 00:16:12.360
And I got a Ten an an Eight.

00:16:12.360 --> 00:16:15.990
OK, now I'll make this even
more interesting by picking--

00:16:15.990 --> 00:16:17.260
I want to pick--

00:16:17.260 --> 00:16:19.020
I want to get a hearts card.

00:16:19.020 --> 00:16:20.460
And let's see how this works.

00:16:26.196 --> 00:16:32.170
Ah finally, all right, so this
is what I have, King of Hearts,

00:16:32.170 --> 00:16:34.090
the Eight of Spades, et cetera.

00:16:34.090 --> 00:16:39.460
So the two cards with the same
suit are the Two and the Jack.

00:16:39.460 --> 00:16:43.520
And so here's the
important thing.

00:16:43.520 --> 00:16:46.810
One of the things that Billy
did, kind of, in a subtle way,

00:16:46.810 --> 00:16:51.160
I'm assuming, and some of
you may have picked up on it.

00:16:51.160 --> 00:16:54.580
The very first card
that he asked one of you

00:16:54.580 --> 00:16:57.700
to pick certainly wasn't
the hidden card, right?

00:16:57.700 --> 00:16:59.860
I mean, he got all five cards.

00:16:59.860 --> 00:17:03.070
And then he decided
which of the cards

00:17:03.070 --> 00:17:05.270
was going to be the
hidden card and then took

00:17:05.270 --> 00:17:08.319
the remaining four
cards and encoded them.

00:17:08.319 --> 00:17:11.710
And if you don't do that, if
you just say this, if you--

00:17:11.710 --> 00:17:15.640
this trick won't work if
this is the hidden card.

00:17:15.640 --> 00:17:19.569
This trick is only going
to work as it turns out

00:17:19.569 --> 00:17:24.160
if the hidden card is a Two.

00:17:24.160 --> 00:17:30.910
It won't even work if the
hidden card is a Jack.

00:17:30.910 --> 00:17:32.520
And there's a reason for that.

00:17:32.520 --> 00:17:36.040
And you-- can you think
of the reason for that

00:17:36.040 --> 00:17:37.819
if you look at the board?

00:17:37.819 --> 00:17:39.360
Can you think of
the reason for that?

00:17:39.360 --> 00:17:41.122
Someone other than Fadi?

00:17:44.426 --> 00:17:47.260
Someone else?

00:17:47.260 --> 00:17:48.920
What do you see up here?

00:17:48.920 --> 00:17:50.150
So what am I trying to do?

00:17:50.150 --> 00:17:52.550
In terms of-- what
would happen--

00:17:52.550 --> 00:17:53.720
you guys talked about--

00:17:53.720 --> 00:17:56.040
Kevin mentioned distance
and things like that, right?

00:17:56.040 --> 00:17:57.630
You know, you call
it the offset.

00:17:57.630 --> 00:18:05.840
So what would happen if I hid
the Jack, and I did this--

00:18:05.840 --> 00:18:08.000
I did something
like this, where I--

00:18:08.000 --> 00:18:11.540
the Two of Diamonds was the
first card that was put out.

00:18:11.540 --> 00:18:15.080
And then I tried to
encode and number

00:18:15.080 --> 00:18:16.610
using these remaining
three cards,

00:18:16.610 --> 00:18:19.160
what's the biggest number
that I could encode?

00:18:19.160 --> 00:18:20.270
I mean, in--

00:18:20.270 --> 00:18:25.240
I need to encode lots
of numbers, right?

00:18:25.240 --> 00:18:27.970
So what's the biggest number
that I could encode here?

00:18:27.970 --> 00:18:30.700
If I had six permutations,
and I start with one,

00:18:30.700 --> 00:18:35.110
the biggest number that I
could encode is a 6, right?

00:18:35.110 --> 00:18:40.240
Sadly, the Jack is too far
away from the two, right?

00:18:40.240 --> 00:18:45.130
If I think of the Jack as being
an 11, it's 9 away from the 2,

00:18:45.130 --> 00:18:46.040
right?

00:18:46.040 --> 00:18:50.030
But help me out here,
what could I do?

00:18:50.030 --> 00:18:53.704
If I flipped it, what happens?

00:18:53.704 --> 00:18:55.150
AUDIENCE: Count backwards

00:18:55.150 --> 00:18:56.858
SRINI DEVADAS: You
could count backwards.

00:18:56.858 --> 00:18:59.007
Or what do I have up
there on the board?

00:18:59.007 --> 00:19:00.590
What do you see up
there on the board?

00:19:04.684 --> 00:19:06.100
I wrote something
that was linear,

00:19:06.100 --> 00:19:10.050
but what do I have
up there on the left?

00:19:10.050 --> 00:19:13.750
Circular, so you think mod,
mod arithmetic you know, think

00:19:13.750 --> 00:19:16.180
of this as being circular, OK?

00:19:16.180 --> 00:19:26.050
So what happens is that, if I
picked a 2 and a Jack, if I--

00:19:26.050 --> 00:19:28.390
what I want to do
is to go clockwise.

00:19:28.390 --> 00:19:36.980
OK and because there are only
13 cards, for any pair of cards,

00:19:36.980 --> 00:19:42.710
it's always the case that I can
choose the first card in such

00:19:42.710 --> 00:19:46.280
a way that the hidden
card is, at most, 6

00:19:46.280 --> 00:19:50.270
away from the first card, OK?

00:19:50.270 --> 00:19:54.380
Because you could get
into a situation where,

00:19:54.380 --> 00:19:59.630
obviously, if I ended up hiding
the Jack and exposing the 2,

00:19:59.630 --> 00:20:03.170
I end up getting a 9, which
is impossible to encode.

00:20:03.170 --> 00:20:10.810
But if I hide the 2 and expose
the Jack, then I go 1, 2, 3, 4,

00:20:10.810 --> 00:20:14.540
and I am at, basically, 4, OK?

00:20:14.540 --> 00:20:16.520
So that's the last thing.

00:20:16.520 --> 00:20:18.080
So let's just do
this really quickly

00:20:18.080 --> 00:20:22.100
with yet another
set of five cards.

00:20:22.100 --> 00:20:25.590
Now obviously we practiced so
we could do this fairly quickly,

00:20:25.590 --> 00:20:26.090
right?

00:20:26.090 --> 00:20:29.600
But-- and you can practice too,
but sometimes with things you

00:20:29.600 --> 00:20:33.196
get lucky, you know, and you
get easy things to encode.

00:20:33.196 --> 00:20:34.070
So what happens here?

00:20:34.070 --> 00:20:37.550
Someone wants to-- so now
that you know the algorithm,

00:20:37.550 --> 00:20:40.700
you have some choices here,
but obviously you have--

00:20:40.700 --> 00:20:41.960
not all choices would work.

00:20:41.960 --> 00:20:43.790
You've got to be a
little bit careful.

00:20:43.790 --> 00:20:47.920
What would you hide?

00:20:47.920 --> 00:20:50.570
So you need to make
sure that you get--

00:20:50.570 --> 00:20:52.202
you can choose a pair of--

00:20:52.202 --> 00:20:53.660
I'll make this a
little bit easier.

00:20:58.600 --> 00:21:04.390
Sometimes choices make
things more difficult.

00:21:04.390 --> 00:21:08.700
Perfect, all right, so
what you see here is--

00:21:08.700 --> 00:21:10.930
you know that you have
to do the clubs now,

00:21:10.930 --> 00:21:15.520
because you have the clubs as
being the suit that's repeated.

00:21:15.520 --> 00:21:17.920
No other suits are
repeated, right?

00:21:17.920 --> 00:21:20.590
So what am I going to expose?

00:21:20.590 --> 00:21:22.330
And what am I going to hide?

00:21:22.330 --> 00:21:25.250
That's your first
question, right?

00:21:25.250 --> 00:21:27.560
Someone else?

00:21:27.560 --> 00:21:29.560
You guys are all going
to have to do this trick.

00:21:29.560 --> 00:21:31.870
That's the final
exam for this class.

00:21:31.870 --> 00:21:36.850
On Friday next week, you're
all doing the trick-- no.

00:21:36.850 --> 00:21:38.720
So what am I going to--

00:21:38.720 --> 00:21:39.670
yeah, go ahead, Josh?

00:21:39.670 --> 00:21:42.923
AUDIENCE: You are going to
hide the Ace, the King of Clubs

00:21:42.923 --> 00:21:44.150
would be the first card.

00:21:44.150 --> 00:21:46.608
SRINI DEVADAS: You're going to
hide the Ace, exactly right.

00:21:46.608 --> 00:21:48.350
You want to hide
the Ace, because you

00:21:48.350 --> 00:21:49.527
want to go this way.

00:21:49.527 --> 00:21:52.110
And if you do it the other way
around, it's not going to work.

00:21:52.110 --> 00:21:53.318
You're going to hide the Ace.

00:21:53.318 --> 00:21:58.050
And you're going to make
the King the first card.

00:21:58.050 --> 00:22:02.780
And now, what you need to
do is-- this is gone, right?

00:22:02.780 --> 00:22:05.210
And now what I need
to do is, I need

00:22:05.210 --> 00:22:10.760
to encode a number between
1 and 6, in general.

00:22:10.760 --> 00:22:14.480
In this case, I need to
encode the number 1 in order

00:22:14.480 --> 00:22:19.430
to give away the fact that
the hidden card is an ace.

00:22:19.430 --> 00:22:23.310
And now I could do what
was suggested before,

00:22:23.310 --> 00:22:25.670
which is have some sort of--

00:22:25.670 --> 00:22:27.830
I mean, there's
obviously an ordering

00:22:27.830 --> 00:22:32.000
associated with these
cards that you see up here.

00:22:32.000 --> 00:22:34.940
If I call this a 1
and I call this a 13,

00:22:34.940 --> 00:22:37.850
then lets do the
logical thing, which

00:22:37.850 --> 00:22:40.880
is, 1 is smaller than 2,
which is smaller than 13,

00:22:40.880 --> 00:22:42.200
but I might end up--

00:22:42.200 --> 00:22:44.750
I might have and
Nine of Hearts here

00:22:44.750 --> 00:22:46.490
rather than a Five of Hearts.

00:22:46.490 --> 00:22:50.750
And I got to, obviously, be
able to order the Nine of Hearts

00:22:50.750 --> 00:22:54.110
in relation to the Five
of Hearts as well, so--

00:22:54.110 --> 00:22:56.900
because I-- all of these could
be nines actually, right?

00:22:56.900 --> 00:23:01.790
And so I can't just rely on
the number to do the ordering,

00:23:01.790 --> 00:23:04.670
so I can just choose
an arbitrary--

00:23:04.670 --> 00:23:09.200
clubs is smallest.

00:23:09.200 --> 00:23:12.980
Diamonds is the next.

00:23:12.980 --> 00:23:15.680
And then I got Hearts.

00:23:15.680 --> 00:23:18.560
I just did this because
this is a little bit

00:23:18.560 --> 00:23:20.570
easy to remember for me.

00:23:20.570 --> 00:23:22.550
You can do this in
many different ways,

00:23:22.550 --> 00:23:26.960
in alphabetical order,
you know, C-D-H-S.

00:23:26.960 --> 00:23:30.410
And so this-- that's moot here.

00:23:30.410 --> 00:23:33.810
What I need to do is to
encode the number one, OK?

00:23:33.810 --> 00:23:36.440
But I encoded-- in order
to encode the number one,

00:23:36.440 --> 00:23:39.320
I have to have some sort
of way of ordering this.

00:23:39.320 --> 00:23:44.250
And so what I'm going to do is,
I'm going to say SLM is one.

00:23:44.250 --> 00:23:46.460
So what do I mean by SLM?

00:23:46.460 --> 00:23:51.740
The smallest card is first--

00:23:51.740 --> 00:23:55.390
I'm sorry, SML is--

00:23:55.390 --> 00:23:58.170
increasing.

00:23:58.170 --> 00:24:01.320
The smallest card
is the first one.

00:24:01.320 --> 00:24:03.670
The medium card
is the second one.

00:24:03.670 --> 00:24:06.960
And the largest card
is the third one, OK?

00:24:06.960 --> 00:24:08.800
And I'll write this out.

00:24:08.800 --> 00:24:10.390
And you can see the code for it.

00:24:10.390 --> 00:24:15.300
But when you see something like
LMS, you're going to get a six.

00:24:15.300 --> 00:24:18.010
And there's obviously six of
these different combinations,

00:24:18.010 --> 00:24:18.840
right?

00:24:18.840 --> 00:24:21.340
The details are actually
entirely up to you.

00:24:21.340 --> 00:24:23.040
I mean, the most
important thing here

00:24:23.040 --> 00:24:27.210
is the ordering that Billy had
had to be ordering that I had.

00:24:27.210 --> 00:24:28.710
And so yesterday
when we practiced,

00:24:28.710 --> 00:24:30.690
one time, there was a mismatch.

00:24:30.690 --> 00:24:32.040
And we got it wrong.

00:24:32.040 --> 00:24:36.090
But that's the only way
the trick would fail,

00:24:36.090 --> 00:24:39.250
really, I mean, other than
human error, is if the--

00:24:39.250 --> 00:24:40.680
is the encoding.

00:24:40.680 --> 00:24:43.110
This is really encoding
followed by decoding.

00:24:43.110 --> 00:24:47.950
And obviously, you need the
same algorithm, if you will,

00:24:47.950 --> 00:24:52.290
which requires that you need
the same ordering, in this case,

00:24:52.290 --> 00:24:53.990
for the cards, right?

00:24:53.990 --> 00:24:55.200
So that's it.

00:24:55.200 --> 00:24:57.710
That's the trick.

00:24:57.710 --> 00:25:00.900
It doesn't seem that
interesting anymore, huh?

00:25:00.900 --> 00:25:03.570
But no, it is interesting
if you show it to people.

00:25:03.570 --> 00:25:07.570
And the fun part is
in actually doing it.

00:25:07.570 --> 00:25:10.570
So I encourage you all to do it.

00:25:10.570 --> 00:25:12.730
Any questions about
how this trick works?

00:25:15.380 --> 00:25:20.740
So what I'd like to do is show
you some code for this trick.

00:25:20.740 --> 00:25:25.150
And there's also a code that
was useful to both of us,

00:25:25.150 --> 00:25:27.087
because we could
practice by ourselves.

00:25:27.087 --> 00:25:29.170
We didn't have to be in
the same room to practice,

00:25:29.170 --> 00:25:32.830
because I could randomly
generate a bunch of these four

00:25:32.830 --> 00:25:33.400
cards.

00:25:33.400 --> 00:25:36.070
And obviously, the program
knew what the hidden card was.

00:25:36.070 --> 00:25:36.930
And I could--

00:25:36.930 --> 00:25:38.022
I'll show you the code.

00:25:38.022 --> 00:25:39.730
I could type in what
the hidden card was.

00:25:39.730 --> 00:25:41.980
And it would say-- you
know, I guess it would say,

00:25:41.980 --> 00:25:45.280
you're a mind reader
extraordinaire, or sorry,

00:25:45.280 --> 00:25:46.330
not impressed.

00:25:46.330 --> 00:25:47.920
And Billy could
do the same thing

00:25:47.920 --> 00:25:50.740
in terms of checking
his encoding, all right?

00:25:50.740 --> 00:25:54.510
And then, after we're done
here talking about the code--

00:25:54.510 --> 00:25:58.060
and there are some interesting
things with the code--

00:25:58.060 --> 00:26:00.809
let's talk about
whether you could--

00:26:00.809 --> 00:26:02.350
talk about different
kinds of tricks.

00:26:02.350 --> 00:26:03.975
And in particular,
I want to talk about

00:26:03.975 --> 00:26:05.710
whether we could
go from five cards

00:26:05.710 --> 00:26:11.310
to four cards using a
different encoding scheme.

00:26:11.310 --> 00:26:19.700
Cool, so I wrote this
code about a year ago.

00:26:19.700 --> 00:26:24.760
And I think I'd probably
write it differently now,

00:26:24.760 --> 00:26:28.440
but we have what we have.

00:26:28.440 --> 00:26:34.590
So the first thing is you
have to decide on an order.

00:26:34.590 --> 00:26:36.360
You absolutely have
to decide an order.

00:26:36.360 --> 00:26:41.190
And the cards themselves,
as I mentioned,

00:26:41.190 --> 00:26:44.650
there's a natural order
associated with the numbers.

00:26:44.650 --> 00:26:48.810
And of course, you can decide
if you want to start with a two,

00:26:48.810 --> 00:26:51.660
and then the ace could be 14--

00:26:51.660 --> 00:26:54.822
I mean, kind of makes sense
for you to go 1 through 13.

00:26:54.822 --> 00:26:56.280
So that's really
what we have here.

00:26:56.280 --> 00:26:57.690
The ace is the smallest card.

00:26:57.690 --> 00:26:59.580
And the King is
the biggest card.

00:26:59.580 --> 00:27:03.000
And as I mentioned,
the clubs are smaller

00:27:03.000 --> 00:27:04.500
than the diamonds, et cetera.

00:27:04.500 --> 00:27:07.500
So I just have a
deck of cards that

00:27:07.500 --> 00:27:09.570
is ordered as you see up there.

00:27:09.570 --> 00:27:11.370
And that's just a
Python list that

00:27:11.370 --> 00:27:13.886
tells you what the ordering
of these 52 cards are.

00:27:13.886 --> 00:27:14.760
Does that make sense?

00:27:18.580 --> 00:27:24.910
So there's many procedures
here, many routines

00:27:24.910 --> 00:27:26.260
that do different things.

00:27:26.260 --> 00:27:27.890
And a lot of them
use the same code,

00:27:27.890 --> 00:27:30.200
so I'm not going explain
each one of them.

00:27:30.200 --> 00:27:32.270
But this one is a good one.

00:27:32.270 --> 00:27:35.260
And I'll also show you
the computer assistant

00:27:35.260 --> 00:27:39.730
one, which is essentially
this procedure except that it

00:27:39.730 --> 00:27:40.460
allows--

00:27:40.460 --> 00:27:44.950
allowed me to practice by myself
and generated cards randomly.

00:27:44.950 --> 00:27:48.940
In this case, what happens
is, you input five cards.

00:27:48.940 --> 00:27:51.040
And what this does is--

00:27:51.040 --> 00:27:53.800
so you could sort of take
five cards out from the deck.

00:27:53.800 --> 00:27:58.360
And then manually, you can
choose the hidden card,

00:27:58.360 --> 00:28:00.190
order the remaining four.

00:28:00.190 --> 00:28:02.740
And if you typed
in those five cards

00:28:02.740 --> 00:28:05.110
into this particular
procedure, it

00:28:05.110 --> 00:28:07.210
would give you the
first four cards, OK?

00:28:07.210 --> 00:28:10.096
And so you can then verify
that you've done the ordering.

00:28:10.096 --> 00:28:11.470
So this would be
something that--

00:28:11.470 --> 00:28:14.095
I don't know if Billy used this
to practice, but he could have.

00:28:16.050 --> 00:28:17.920
So what do I have here?

00:28:17.920 --> 00:28:20.730
Well, the first thing is just
printing out what the order is.

00:28:20.730 --> 00:28:23.580
There's a bunch of things
that need to get initialized.

00:28:23.580 --> 00:28:28.830
Cards is simply a
list of five cards.

00:28:28.830 --> 00:28:31.800
And then you have
c index, or cind,

00:28:31.800 --> 00:28:35.670
which is the indices
in that giant list

00:28:35.670 --> 00:28:39.004
that we have that
had 52 cards in it.

00:28:39.004 --> 00:28:40.920
They're just the indices
of the various cards.

00:28:40.920 --> 00:28:46.740
You can use .index, which is
a method to go from a card,

00:28:46.740 --> 00:28:51.480
which is like a_c, for
example, to the index.

00:28:51.480 --> 00:28:54.900
And then card suits are what
suits are for the cards.

00:28:54.900 --> 00:28:58.830
And it's 0, 1, 2, and 3 for
clubs, diamonds, et cetera.

00:28:58.830 --> 00:29:01.440
And then the numbers are
what the numbers of the cards

00:29:01.440 --> 00:29:03.480
are, 1 through 13, OK?

00:29:03.480 --> 00:29:04.340
You kind of need--

00:29:04.340 --> 00:29:05.631
there's a bunch of bookkeeping.

00:29:05.631 --> 00:29:08.820
As you can imagine, we're
doing things in our head here,

00:29:08.820 --> 00:29:11.430
but if you want to get a
computer program to actually do

00:29:11.430 --> 00:29:14.440
all of these computations,
it's not complicated,

00:29:14.440 --> 00:29:16.380
but you have to worry
about the four suits.

00:29:16.380 --> 00:29:18.330
And you've got to worry
about the 13 cards.

00:29:18.330 --> 00:29:22.320
And you have to go ahead
and encode SML, or produce

00:29:22.320 --> 00:29:23.280
this encoding, right?

00:29:23.280 --> 00:29:25.071
So you can imagine
there's a bunch of code.

00:29:25.071 --> 00:29:28.951
It's not complicated code,
but there's a bunch of code.

00:29:28.951 --> 00:29:30.450
So the first thing
that happens here

00:29:30.450 --> 00:29:34.170
is, in this
particular procedure,

00:29:34.170 --> 00:29:36.467
you want to input
put these cards in.

00:29:36.467 --> 00:29:37.550
And so let me just run it.

00:29:37.550 --> 00:29:41.530
And so you get a sense of
what this procedure does.

00:29:41.530 --> 00:29:42.810
All right, beautiful.

00:29:42.810 --> 00:29:45.360
So let's just say--

00:29:45.360 --> 00:29:48.880
let me just pick
five of these here.

00:29:48.880 --> 00:29:51.860
So the first one
is Five of Hearts--

00:29:51.860 --> 00:29:55.620
I'm sorry, Five of Hearts,
yup, Five of Hearts,

00:29:55.620 --> 00:30:06.296
Nine of Diamonds, Jack
of Spades, Ten of Hearts,

00:30:06.296 --> 00:30:07.990
Eight of Hearts.

00:30:07.990 --> 00:30:12.540
And so it essentially
says the first--

00:30:12.540 --> 00:30:14.380
so if I have
something like this,

00:30:14.380 --> 00:30:23.990
it ended up choosing the
Ten as the hidden card,

00:30:23.990 --> 00:30:28.520
and decided to choose
Five as the first one.

00:30:28.520 --> 00:30:30.920
And then because Ten
was the hidden card,

00:30:30.920 --> 00:30:33.470
you needed to encode 5, right?

00:30:33.470 --> 00:30:43.910
And so the way you encode
5 is by encoding L S and M.

00:30:43.910 --> 00:30:49.520
So the first card
that should be up

00:30:49.520 --> 00:30:53.990
is a Jack, followed
by the smallest card,

00:30:53.990 --> 00:30:56.760
which is an Eight,
followed by a Nine.

00:30:56.760 --> 00:30:58.770
So that's essentially it.

00:30:58.770 --> 00:31:01.649
So now that you've seen
that, let's take a look.

00:31:01.649 --> 00:31:03.815
I'm not going to go through
every line of code here,

00:31:03.815 --> 00:31:09.140
but I want to point out a couple
of things that are interesting.

00:31:09.140 --> 00:31:13.070
This is simply filling
in the data structures.

00:31:13.070 --> 00:31:14.719
The only thing that's
interesting here,

00:31:14.719 --> 00:31:16.760
or the thing that's probably
the most interesting

00:31:16.760 --> 00:31:18.620
here is what I've highlighted.

00:31:18.620 --> 00:31:24.020
This is a way of taking an
element in a Python list

00:31:24.020 --> 00:31:25.680
and getting the index for it.

00:31:25.680 --> 00:31:27.620
And so that's essentially
something that--

00:31:27.620 --> 00:31:29.670
it's object-oriented
programming.

00:31:29.670 --> 00:31:33.560
We probably want to get
into that in this class,

00:31:33.560 --> 00:31:38.040
but you'll definitely see
that in 009 and other classes.

00:31:38.040 --> 00:31:40.640
And essentially, what we have
here, given the ordering,

00:31:40.640 --> 00:31:49.640
is the suits simply correspond
to whatever the indexes mod 4.

00:31:49.640 --> 00:31:52.180
Because, as you
can see from this,

00:31:52.180 --> 00:31:58.070
the clubs are-- this is 0,
the index 0, and the club

00:31:58.070 --> 00:32:02.870
is index 0, 1, 2, 3, 4.

00:32:02.870 --> 00:32:05.590
So you're going to
get mod of clubs

00:32:05.590 --> 00:32:07.730
is always going to
be-- mod 4 of clubs

00:32:07.730 --> 00:32:08.880
is always going to be a 0.

00:32:08.880 --> 00:32:12.800
Mod 4 of diamonds is always
going to be a 1, et cetera,

00:32:12.800 --> 00:32:14.850
so that's essentially
what happens here.

00:32:14.850 --> 00:32:17.490
And the first thing I
need to do is figure out

00:32:17.490 --> 00:32:21.020
two a card that have the same
suit, because that's important,

00:32:21.020 --> 00:32:24.560
because that's going to
determine what my first card is

00:32:24.560 --> 00:32:25.880
and what my hidden cards are.

00:32:25.880 --> 00:32:28.160
And that's what
happens over here.

00:32:28.160 --> 00:32:30.730
And then once I
have that, I need--

00:32:30.730 --> 00:32:34.490
I've just got to split these
five cards into two piles, one

00:32:34.490 --> 00:32:37.760
of which has the hidden
and the first card in it,

00:32:37.760 --> 00:32:40.550
and the other pile has the
three cards that correspond

00:32:40.550 --> 00:32:41.654
to the ordering in it.

00:32:41.654 --> 00:32:43.070
Obviously, the
computations that I

00:32:43.070 --> 00:32:45.500
have to do for the
first couple are

00:32:45.500 --> 00:32:49.250
quite different from the ones
for the remaining three cards.

00:32:49.250 --> 00:32:50.380
In one case, it's ordering.

00:32:50.380 --> 00:32:52.160
In the other case,
it's a comparison.

00:32:52.160 --> 00:32:54.794
And I do have to-- the most
interesting remaining part

00:32:54.794 --> 00:32:56.210
of the code that
I'm going to show

00:32:56.210 --> 00:33:00.110
you is the determination
of what the hidden card is

00:33:00.110 --> 00:33:01.550
and what the first card is.

00:33:01.550 --> 00:33:03.090
And that's going require--

00:33:03.090 --> 00:33:05.600
this is the part that actually
took me the longest to code.

00:33:05.600 --> 00:33:07.370
I got it wrong a
couple of times.

00:33:07.370 --> 00:33:08.905
It's going to require me--

00:33:08.905 --> 00:33:10.840
it's five lines of
code, but it's subtle.

00:33:10.840 --> 00:33:13.250
It's going to require
me to kind of figure out

00:33:13.250 --> 00:33:17.510
whether it's a jack versus
two, you know, or vice versa.

00:33:17.510 --> 00:33:19.790
And things get a
little bit interesting.

00:33:19.790 --> 00:33:20.856
For example, if you had--

00:33:23.360 --> 00:33:31.250
if it wasn't the Jack and the
Two, the example I had here,

00:33:31.250 --> 00:33:33.160
so let's do this--
put the Jack and Two.

00:33:33.160 --> 00:33:36.580
Let's say I had a
Three and a Ten, right?

00:33:36.580 --> 00:33:38.800
They're kind of
the furthest apart.

00:33:38.800 --> 00:33:42.070
And you had to be kind of super
careful here, because 3 to 10

00:33:42.070 --> 00:33:45.130
is obviously 7,
which is too large,

00:33:45.130 --> 00:33:47.720
but you need to go 10
to 3, which is 6, right?

00:33:47.720 --> 00:33:49.840
So the things that
are diametrically

00:33:49.840 --> 00:33:52.120
opposite to each
other are usually

00:33:52.120 --> 00:33:55.570
the hardest when it comes
to actually doing the trick,

00:33:55.570 --> 00:33:58.210
but it's also hard from
a standpoint of coding.

00:33:58.210 --> 00:34:01.120
I had to get the mods
right, and the subtraction,

00:34:01.120 --> 00:34:05.420
and in terms of what got
subtracted from the other.

00:34:05.420 --> 00:34:07.540
So the rest of it is--

00:34:07.540 --> 00:34:09.949
I just have high
level descriptions.

00:34:09.949 --> 00:34:13.900
Obviously, the code for
these individual subroutines

00:34:13.900 --> 00:34:17.260
is in the file as well, but this
one determines what's hidden,

00:34:17.260 --> 00:34:20.320
what the other card is, and
what the number that you

00:34:20.320 --> 00:34:21.370
need to encode is.

00:34:21.370 --> 00:34:24.610
So when you go do the split,
and you have the two cards,

00:34:24.610 --> 00:34:27.317
you obviously need to
decide which one goes first,

00:34:27.317 --> 00:34:28.150
which one is hidden.

00:34:28.150 --> 00:34:29.860
And you also get the number.

00:34:29.860 --> 00:34:32.250
And that number had
better be between 1 and 6,

00:34:32.250 --> 00:34:35.510
otherwise this is
not going to work.

00:34:35.510 --> 00:34:38.515
And then you remove the other--

00:34:38.515 --> 00:34:44.739
the two cards hidden in other
from the set of five cards.

00:34:44.739 --> 00:34:49.030
In order to actually
do this SML,

00:34:49.030 --> 00:34:53.230
it was a little easier for
me to sort these cards.

00:34:53.230 --> 00:34:56.080
And then, depending on
the number and code,

00:34:56.080 --> 00:34:57.550
I'd change the order.

00:34:57.550 --> 00:35:00.430
Obviously, if I sort the
cards, I'm going to get SML.

00:35:00.430 --> 00:35:03.670
And that may not be what
I want, but it's easier

00:35:03.670 --> 00:35:06.100
to start with SML,
saying, this is

00:35:06.100 --> 00:35:09.430
the order that gave me the
number 1 as an encoding.

00:35:09.430 --> 00:35:12.310
What do I need to do in order
to change that encoding to a 2,

00:35:12.310 --> 00:35:14.650
or 5, or a 6, or what have you?

00:35:14.650 --> 00:35:18.660
OK, and so that's what
this outputNext3Cards does.

00:35:21.650 --> 00:35:23.961
This is what took me
the longest to code.

00:35:23.961 --> 00:35:25.960
I mean, it was a few
minutes, but the rest of it

00:35:25.960 --> 00:35:29.320
was pretty much busywork.

00:35:29.320 --> 00:35:31.340
There wasn't too much thinking.

00:35:31.340 --> 00:35:36.890
So this thing here, as you
can see, the encode is done--

00:35:36.890 --> 00:35:40.970
you don't need to worry too
much about the list itself,

00:35:40.970 --> 00:35:42.350
and the indexing into it.

00:35:42.350 --> 00:35:47.540
The bottom line is I need to
figure out this situation.

00:35:47.540 --> 00:35:49.990
And I need to subtract.

00:35:49.990 --> 00:35:54.670
And so when I see something
that says 10 and a 3,

00:35:54.670 --> 00:35:57.160
I end up getting a 7.

00:35:57.160 --> 00:36:00.310
And then I know that I
have to do a flip, OK?

00:36:00.310 --> 00:36:03.900
But it also may be the case that
I might get something that--

00:36:06.430 --> 00:36:12.280
the reason I need the mod 13 is
partly because I might end up

00:36:12.280 --> 00:36:13.990
getting a negative number.

00:36:13.990 --> 00:36:18.190
So it's not clear that
encode, take away the mod 13,

00:36:18.190 --> 00:36:20.410
is going to give me
a positive number.

00:36:20.410 --> 00:36:26.200
I might be subtracting 9 from 2,
so I end up getting a minus 7.

00:36:26.200 --> 00:36:27.670
So you don't know this.

00:36:27.670 --> 00:36:29.989
I mean, the program doesn't
know which one is which.

00:36:29.989 --> 00:36:31.780
And it has to figure
out which one is which

00:36:31.780 --> 00:36:33.150
and flip them together.

00:36:33.150 --> 00:36:36.770
So if there's any code that
you want to look at carefully,

00:36:36.770 --> 00:36:38.470
it's this code.

00:36:38.470 --> 00:36:40.302
And it's just a matter
of sort of going

00:36:40.302 --> 00:36:42.010
through the combinations
and making sure.

00:36:42.010 --> 00:36:45.330
I know it works, but you need
to convince yourself it works.

00:36:45.330 --> 00:36:47.625
So that's pretty much it.

00:36:47.625 --> 00:36:50.950
There's not much
more to say here

00:36:50.950 --> 00:36:56.560
that wouldn't be obvious to
you looking at it carefully,

00:36:56.560 --> 00:36:59.730
so I don't want to
belabor the obvious.

00:36:59.730 --> 00:37:03.920
And outputNext3Cards is the
part that I just described.

00:37:03.920 --> 00:37:07.210
You start with the default
ordering, which encodes a 1.

00:37:07.210 --> 00:37:09.400
And then you need to do
a little bit of flopping,

00:37:09.400 --> 00:37:12.130
if you want to encode
a 3, for example.

00:37:12.130 --> 00:37:13.840
And if you want to
encode a 3, then you'd

00:37:13.840 --> 00:37:15.280
change things around.

00:37:15.280 --> 00:37:17.480
And this is exactly what
I described to you before.

00:37:17.480 --> 00:37:19.760
So this is actually
fairly straightforward.

00:37:19.760 --> 00:37:21.880
If you have that table
written in front of you,

00:37:21.880 --> 00:37:25.420
you just go off
it and write that.

00:37:25.420 --> 00:37:28.660
Certainly if you change
the algorithm, all of this

00:37:28.660 --> 00:37:30.270
would change quite dramatically.

00:37:30.270 --> 00:37:34.660
And there's an
exercise which asks

00:37:34.660 --> 00:37:39.400
you to do that, which you
could certainly try to do.

00:37:39.400 --> 00:37:42.940
I want to show you one other
thing, which is interesting.

00:37:42.940 --> 00:37:47.780
And then I want to run
this new subroutine.

00:37:47.780 --> 00:37:51.230
So what I have
here is, I'm going

00:37:51.230 --> 00:37:53.260
to run-- oh, I've
already run it.

00:37:53.260 --> 00:37:57.820
So I want to show you
computer assistant.

00:37:57.820 --> 00:37:59.230
It was very useful to me.

00:38:04.036 --> 00:38:05.910
And this says, please
give me a random number

00:38:05.910 --> 00:38:07.680
of at least six digits.

00:38:07.680 --> 00:38:12.000
So obviously, I
don't want to know

00:38:12.000 --> 00:38:13.980
what the hidden card is
if I want to practice

00:38:13.980 --> 00:38:16.790
in a legitimate way.

00:38:16.790 --> 00:38:18.510
So what I did was,
I said, I'm going

00:38:18.510 --> 00:38:19.677
to have this sort of hokey--

00:38:19.677 --> 00:38:20.759
I mean, it's really hokey.

00:38:20.759 --> 00:38:22.650
I'm going to have this
hokey algorithm that's

00:38:22.650 --> 00:38:26.490
going to take this giant number
that, I'm going to type in.

00:38:26.490 --> 00:38:28.890
And it's somehow going to
take this giant number.

00:38:28.890 --> 00:38:34.020
And it's going to
deterministically generate

00:38:34.020 --> 00:38:38.582
5 cards based on
this giant number,

00:38:38.582 --> 00:38:40.290
but I didn't want to
have an obvious way.

00:38:40.290 --> 00:38:45.296
I mean, I don't want
to say the number 12345

00:38:45.296 --> 00:38:47.670
and then end up getting the
first five cards in the deck,

00:38:47.670 --> 00:38:49.200
or something like that, because
that would sort of give it

00:38:49.200 --> 00:38:50.040
away right.

00:38:50.040 --> 00:38:53.610
So I want to have some sort
of obfuscated way of taking

00:38:53.610 --> 00:38:56.490
a giant number and
generating something that

00:38:56.490 --> 00:38:59.310
was at least unpredictable to
me in terms of the five cards

00:38:59.310 --> 00:39:00.960
that are generated.

00:39:00.960 --> 00:39:04.940
And so what I do is,
if I type in a number,

00:39:04.940 --> 00:39:06.480
some random number.

00:39:06.480 --> 00:39:08.580
And at this point,
I have no idea

00:39:08.580 --> 00:39:13.020
what the five cards that are
going to be generated are.

00:39:13.020 --> 00:39:17.950
And this just tell me-- it
does do the assistant order

00:39:17.950 --> 00:39:20.670
the cards functionality,
so it does take those five

00:39:20.670 --> 00:39:25.590
cards, hides a card, and then
exposes the four cards to me.

00:39:25.590 --> 00:39:27.330
And so I'd get
different-- depending

00:39:27.330 --> 00:39:28.380
on what number I type.

00:39:28.380 --> 00:39:31.800
So the way I'd practice
is I'd just sort of

00:39:31.800 --> 00:39:34.170
close my eyes and just
type some random number.

00:39:34.170 --> 00:39:36.220
And then it would produce
four cards for me.

00:39:36.220 --> 00:39:39.830
And notice that
this is wonderful.

00:39:39.830 --> 00:39:41.550
Notice that there's
a bug, right?

00:39:41.550 --> 00:39:43.980
This is exactly
why I put this up.

00:39:43.980 --> 00:39:49.222
And wow what luck, so notice
that this didn't work.

00:39:49.222 --> 00:39:50.430
You know, and that's the fix.

00:39:50.430 --> 00:39:51.690
That's an exercise.

00:39:51.690 --> 00:39:53.280
I'm not-- I kid you not.

00:39:53.280 --> 00:39:56.130
It's an exercise
that's going to be

00:39:56.130 --> 00:39:59.970
up there, which is fix my
hokey algorithm so it doesn't

00:39:59.970 --> 00:40:01.470
do this.

00:40:01.470 --> 00:40:03.990
And so what happened here was,
I had a deterministic way.

00:40:03.990 --> 00:40:05.890
This wasn't a random
number generator.

00:40:05.890 --> 00:40:07.920
The good way of
doing this would have

00:40:07.920 --> 00:40:12.630
been to use Python's random
number generator facility

00:40:12.630 --> 00:40:15.690
and not have me do anything,
because obviously I

00:40:15.690 --> 00:40:20.000
attached something that turned
into that, which is a deck that

00:40:20.000 --> 00:40:22.620
has two King of Hearts in it.

00:40:22.620 --> 00:40:26.610
And so my deterministic way,
which was a convenient way

00:40:26.610 --> 00:40:28.320
because it's only
four lines of code

00:40:28.320 --> 00:40:35.100
didn't need me to include
the Python random library,

00:40:35.100 --> 00:40:37.830
et cetera, causes trouble.

00:40:37.830 --> 00:40:39.730
So this obviously won't work.

00:40:39.730 --> 00:40:41.257
So I'll just type something.

00:40:41.257 --> 00:40:43.090
And it's going to say,
sorry, not impressed.

00:40:43.090 --> 00:40:48.750
OK, not impressed with my guess
and not impressed with my code,

00:40:48.750 --> 00:40:49.875
so let me do this again.

00:40:54.880 --> 00:40:58.150
And so let me just do that.

00:40:58.150 --> 00:40:59.140
And now-- what?

00:41:01.920 --> 00:41:04.290
Is this-- this is ridiculous.

00:41:04.290 --> 00:41:07.949
I mean, does my code even work?

00:41:07.949 --> 00:41:09.490
I'm going to blame
it on my computer.

00:41:09.490 --> 00:41:12.370
I told you my
laptop is acting up.

00:41:12.370 --> 00:41:12.870
OK.

00:41:16.940 --> 00:41:25.110
1111222-- ah-- thank you,
all right, so now I see this.

00:41:25.110 --> 00:41:29.500
And I say Seven of Clubs,
so that's the first card.

00:41:29.500 --> 00:41:30.990
So clearly, it's a clubs.

00:41:30.990 --> 00:41:35.160
And then Ten, King and
Six, so Ten is medium.

00:41:35.160 --> 00:41:36.870
So I got medium, large--

00:41:36.870 --> 00:41:38.910
MLS, right?

00:41:38.910 --> 00:41:41.370
So MLS, is--

00:41:41.370 --> 00:41:43.200
MLS would be 4, right?

00:41:43.200 --> 00:41:47.950
So 4 would give me the
Jack of Clubs, right?

00:41:47.950 --> 00:41:50.020
There you go.

00:41:50.020 --> 00:41:52.150
So this worked, OK?

00:41:52.150 --> 00:41:54.120
But now I want to show--
you the last thing

00:41:54.120 --> 00:41:55.370
I'll do is show you this code.

00:41:55.370 --> 00:41:58.050
And you guys should
absolutely fix this code.

00:41:58.050 --> 00:42:01.200
It is clear what
your exercise is.

00:42:01.200 --> 00:42:02.280
Or you could--

00:42:02.280 --> 00:42:07.590
I do want to talk about
doing this with four cards.

00:42:07.590 --> 00:42:12.750
So, as note is that, this is
the offending line of code, OK?

00:42:12.750 --> 00:42:16.830
So what I did was, I wanted
to generate five, kind of,

00:42:16.830 --> 00:42:19.530
random-looking numbers
out of this giant number

00:42:19.530 --> 00:42:20.910
that I typed in, right?

00:42:20.910 --> 00:42:22.000
And I got lazy.

00:42:22.000 --> 00:42:24.310
And I was tired of
this puzzle by the time

00:42:24.310 --> 00:42:26.050
I ended up coding it.

00:42:26.050 --> 00:42:27.620
So I just said,
you know, I want--

00:42:27.620 --> 00:42:32.194
I don't want to include
random.lib from Python.

00:42:32.194 --> 00:42:33.360
I'm just going to take this.

00:42:33.360 --> 00:42:37.350
And I'm going to do some sort
of iterative computation, where

00:42:37.350 --> 00:42:42.900
I'm generating what I think are
random numbers between 1 and 52

00:42:42.900 --> 00:42:44.700
from this giant number
that I typed in.

00:42:44.700 --> 00:42:46.986
And I'm going to
do this five times.

00:42:46.986 --> 00:42:48.360
And what happened,
as you saw, is

00:42:48.360 --> 00:42:50.910
that I generated the same number
twice a couple of times, right?

00:42:50.910 --> 00:42:52.743
And that's why, obviously,
the trick doesn't

00:42:52.743 --> 00:42:54.005
work in that case, right?

00:42:54.005 --> 00:42:55.380
What was interesting
was, the way

00:42:55.380 --> 00:42:57.930
I found this bug was not
the obvious way that we just

00:42:57.930 --> 00:42:58.590
saw here.

00:42:58.590 --> 00:43:04.410
It was actually something
where the hidden card

00:43:04.410 --> 00:43:08.280
was the same as one of the
four cards that was exposed.

00:43:08.280 --> 00:43:09.570
And I didn't know that, right?

00:43:09.570 --> 00:43:11.690
So I'm like, what?

00:43:11.690 --> 00:43:13.350
Why am I not getting this right?

00:43:13.350 --> 00:43:14.939
It kept saying,
sorry, not impressed.

00:43:14.939 --> 00:43:17.355
And what it meant was, it
wasn't impressed with my coding,

00:43:17.355 --> 00:43:20.400
not with my deductive skills.

00:43:20.400 --> 00:43:22.980
So it took me a while
to figure this out.

00:43:22.980 --> 00:43:25.470
And you can fix it.

00:43:25.470 --> 00:43:28.440
OK, so that's it.

00:43:28.440 --> 00:43:30.900
Any questions about the--
what we've talked about,

00:43:30.900 --> 00:43:31.930
the puzzle, or the code?

00:43:34.860 --> 00:43:37.470
OK, so in the five
minutes that we have left,

00:43:37.470 --> 00:43:38.970
let's talk about
whether there would

00:43:38.970 --> 00:43:41.790
be a trick which would
be perhaps even more

00:43:41.790 --> 00:43:46.110
impressive where we would
only use four cards.

00:43:46.110 --> 00:43:50.880
So it would only be four cards
that the audience selects.

00:43:50.880 --> 00:43:53.070
And we would--

00:43:53.070 --> 00:43:56.640
Billy, I guess, would
show me three cards.

00:43:56.640 --> 00:44:01.290
And I'd have to
guess the fourth.

00:44:01.290 --> 00:44:04.080
Would that be possible?

00:44:04.080 --> 00:44:07.050
I mean, the numbers
really don't work right,

00:44:07.050 --> 00:44:12.005
because that fourth card
could be one out of--

00:44:12.005 --> 00:44:13.380
I guess, if you
show three cards,

00:44:13.380 --> 00:44:15.510
one of the 49 different
possibilities.

00:44:15.510 --> 00:44:18.330
And it would be pretty
difficult, right?

00:44:18.330 --> 00:44:25.560
You could think about
something where--

00:44:25.560 --> 00:44:27.620
the only way I
could come up with

00:44:27.620 --> 00:44:29.304
was-- it required
much more encoding,

00:44:29.304 --> 00:44:30.720
but I was thinking
about something

00:44:30.720 --> 00:44:35.430
like this, where let's say I
have these four cards, right?

00:44:35.430 --> 00:44:37.410
And let's even take--
let's say that they're

00:44:37.410 --> 00:44:39.977
all of different suits, right,
because that's possible.

00:44:39.977 --> 00:44:41.810
The other thing that
happens when you have--

00:44:41.810 --> 00:44:43.860
when you only have
four cards is they

00:44:43.860 --> 00:44:45.747
all four could be of
different suits, right?

00:44:45.747 --> 00:44:46.830
That's certainly possible.

00:44:58.125 --> 00:44:58.750
What do I want?

00:44:58.750 --> 00:44:59.375
I want a heart.

00:44:59.375 --> 00:45:02.410
OK, good, so I have
something like this.

00:45:02.410 --> 00:45:04.764
And now I'm in real trouble.

00:45:04.764 --> 00:45:06.430
I mean, clearly,
anything that we talked

00:45:06.430 --> 00:45:08.410
about isn't going to work.

00:45:08.410 --> 00:45:14.830
So let's just say that I end
up choosing one of these cards

00:45:14.830 --> 00:45:15.730
to hide, right?

00:45:15.730 --> 00:45:19.240
So this Ace is hidden,
because it's not

00:45:19.240 --> 00:45:22.480
quite clear what I
can do here, but bear

00:45:22.480 --> 00:45:24.590
with me for just a minute.

00:45:24.590 --> 00:45:28.390
So for argument's sake, let's
say that now, at this point,

00:45:28.390 --> 00:45:31.240
I'm trying to get more
information out of this.

00:45:31.240 --> 00:45:32.840
The ordering isn't
going to help me.

00:45:32.840 --> 00:45:35.770
I mean, the ordering is going to
help me a little bit, but what

00:45:35.770 --> 00:45:37.450
am I going to get, like 6--

00:45:37.450 --> 00:45:40.030
1 through 6 from this?

00:45:40.030 --> 00:45:44.980
So I could say the first
card is an anchor, OK?

00:45:44.980 --> 00:45:47.620
And so I'm going to expose this.

00:45:47.620 --> 00:45:51.002
So the only thing I could think
of was, you could sort of do--

00:45:51.002 --> 00:45:52.210
this is a little bit obvious.

00:45:52.210 --> 00:45:53.680
And I'm maybe
giving things away.

00:45:53.680 --> 00:45:56.950
But depending on where
you have the hidden card,

00:45:56.950 --> 00:46:01.660
and you can get more
information based on the order

00:46:01.660 --> 00:46:04.510
in which you put these cards
out and whether they're

00:46:04.510 --> 00:46:08.500
to the left or the right
of this hidden card.

00:46:08.500 --> 00:46:10.210
So you'd need to do
something like that.

00:46:10.210 --> 00:46:13.120
I mean, I haven't
figured this out.

00:46:13.120 --> 00:46:18.970
At least, I can't think
of a complete solution

00:46:18.970 --> 00:46:22.720
to this puzzle, but I
do feel like that you

00:46:22.720 --> 00:46:26.110
can get some information,
additional information based

00:46:26.110 --> 00:46:28.910
on whether you put things
to the left or the right.

00:46:28.910 --> 00:46:31.780
And that's clearly a bit of
information that you get.

00:46:31.780 --> 00:46:33.520
And maybe you could add to that.

00:46:33.520 --> 00:46:36.050
And you know, think about it.

00:46:36.050 --> 00:46:38.896
I think it makes for an
interesting exercise.

00:46:38.896 --> 00:46:40.270
And obviously,
there's other ways

00:46:40.270 --> 00:46:43.650
of doing the five-card
trick, as well.

00:46:43.650 --> 00:46:46.690
Cool, all right, that's
all I had for today.

00:46:46.690 --> 00:46:49.060
If there are no
questions, we can

00:46:49.060 --> 00:46:51.620
close this particular session.