One time during my grad student days I had dinner.
Unbelievable, yes, but true.
With a friend. Yes, even more incredible, but true.
At a restaurant. Now I’m really pushing it, aren’t I?
Well, ok, since we’re over the top, I might as well go the whole hog and say it was even a fancy restaurant. One of those places where, as you dine, a happy violinist in shiny tux and a big smile comes by and plays a nice tune.
I used to say that’s a great idea to distract you from realizing that the food was awful. When you’re poor you have to wear your wit to keep warm.
I had initially resisted the suggestion to eat there. But my dinner companion said that they were gonna have a magician that day. Their violinist had gotten sick from the previous night’s dinner. It was usually on the house for them. I’m guessing he wasn’t happy. Or smiling.
I like magic. So I went. Sure enough, no sooner than I’d washed down my first mouthful with a large gulp of affordable water, a short friendly dude in a tall hat came by and asked if I’d like to see a trick.
Would I ever? So I said “Absolutely” which was my Ph.D. advisor’s favorite word. Before he took me on as his student.
I used to think I was pretty bright. But this guy did a trick that had me completely stumped. With cards, no less. Try as I might I couldn’t figure out how he did it.
Then I did some quick mental calculations.
“Ah…” I thought. “That’s how it works. A 10% chance that he’d flub it, which would be about one of ten customers. And when that happens, he’d distract you quickly with a follow-up trick so you’d forget he messed up.
Even if he doesn’t have a pretty assistant.
And then something cool happened. He must have sensed what I was thinking. Magicians are like that. Now magicians never do the same trick twice. Even to different people. Yes, magicians are like that.
But this short dude adjusted his tall hat and said “You know what? I’m gonna do this trick again. I’m gonna do your friend now.”
He did it. With the same awesome effect. My friend wasn’t into magic as much as I was. So he just smiled. Which I always thought was a great cover up for bewilderment. But me? I was floored. What are the odds that the trick works twice in a row? It’s the probability that it succeeds both times. And 90% percent squared is just 81%. That means one in five pairs of customers could be disappointed. Double the risk of embarrassment. I doubt a professional entertainer would accept that.
Even for dinner on the house.
So how did he do it? The inquisitive me couldn’t resist. So I posted my take on the whole thing on the Quora of those days – USENET. I said that I just saw an amazing trick and “here is my oh-so-clever take on how it’s done. And can anyone do better than that?“
Professional magicians are tech savvy. They were on the Internet long before many of you discovered it. Usenet days. Maybe they had a hand in conjuring it up. One of them responded to my post the very next day.
He said I was clever. No magic there.
But then he said that the pro magicians were cleverer. That they’d never do a trick that didn’t work 100% of the time. They take no risks.
He said he could tell me how it’s actually done if I was interested. But that it would snuff out a tiny bit of magic from my life.
I said “Absolutely.”
I was way too brilliant then. And way too young. And way too stupid. Now I like to believe I’m only one of those.
So he broke it down for me. One email. One sentence. That’s all it took to kill the magic.
That trick has never been the same for me since. But I got to appreciate the compassion of magicians more.
When they ask “Was it good for you?” they don’t mean it like when we say “Was it good for you too?” I know what they’ve given up.
That’s what I told my students recently. They had to generate random and unique ID numbers for a million pets – Random numbers ranging from 1 to ten million. So if you were to guess a random ID, you’d only have a 10% chance of finding an actual pet with that ID. They were working on a Pet Store app.
And one more thing… the distribution of IDs to pets had to be uniform. Not all bunched up in some range. Or you could simply assign the first million numbers to your million pets. And of course, two pets can’t have the same ID. That’s what unique means, right?
That what makes it interesting for them. Coming up with a scheme to assign uniformly random IDs to a bunch of pets. Without conflict.
It’s simple. But they’re beginners. Some students try to concoct fancy schemes. Some of these are quadratic. “Look up each ID before issue to see if it has been used” for instance. That’s a good baseline response. Ripe for a suggestion to make it faster. To make it linear.
But some say they’ll just do random IDs without checking. “It’s gonna be unique 90% of the time. What’s the problem?”
Probably not the right time to ask whether they’d settle for a 90% (B+) in the final. But here’s where I bring out the magician story. It’s not enough to be correct 90% of the time. You need to be right always.
The story makes them appreciate proofs.
At the very least, it gets them thinking about algorithm correctness. What it means to provide guarantees that a program does what it says it does.
One of them says that’s why we trust computers more than we do humans.
And oh, if you’re curious about that magic trick, you can see my sloppy version of a similar one on YouTube. I did it for my students.