DAVID: Brian, instead of numbers, let's do something a little more real world.
I think you have a couple of beverages in front of you?
BRIAN: Yeah.
So right here, I have a red glass and a blue glass,
which I guess we can use to represent, like, two variables for instance.
DAVID: Yeah, now, let me suppose--
I wish I told you in advance.
I'd actually prefer that the red liquid be
in the blue glass and the blue liquid be in the red glass.
So do you mind swapping those two values just
like you swapped numbers last week?
BRIAN: Yeah, sure.
So I can just take the two glasses and I can switch their places.
DAVID: OK, wait.
OK, that's not exactly--
OK.
You took me too literally.
I think here, if we think of the glasses now as specific locations and memory,
you can't just physically move the chips of memory inside of your computer
to swap things.
So I think I literally need you to move the blue liquid
into the red glass and the red liquid into the blue glass
so that it's more like a computer's memory.
BRIAN: OK, I can try to do that.
I'm a little nervous, though, because I feel like I can't just
pour the blue liquid into the red glass because the red liquid's already
in there.
DAVID: Yeah.
So this probably doesn't end well, right?
If he's got to do some kind of switcheroo between the two glasses.
So any thoughts here?
Like, what is the real-world solution to this weird but real problem where
we want to swap the contents of these two locations,
just like Brian was swapping the contents of two memory locations
last week?
Brian, if you have your eye on the chat in Parallel,
might anyone have ideas on how we could swap these two liquids?
BRIAN: Yeah.
A couple of people are saying that I need a third glass.
DAVID: All right.
Well, Brian, do you happen to have a third glass with you back there,
behind back stage?
BRIAN: In fact, I think I do.
So I have a third glass here that just so happens to be empty.
DAVID: OK.
And how would you now go about swapping these two things?
BRIAN: All right.
So I want to put the blue liquid inside the red glass.
So the first thing I need to do, I think,
is just to empty out the red glass to make space for the blue liquid.
So I'm going to take the red liquid, and I'm just
going to pour it into this extra glass.
DAVID: Temporarily, though, right?
BRIAN: Temporarily, yeah.
DAVID: OK.
BRIAN: Just to keep it, to store it there.
And now I think I can just pour the blue liquid into the original red glass
because now I'm free to do so.
So I'll pour the blue liquid there.
And I think the last thing I need to do now
is, now this glass that originally held the blue liquid is now empty,
so the red liquid which was inside of this temporary glass over here,
I can take the red liquid and just pour it into this glass here.
And now I didn't swap the positions of the glasses.
But the liquids have actually switched places.
Now the blue liquid is on the left.
And the red liquid is on the right.