Thank you to all of you for coming along. Now as Tom mentioned, I’m researcher at the London School of Hygiene and Tropical Medicine where I specialise in mathematical models of infectious disease. So on the face of it, my job couldn’t be further really from the world of casinos and playing cards and plastic chips.

But really science and gambling have incredibly intertwined relationship, a really longstanding history. And that’s what I want to talk about this evening. And seeing as I’m talking about gambling, I thought I would start with an example of how not to gamble.

So this is a story– story from a few years ago. And as you can probably notice, there’s two large flaws with this lady’s strategy. The first is it’s completely illegal. And the second is it clearly doesn’t work.

And the reason I wanted to show you this is I think when we talk about people taming chance and beating the system, typically these are two themes that crop up quite a lot. You either have them doing something a bit dodgy. Or you have them presenting a system which clearly isn’t going to do something very successful. And what I want to do this evening is take a look at a third approach. Take a look at some of the ways in which mathematicians or scientists have taken on games of chance and used their techniques to get an edge over the house. I also want to look at how the ideas have flowed the other way, how actually games and gambling have inspired many ideas which are now fundamental to modern maths and science.

**And really lotteries, I think, are a good place to start**, because for me, it was a story about lotteries that first got me interested in the mathematics of betting. As I’m sure any of you who’ve played the lottery or have thought about playing lottery will know it’s incredibly difficult to win. But actually, even the way we measure how difficult it is to win is a fairly recent development. Although maths is– has been around for millennia.

**The idea of how we quantify luck, how we quantify random events, is a relatively recent one.** It was one that was developed in the 16th century. And it was actually in Veneto, Italy.

There was a Italian called Gerolamo Cardano. He was a physician. As a doctor, he was the first to describe the clinical symptoms of typhoid. He was also a gambler. And as a gambler, he was the first to describe such games mathematically. And he actually outlined what’s known as a sample space.

**So this is the– all of the combinations of events that could occur.** And obviously, if you’re only interested in one of those, that gives you a sense of how difficult it is to win. Now for the UK National Lottery as it stands, you have to pick six numbers from a possible set of 59. So this results in just over 45 million possible combinations of you– of numbers you could pick if you bought a card.

Clearly this makes life very difficult for you to win the jackpot. But there is a way that you can guarantee you will win the lottery this weekend. And that is quite simply to buy up every single combination of numbers. Now that might sound a little bit absurd. But let’s just run with it for a moment.

**As I said, there’s 45 million combinations of tickets for the UK lottery.** So if you were to buy up every single possible combination and line them up end-to-end, it would actually stretch from London to Dubai. What’s more, each ticket cost 2 pounds. So if you really want to win the jackpot this weekend, it’s going to cost about 90 million pounds to achieve. Clearly that’s not a feasible strategy.

But not all lotteries are the same. In the 1990s, for example, the Irish National Lottery had a much smaller sample space– a much smaller possible combination of numbers that could come up. In fact, there were about 1.94 million combinations. Each ticket costs 50p.

So as a result, it would cost you less than a million pounds to buy up every single combination. And actually a syndicate headed up by an accountant got thinking about this. And clearly most weeks, this is a pretty poor investment, because the jackpot would be maybe a few hundred thousand. And if you’re spending almost a million to win a few hundred thousand, doesn’t take much to spot that’s a pretty bad investment.

But if a rollover were to come around, maybe this could be plausible. And actually rather than stretching it to Dubai, if you lined up all of these tickets and the combinations end-to-end, it would actually stretch from London to Plymouth. So you’ve got something that’s a bit more doable.

And what they started to do is collect together these tickets and fill each one out by hand to get every single one of these combinations. And then they waited. They waited for about six months until the May Bank Holiday in 1992 when the rollover hit 2.2 million. And they put their plan into action. They took all these tickets they’d filled out, started taking them to shops, and buying them up. And in many cases this raised some attention.

So shops that would usually sale maybe a thousand tickets in a week were suddenly selling 15,000. The Lottery perhaps expectantly, frowned upon this a little bit and tried to stop them. And as a result, when the lottery draw came around, they’d only bought 80% of the possible combinations of tickets. So there’s still an element of luck as to whether they’d win the jackpot.

*Fortunately for them, that jackpot’s winning set of numbers was within the combinations that they bought up. So they won that week. Unfortunately, there were two other winners that week.*

So they had to split the jackpot. But when you added up all those lower tier prizes that they match five numbers, four numbers as well, they walked away with a profit of 300,000 pounds. Now for me, years ago when I heard the story, that was just a fantastic illustration of how you can take a pretty simple mathematical insight, a good dose of audacity and hard work, and convert it into something that’s profitable. And this isn’t the only instance that people have targeted these kind of games. For the UK lottery, the draw is random.

So really the only way you can guarantee a win is to use this brute force approach by simply buying up all of the combinations. But not all lotteries are the same. Take scratchcards, for example. On the face of it, scratchcards are completely random. If you think about it, they can’t be completely random.

Because if you’re producing scratchcards, and you just randomly generate which cards are going to be winners, there’s a chance that by sheer chance you will produce too many winning cards. If you’re a company making scratchcards, you want some way of controlling and limiting which prizes go out. As statisticians will call it, you need controlled randomness. You want the prizes to be fairly uniformly, evenly distributed amongst the occasions. But you don’t want the generation to be completely random. And actually in 2003, a statistician called Mohan Srivastava was thinking about scratchcards.

He’d been given some as a joke present and was wondering on this idea of controlled randomness. And he realised there must be some way for the lottery to identify which cards were winners without having to scratch them off. On each card there were a series of digits. And some of these would appear two times, three times. But some numbers and symbols only appeared once on the card.

And actually if these unique numbers appeared in a row, that card was always a winner. And he went and bought more cards and tested out his strategy. And every single time, the cards that had these numbers in a row were guaranteed winners.

Now what would you do in this situation? You’ve essentially cracked scratchcards. You’ve got a system which can identify the winning ones and the not winning ones just by looking at them. Would you go out and buy tonnes?

What would you do? Well, think back to that slide that I showed you at the start. Winning scratchcards are remarkably rare.

And actually what Mohan did, rather than just going on a huge scratchcard buying spree, was work out how long it would take him to buy up enough cards and guarantee himself a winner. And he was a statistician working on geological problems earning pretty decent money. And he realised that actually, although he had a winning lottery strategy, it was better off just to stick in his existing job. So what he did was he rang up the lottery and told them that there was a hidden code on their scratchcards, and he had deciphered it, and he knew how to win.

The lottery, of course, didn’t take him seriously. So what he did was actually collected the scratchcards. And he identified some winning ones, some losing ones, divided them into two piles and posted them by courier to lottery. That evening he got a phone call from lottery saying, we need to have a chat. And really the story is representative of a lot of areas of gambling. Often it’s not professional gamblers who come up with these strategies that beat the system.

And often people who beat the system, don’t become professional gamblers. For a lot of these people, gambling is almost a playground for ideas. It’s a way of testing out problem solving and skills that actually would apply to many other industries. People who have tried these problems are moving into academia, into finance, into business.

And as I mentioned with Cardano, this isn’t a new phenomenon. Really throughout history, many of the great thinkers and mathematicians have used gambling as a way of refining their ideas. In around 1900, a French mathematician called Henri Poincare was particularly interested in gambling.

Now Poincare was one of the– what’s know as the last universalists. As a mathematician, he was one of the last people to specialise in almost every area of the subject as existed at the time. It hadn’t expanded to the point where it was as large as it is today.

And one of the things he was interested in was predictability. And to him, unexpected events, unexpected outcomes were the result of ignorance. He thought if something is unexpected, it’s because we’re ignorant of the causes. And he classed these problems by what he called the three levels of ignorance.

The top level was a situation where we know what the rules are, we have the information, we just have to do some basic calculations. So if you’ve got, say, a school physics exam, you know what the physical laws are. You’re given the information. So in theory, you should be able to get the right answer.

If your answer is surprising, then you’ve done something wrong in the working. But it’s not a kind of difficult level of ignorance to escape, in theory. The second level of ignorance according to Poincare was one where you know what the rules are, but you lack the information necessary to carry out the calculations accurately. And he used roulette as an example.

So a roulette table, you start a ball spinning round and round. And he observed a very small change in the initial speed of the ball could have a very dramatic effect on where it ends up, because it’s going to be circling this table over time. And nowadays mathematicians refer to this as sensitive dependence on initial conditions. And popularly it’s known as the butterfly effect. There’s a talk in the ’70s where a physicist pointed out that a butterfly flapping its wings in Brazil could cause or perhaps prevent a tornado in Texas. These very small changes, which Poincare first observed, could have a very large effect later on.

And then we’ll say that the results is random. It’s down to chance. But really, it’s a problem of information. Then comes the third degree of ignorance. And this is where we don’t know the rules. Or perhaps they’re so complex, we’ll never be able to untangle them.

And in this situation, all we can do is watch. Watch over time and try and gain some understanding of what we’re observing. And it’s really this level of ignorance when gamblers started targeting roulette that they focused on. They didn’t try and untangle all of these physical laws. They just said, well, let’s just watch a load of roulette spins at a table and see if there’s a bias. See if there’s something odd going on with this table.

But this raises the question of what do we actually mean by odd. What do we mean by biassed? And while Poincare was thinking about roulette in France, on the other side of the channel, a mathematician called Karl Pearson was also thinking about roulette. And Pearson was fascinated by random events. As he said, we can’t have any true sense of what nature does. We can only observe and try and make inferences on those observations.

And he’s really keen to collect random data to test out these kind of ideas. On one occasion he spent his summer holiday flipping a coin 25,000 times to generate a data set to analyse. And he was also interested in roulette. Now fortunately for him at the time, the Le Monaco newspaper would publish the results of all the roulette spins in the casinos at Monte Carlo. Now for Pearson this is a fantastic data set.

He wants to test out his ideas about randomness. You’ve got all these previous roulette spins to test it out on. And he started looking at ways to understand whether they were random or not.

And a roulette table, of course, you’ve got these black and red numbers. And then you’ve got zero. If you take out the zero, over time you’d expect the proportion of black and red to be even.

You’d expect it to be 50/50 over time. And when Pearson looked at the data, he found that red came up 50.15% of the time. This was over about 16,000 spins. So according to his calculation, this wasn’t that implausible, that actually that kind of deviation from the expected value is reasonable given the kind of data set he had. But then he continued. And he looked, for instance, at how often pairs of numbers appear.

Now if you’ve got a random process at roulette table, sometimes you’d expect there to be a string of the same colour appearing purely by chance. You might get a few reds coming up– a few blacks. But what Pearson found was that the number switched too often, that actually you didn’t get these strings of the same colour appearing as often as you might expect. They were switching over.

And to him this was pretty definitive evidence that the tables were corrupt, that they were biassed. And as he puts it, if I had been observing these tables since the start of geological time on Earth, I would not have expected to see a result that extreme. And he actually suggested that they close down the casinos and donate the proceeds to science. As it happened there was something a little bit more down to earth going on. It turned out that those journalists from Le Monaco, rather than sitting by the tables and recording the numbers, instead had been sitting in the bar and making them up.

But this idea– think back to how he phrased it. It was the probability of observing an event as extreme as the one I’ve observed. This was the first forays into what’s known as hypothesis testing.

Nowadays, whether we work in clinical trials or on particle physics experiments, we use the principles that Pearson honed on these roulette tables and coin tosses to understand whether we have enough evidence to reject or accept a certain hypothesis. So in this case his hypotheses was that the tables were random. And he had enough evidence to say that this wasn’t the case. And actually gamblers have also used these ideas throughout Victorian times. And moving into late 1940s, for example, two medical students used these kind of methods to go and unlike the lazy journalists, they actually watched the tables this time, collected all the data and found that there were biases. These tables bore down over time.

And certain numbers or areas would appear more often than not. And actually they went around Nevada and gambolled at all these tables. And the exact figure was never known.

But they did buy a yacht and sell around the Caribbean for a year– so a pretty successful strategy. The problem for gamblers, though, is casinos cottoned on to what they were doing. And they would make sure the tables were incredibly well maintained and you didn’t have these biases occurring. But in the ’60s and ’70s, some physics students realised that this actually leaves you in the second level of ignorance. Because if you’ve got a very pristine, well-maintained roulette table, it’s not a statistics problem. It’s a physics one.

As one of them said, it’s kind of like having a planet orbiting a point. You got this ball going around. In the ’70s, a group of students at University of California, Santa Cruz actually started doing these calculations.

And they looked at roulette spin. And they said, well, to start off with, the croupier will spin the ball. And it would go around the edge of the track around the rim of the table. And often it would go around a couple of times before the croupier calls no more bets. In other words, you have a window in which you can collect information on what the ball is doing and act on it. You can place bets during this period.

**Over time it would drop down onto the track.** And this will spin freely and eventually hit one of these deflectors and land in one of the pockets. And what’s it– they actually did testing out their strategy on different tables in their lab was realised that if you could calibrate your models– if you could write down the equations for the physical system– you got the ball going around. It’s slowing down and then drops down. If you write down these equations that calibrate into a specific table, then in that initial bit of time, you could collect enough information to improve your prediction about where the ball would land. You’d never get exactly.

But you didn’t need to. You just need to get some idea of which region of the table is going to land in, enough to get an edge over the casino. It’s all well and good, of course, doing that in a classroom and working for all occasions– all the equations.

But in a casino, you need to do it in real time. You need to do that on the casino floor as the ball is spinning. So what these teams actually did was come up with hidden computers to do these calculations in person. Now wearable technology is, of course, all around us these days.

But the first wearable computer was designed for this purpose as it happens. And because it was a new technology, there were, of course, some drawbacks for this. They’d often give themselves electric shocks for example. And as well as this– as I mentioned, things are very sensitive to initial conditions.

So if the weather changed, they would need to recalibrate to the roulette table. On one occasion they were actually losing a fair bit of money and couldn’t quite work out why. Until they realised there’s an overweight tourist further down leaning on the table and screwing up all of their predictions.

So really these kind of methods were somewhat imperfect. In theory they worked very well. But these kind of stories have been a bit sporadic.

But it wasn’t just roulette during this period that gamblers started targeting. They also started targeting other games. And actually one of the most successful gamblers in the world is a man by the name of Bill Benter. And when he was a student in the ’70s, he came across this sign in an Atlantic City casino. Now to him this sign meant one thing.

Card counting clearly works. And the whole idea of card counting– so if you have games like blackjack. You’re trying to get to a certain total playing the dealer. And in blackjack, you try and get near to 21 but not go over. So you’ve got to draw cards and try and get near this total.

On the face of it, this is a random game. The draw is completely random what will come out. But of course, it’s not for a deck of cards. Because if certain cards have already come out, they can’t reappear until you shuffle the deck.

So if you can collect information on what’s already appeared, this can potentially give you an edge over the casino. It can give you an advantage against them. Now again, casinos started realising what players were doing, that they were tracking what was in the deck.

So they started using more decks of cards. Rather than one, they would use a whole pile. And this made it much harder to card count. Because if there’s multiple of the same card in the deck, it’s much more difficult to keep track of what’s come out and what hasn’t. But the casinos were inadvertently handing the gamblers a very significant advantage, because at the time, casinos typically used what’s know as a dovetail shuffle. So this is probably familiar to you.

You split the deck in two. You riffle the cards together. Now a dovetail shuffle, if you do it once, preserves an enormous amount of information about the cards.

So just to give you an example, let’s say we have a six pack of cards in order from ace to king. If we do a dovetail shuffle, we split them. I’ve coloured them just to make life a bit easier. And then we riffle them together. Now they might not fall exactly interwoven.

But you can see here in two different colours, you’ve got two quite clear what’s known as rising sequences of numbers. So cards have been shuffled. But actually, if you know where they started at each point as you go from left to right, you know there’s only one of two cards that could be appearing. And actually there’s a number of magic tricks that rely on this fact. So if you get a deck of cards and move one and then riffle shuffle, you can spot with– the moved card– because it won’t fit into one of these rising sequences. As mathematicians have shown that for this kind of shuffle, you need to shuffle the deck at least half a dozen or so times to get something that’s as good as random.

And in casinos in that period, people were actually only shuffling them once. So really if you can track what’s happened, you’ve got a huge amount of information about what’s going on. And in many cases, they would actually sneak in pieces. And again, another opportunity at confusing casinos– to track the cards that have come previously. And whereas before card counters would measure what’s come and then get a custom approximation of what’s left, now they’d actually at each point in time know that there’s only one of two cards that could appear.

So this is a terrific advantage that they had. But this poses a challenge, because how do you capitalise on that? At each point in time, let’s say, there’s a card that’s advantageous and less beneficial. How do you make that decision about how much to risk in that situation?

And what I want to do is just start with a simple example. Let’s suppose we have a coin toss. And I’m going to offer you a biassed bet here. So I’m going to offer you two to one odds on tails.

So in other words, you name an amount of money. If it comes up heads, you pay me that amount of money. If it comes up tails, then I will pay you double the amount you named.

So clearly that’s a pretty stupid bet on my part. I’m giving you an advantage. But how much would you be willing to risk?

After all, it is a coin toss, and you would still have a chance of losing money. Could I just get a quick show of hands? Who here would be willing to risk one pound on that bet? Show of hands– OK, so I think most of you. Keep your hand out if you be willing to risk 10 pounds. OK, how about 100 pounds?

OK, and 500? How many times do you get to play? Once.

OK, so there’s a few people left. I’m not sure if they’re playing with monopoly money. But OK, so if you put your hands down.

That wasn’t legally binding, anyway. But I waned to give you a chance to kind of get a feeling of measuring risk. How much are you willing to risk in that situation? And I don’t know if you can see, but actually the hands kind of went down a lot between 10 and a hundred pounds.

But this is quite an important question for gamblers. And actually in the ’50s, a physicist called John Kelly started thinking about this idea of biassed bets. Suppose you have inside information. And you have some edge over a book maker or casino. How do you exploit that?

In this situation for you, although I gave all of you the exact same bets– mathematically it’s the same offer– your perception of the value of that was very different. Some of you valued it at a pound, some at 10, some at 500. What’s the optimal thing to do there?

There’s actually this concept known as utility in economics. It’s the value of something changes depending on how much money is in your wallet, for example, and how much you’re willing to lose. And what Kelly did is he looked at these two contrasting aims you have, if you want to give a good long-term return. First you’re trying to make money, because you’ve got a biassed bet. But you’re also trying to avoid going bankrupt. Essentially you’re still tossing a coin.

There’s that chance you’re going to lose. I don’t think anyone here would have bet their house on this. Maybe you would have.

You might have an angry family. But in this case, you want to somehow exploit it, but also limit your losses. And what Kelly did was come up with this formula.

So I apologise for my handwriting. Basically you’ve got the odds, which in this case is two. You got the probability you’ll win– this Pwin– minus the probability you’ll lose.

And this is the optimal fraction of your money to bet for a given edge over somebody in a wager situation. So the bet I just showed you. The odds were two. The probability you’ll win is a half, because it’s a coin toss.

Probability you’ll lose is also a half. So if you stick these numbers in, you get the following kind of equation. A little bit of arithmetic– you can end up with a quarter. So in this situation, if you want to maximise your long-term growth of money, it’s optimal to risk about a quarter of your income.

Just have a think back to when you were raising hands, whether that was the course of– were you taking advantage or not? Now some of you might think, OK, that’s all well and good. You showed me a formula. Let’s test it out.

Now I could have, of course, adopt the Karl Pearson approach and spend the next half an hour or so tossing coins to convince you. That’s a bit boring. So what I thought I’d do instead is show you some simulations of if we adopted different strategies, what kind of outcomes we would get. So here along the vertical is your bankroll. I’m going to assume that you start with a hundred pounds. And along the bottom is the coin flips.

So we’re going to play this bet again, and again, and again, and see what you’d end up with over time. Now you might have thought a quarter of my money, that’s not taking risks. So I want to go big. You might say, well, I want to bet 80% of my money. And in this case, if we just do one random simulation, what might happen is you’ll get a couple of big wins at the start.

You’re approaching a thousand pounds. Lose a load of money– win a load of money. It’s exciting. And then lose all your money and go bankrupt– Less exciting. If you adopt this optimal Kelly strategy and bet 25%, what will happen is it will take longer. You’ll grow a bit slow over time.

But you won’t go bankrupt. And actually in the long term, you will get something that takes off. You might say actually, that’s still a bit too much for me. I’m going to bet 10% of my income on each one of these wages.

And in this case, if you do it randomly, it’ll take a long time to grow. So you won’t go bankrupt. But it will take much more time to bet your money. And you notice this kind of increases quite steeply at the end.

And that’s because you’re reinvesting your money. It’s this kind of compound interest effect over time. Again, this is just one simulation. It’s a coin toss. It’s a bit of randomness. So what we could do is simulate it, say, 10 times.

Instead of this one instance here, do each one of these 10 times over. And in the case where you bet 80%, you’re going to end up with something which nine of these you go bankrupt, one of them you do make a bit of money. But in most of these cases, you’ll run out of your income pretty quickly.

If you bet 25%, this optimal amount, then again, it grows a bit slower. But you don’t go bankrupt at any point. And you will eventually grow your income. And then again, this 10% is just a much slower growth.

So it takes much, much more time to build this up over the series of bets. And this is the strategy that people use playing blackjack– playing a lot these games to manage their bankroll. And actually the concept of utility and money management is obviously important in finance. But it underpins the entire insurance industry, because whether we insure something or not depends on how we value it, whether we’re willing to risk the fact that we could lose it and cost us out of a lot of money, or whether we take those small premiums. That would depend on the value of the item. But implementing this strategy, of course, for card counters can still be a problem.

As one card counter I talked to said, learning to card count is easy. Learning to get away with it is very difficult. And many of these people who were successful, people like Bill Benter soon became pretty well known in the world of casinos and found themselves banned from all the way around the world. So they turned their attention to a bigger game, a much larger place to wager.

Now, this is Happy Valley Racecourse in Hong Kong. If you’ve ever been Wednesday night, this is kind of where all the action is. On a typical race day, about $150 million are wagered. Gambling is an enormous part of what’s going on here. One of the appeals for this for gamblers is a fairly small– well, firstly it’s– they’re pretty convinced it’s an honest operation.

And it’s a small pool of horses, about a thousand horses that run again, and again, and again. So you can generate lots of data to look at and try and interpret which horse might have a good chance. But to do that, of course, you need some way of converting data into a measure of performance.

Which horse is the best? Which horse is going to win? And to use this, teams turned to an idea that was first conjured up by this man. This is Francis Galton, a Victorian scientist and cousin actually of Charles Darwin.

And as you can see, they shared some passions particularly for cravats and short sideburns. But there were some differences. Darwin actually was meticulous in shaping his research.

So even the theory of evolution, you can see many of his fingerprints over this. Now Galton liked to think of himself more as an explorer. He would dabble in anthropology, and psychology, and biology, and economics, and then start it off a bit and then leave it and wander off to something else. And one of the things he was interested in was inheritance. And he actually on some occasions would send his friends seeds and get them to grow them for him.

It’s kind of an early crowdsourcing approach– and get them to report back. And one of the things he’d notice is that if you grew a season and had the subsequent generation, if those were for instance taller, you wouldn’t expect the next generation to be taller, and taller, and taller– that over time you’d get a feature which he referred to as regression to mediocrity– that over time these kind of features would somehow converge. And the influence of the older lineages might kind of smooth over variation. He wanted to understand this in a slightly more rigorous way. And it was actually a horse trainer who presented him with a figure, which allowed him to frame this idea.

And it was the following. It was a diagram. It was a square which represented the characteristics of a horse. And this trainer had proposed that about half of the characteristics are explained by the mother and the father. So you have a couple of squares for those. And then of the remaining characteristics, maybe a quarter is explained by the four grandparents.

And then another chunk is explained by the great grandparents and so on. And this idea was one of the founders of what’s known as regression theory in statistics. It’s the idea that we can take a number of factors and work out how it influences the characteristics of a certain object or system. And we could have a similar approach in horse racing.

We could say, well, let’s just suppose this box is the performance of the horse. And we have lots of different bits of past data. And we could say, well, maybe each one of these bits of data explains some amount of the horse’s performance. Of course, this is a bit simplistic, really, isn’t it. Because just like with the characteristics of inheritance where, for instance, some of the variation is explained by the parents that are also going to be shared with the grandparents, the characteristics of a horse– these features are going to overlap.

Some of these will explain multiple aspects. So these kind of things are going to be a bit more jumbled up. And what’s more, we might not be able to explain all of the horse’s performance. There might be some chunk which we still can’t explain.

And really the aim from a statistical point of view is to try and minimise this unknown quantity. And there’s actually– in the ’80s, Bill Benter visiting a library in Nevada came across a paper by two researchers called Ruth Bolton and Randall Chapman. They work in marketing. They still do actually. And they had essentially outlined this method for horse races, this approach of converting data into some kind of measure of performance that you could use to make predictions.

And as Bill said, it was the idea that sowed a multibillion pound industry– an incredibly important piece of research. And actually for Ruth Bolton, it was the only paper she wrote about horse racing. It’s during her PhD. And it was really kind of a side project. But this had a huge impact on this industry.

And on doing the analysis of those early syndicates in Hong Kong, certain things would come out as more important. For example, in one of their early bits of research, the number of races a horse had run would tell you a lot about how it’s going to do. And it’s tempting to come up with a story for that.

We say, well, if it’s run more races, then it’s going to be more experienced. And then that’s going to give it a better performance in the next race. But they actually avoid doing that, because really they know it’s a jumble, that all of these things are going to overlap and explain one thing.

And it’s not clear that just because something is important, it has a direct explanation. This quite common problem in statistics is known as this idea that correlation doesn’t always mean causation. Just to give an example, here we have along the bottom is the wine spend per year at the Cambridge colleges. On the vertical is the exam results. So as you– [LAUGHTER] As you can see, there’s a pretty strong correlation between colleges that spend more on wine have better results.

And this isn’t the only thing that’s happened. Actually it turns out that countries that have a higher per capita spend on chocolate typically win more Nobel Prizes. As lovely as it would be that eating chocolate would make you a Nobel Prize winner and drinking wine would make you better at exams, there’s clearly something else going on. There’s some underlying feature which explains all of these things.

And really these syndicates therefore don’t try and untangle it. And actually one of the remarkable things is they have no desire to be pundits and experts on this kind of field. For them the question is what horse is going to win, not why is that horse going to win.

So it’s almost this going back to the idea of ignorance. They’re embracing their ignorance. And they’re saying, I don’t really mind that I can’t explain exactly how it’s going. I just want a method that is going to give me good predictions.

Now starting off by measuring performance is one good thing. But actually when you have multiple horses racing, you can get some slightly unexpected results occurring. So just an example, a very simple one, let’s suppose we have two horses.

We have one which half the time does well, half the time does badly. On the day, you don’t know which it’s going to be. And you have the second horse which is a bastion of reliability.

Every single race, exactly the same performance. Now on average over lots and lots of races, they’ve got the same kind of performance, because the top one on average that will cancel out. And in a race, it will be essentially a 50-50, because it completely depends in a race whether the top horse number one is having a good day or a bad day.

So these two horses race against each other. It’s basically a coin toss. It’s a 50/50 chance, because if the top horse is having a good day, he’s going to win. If he’s having a bad day, he’s going to lose. That’s kind of intuitive. But if you add a third horse into the mix, something a bit strange happens.

So let’s suppose we have a third horse here, which some days performed slightly better than the middle horse, some days performed slightly worse. So again on average, all these horses have the same performance. Now by the same kind of logic, the top horse here again has a 50% chance of winning, because half the time he will come out front and half the time he’ll come out last.

So he still has a 50% chance of winning. Of the two horses that remain, if the top horse doesn’t win, we can apply the same logic. Of these two horses on the bottom, if the horse number three has a good day, he’s going to come out on top. And if he has a bad day, he’s going to lose. So if the top horse doesn’t win, you spit the probabilities between the two horses remaining, because you can’t decide. Now just take a look at what’s going on here.

All these horses on average have identical performance. But it’s the variability that’s different. And actually the top horse because it’s most variable in this kind of race has a larger chance of winning. You can actually apply the same kind of logic to other situations.

So say we have an election, which the first past the post system. So the person who gets the most votes wins. If you have three people who on average you’d expect to get the same amount of votes, is actually the most polarising candidate, the kind of all or nothing one, which has the best strategy, because they’ve got the largest chance of winning in this situation. If you want to push the example a bit further, you could look at job interviews or maybe even dating, if you’ve got lots of different suitors. In this situation, it makes most sense to adopt this all or nothing kind of Marmite strategy, if the objective is to come out first against multiple people. This isn’t a problem if there’s only two in the race.

But as soon as you have multiple competitors, you get this kind of weird dynamic coming out. And really the mathematics of games and these kind of features have been interest to mathematicians for a long time. Actually the origins of game theory, the origins of mathematics of games originated with poker. In the 1920s, a researcher John Von Neumann– brilliant mathematician. He was the youngest professor in the history of the University of Berlin– wasn’t so good at poker, though. On the face of it, poker is a perfect game for a mathematician, right?

It’s the probability you get a certain hand– the probability your opponent gets a different one. But von Neumann realised that there’s more to it than that. He said real life consists of bluffing– of little tactics of deception– of asking myself what does the other man suppose I’m going to do.

And he wanted to study that kind of feedback between what you think, what they think, and they think you think. And he looked at very simplified forms of poker. And one situation he looked at was two players. They each get dealt a single card. And then they put some money in the pot at the start. And first player has the choice.

So they can either just stick with their bets, in which case they just turn over their cards and compare them. Or they can raise the stakes. And then it’s up to the second pair to decide whether they meet that bet or not. So two players, one card, money in the middle. What von Neumann found is that in these kind of games, you’ve got almost a tug of war, because each player is trying to maximise their gain while simultaneously trying to minimise their opponent’s gain.

If you play a game like poker, anything your opponent wins comes out of your pocket. So you’re trying to maximise what you get, while at the same time trying to minimise what they get. Which means that there’s this kind of equilibrium point.

There’s a point at which the two conflicting forces balance. And this situation– analysing it for the game. He found that this situation in which no player would benefit by changing their strategy– this balance point. For the first player, the strategy was as follows, that if they got a very high card, then they should raise the stakes. Intuitive just makes sense.

If you have a good card, you might as well bet on it. If they had a middling card, it didn’t make sense for them to raise the stakes. They didn’t have a great chance of winning.

But they still had some chance. So in other words, they should just stick with their existing bet. But when von Neumann looked at what happened when you got the lowest kind of cards, he found that it doesn’t make sense to stick with your bet, because if you turn over the cards, you’re probably going to lose. Instead you should up the stakes. So in other words, you should bluff.

And actually up to this point gamblers had often– poker players had often bluffed in games. But it was always seen as a quirk of human psychology, a kind of innate trickery that humans came up with. But here was von Neumann showing that it was a mathematical necessity. In other words, he proved that bluffing is a necessary part of life. And this idea was fundamental to game theory, that you can have these strategies put together.

In this very simple version of poker, though, there’s almost a list of fixed rules we can follow. So in other words, if you get high or low card, you raise the stakes. If you get a middling card, you stick with what you’ve got.

And in any game where you’ve got all the information in front of you– so other games for instance– things like noughts and crosses, checkers, chess– all of the games in theory have a fixed set of rules. It’s known as pure strategy. So you follow these exact rules, and you’ll get the optimal result.

So if someone noughts and crosses, I think most people can work out when they are younger that they realise there’s a set of moves. And if they always do that, they always get the results that’s the best possible. But of course, not all games are like this. A good example is rock, paper, scissors.

So it might be admirably consistent of you to always pick the same one. But if your opponent spots what you’re doing, they can take advantage of that. So it’s not the kind of optimal strategy if you’re trying to make your opponent’s decisions as difficult as possible. And these kind of games, that’s what you’re trying to do. You’re trying to make your opponent indifferent to changing, because you’ve got that tug of war going on.

So if they can gain more by adopting a different strategy, you haven’t got the optimal approach. And in rock, paper, scissors, if you want to make your opponent’s choices as difficult as possible, what you can just simply do is pick randomly. If you pick completely random options amongst those, then in the long run your opponent won’t be able to make any money off you. So this is kind of the optimal thing to do. And rock, paper, scissors, there’s three options.

It’s not too hard to work out that picking randomly will make your opponent’s decisions difficult. But games like poker are far more complex. You have a whole array of choices that you can make through the game. So it’s not something you can actually write down with pen and paper.

And fortunately we can turn to a technique that one of John von Neumann’s colleagues devised. And this was a mathematician called Stanislaw Ulam. And unlike many mathematicians, he wasn’t a big fan of working through loads of equations. On one occasion he was working a blackboard trying to solve a quadratic, got to the end, and was just so frustrated and annoyed, he went home for the day. So really kind of wasn’t his thing to kind of crunch through all this algebra.

He was once playing handheld, which is a version of solitaire. And he wondered what the probability would be if he just laid out the cards. What’s the probability he’d have a situation where he could win that game– the cards would fall in a favourable way.

He started looking at calculations and realised it was just a lot of effort. So instead he thought, well, what if I just lay out the cards a few times and see what happens. In other words, what if I just simulate this process a few times and get some sense of how likely it is.

At the time, Ulam and von Neumann were working on the US nuclear programme at Los Alamos working on neutron collisions. Part of the project was a hydrogen bomb. And again these are random processes where you couldn’t neatly write down the formulas and solve them. And they realised that this method would be incredibly powerful for that. Being a government programme, they needed a code name for it.

So they called it the Monte Carlo method, because Ulam had a heavy gambling uncle at the time. And the Monte Carlo method has become a fundamental part of science. I mean in my line of work where we try and look at disease outbreaks, you have something like Ebola or Zika, that’s an incredibly complex set of interactions.

It’s not something you can write down with pen and paper neatly. And so we use these simulation-based approaches simulating these random processes to understand these systems. It also appears now as a sports betting when you’re trying to understand how these very complex team interactions work.

And it also applies to poker. Teams have used this kind of approach for games of poker where you can’t neatly solve the equations. You can use a simulation-based approach to get the computers to learn. And actually Allen Turing one of the fathers of computing, when he was first thinking about this idea of machine learning, said that actually if you’re trying to build intelligent machine, it doesn’t make sense to build the adult mind. You don’t want to try and build the finished product with all the knowledge that was there.

It makes much more sense to build the child’s mind and let it learn. Let it work out how to play these kinds of games. And this is what these poker teams do. They create these algorithms that can learn. And actually the way in which they learn is perhaps a bit surprising, because what they do is they get these algorithms over time to employ what’s known as regret minimisation.

So as they play these games billions of times against each other, at each point when they’ve made a decision, they look back and say, could I improve that if I’d done something differently. So at each point they have an artificial measure of regret for each decision they make. And actually there’s a lot of evidence from some neurological– neuroscience studies– that that ability to have regret is quite important in learning games of chance. There’s been studies of people who have damage to the bit of the brain that’s responsible for regret– this ability to look backward and ask how would I feel if I’d done something differently.

And these people often are perfectly capable of playing logic games. If they have to sort cards, absolutely fine at that. If there’s any element of risk to the game and they have to learn how to play the optimal strategy, that’s something they really struggle with. And actually a lot of economic theories developed not around looking back but around what’s known as expectation maximisation. So in other words, you look forward. And you say, if I did this, could I make money?

If I did this, could I make more? But really from these artificial intelligence approaches, it seems that it’s much more powerful to look back and employ that power of regret as you go to look back on your decisions as you take these risks. And in fact these teams have employed these algorithms and got these computer bots to play each other so many times that last year they announced that poker is solved. To be specific, for two-player poker where the stakes have a limit, these bots have played each other so many times that they’ve come up with a strategy which will not be expected to lose money in the long run. So even if you’re playing a perfect opponent, this bot would not lose money over the course of a very long game.

Interestingly, actually a lot of the players who came up with this system, or a lot of the computer scientists, aren’t very good at poker themselves. By their own admission, they’re not poker players. So this is kind of a remarkable illustration of the power of these algorithms. You can have people who aren’t particularly good at poker creating poker bots that can beat any human arguably. This is a remarkable achievement. But there is, of course, a downside of this in that you’re assuming that your opponent is perfect.

If you’re looking for this optimal strategy, that’s inherently defensive, because you’re assuming that your opponent’s perfect. And you’re almost giving them too much credit. Because if you got a flawed opponent, and you’re coming up with a strategy that assumes they’re perfect, you’re potentially not exploiting them as much as you could. And just to give an example of these kind of flaws that could occur, let’s go back to rock, paper, scissors. What I’d like you all to do is just turn to the person next to you and play a couple of games of rock, paper, scissors with them, please. [BACKGROUND CONVERSATIONS] OK, thank you, ladies and gentlemen.

OK, I can see there’s a couple at back trying to play the best of seven or something. What I’d to do, can I just have a quick show of hands of who opened with rock there? OK, a fair few– who opened with scissors? Quite– and who opened with paper? OK, not so many actually for paper. So typically in these kind of big competitions where people play lots of times, it’s novices that open with rock, often men.

Scissors tends to be the most popular for people who play a lot of these games. And paper is not always chosen so common. Also think about what happened between the first game and the second game you played. Because in one fairly large study of rock, paper, scissors, what happened was people who when the first round typically stick with the same move for the second go.

So it’s this old– the military adage of generals always fought– always fight the last war, especially if they won it. So it’s the idea that if you won, you just stick with what’s safe. People who lost, however, will often switch to the move that would have beaten the one they lost. So if they lost to rock, they’ll often swap to paper on the next go. So it doesn’t always happen.

But in these large competitions, these kind of patterns emerge. So although the optimal thing to do in rock, paper, scissors is to behave completely randomly, people don’t. They fall into these predictable patterns. And there was actually a story a few years ago in Japan.

An electronics firm wanted to auction off their art collection. And they approached Christie’s and Sotheby’s to hold the auction. They were obviously both keen to do it. And so the head of the electronics firm decided the fairest way to settle it would be with a game of rock, paper, scissors. Now Sotheby’s thought that’s perfectly random.

That’s nice. That’s fine. Christie’s however, the CEO in Japan had a young daughter, a 7-year-old who played relentlessly in the playground. So he got his daughter to teach him a bit of rock, paper, scissors strategy. And they walked in sure enough to the boredom, Sotheby’s treating it like a random gain, Christie’s with a strategy.

Christie’s walked out the winner. So in this kind of case, exploiting those patterns and those kind of predictability and knowledge of what’s happened before can extremely valuable. But there are some challenges to that. And particularly if you are playing computers, one of the challenges from a human point of view is the limitation of our memory. So just to illustrate this point, what I’d like to do now is to just all of you try and memorise that number for me.

So I’ll give you a couple of moments to have a quick look at it. OK, right. Who fancies having a go at trying to recite it? Any volunteers?

Yes, sir? 6, 1, 0, 2, 6, 0, 1, 0, 0, 0, 6, 8. Very, very close, sir. Does any one want to have another go?

What was your name, sorry? Gavin. Gavin. So Gavin got very close. Any one want to try and build on that?

Yes. Yes? 610, 216, 1,000, 91. So what’s your name? Steve.

Steve. Steve– round of applause for Steve, ladies and gentlemen. [APPLAUSE] Now Steve did something quite clever there– don’t know if you spotted it. I’ll explain what he did.

So I asked you to memorise 10 digits. And that was actually a bit devious of me, because in a lot of psychological studies, people presented with numbers can typically memorise about seven and recite them. Sorry? 12. 12 digits? Yes.

In what? Up there. You said 10. Oh, sorry. Yeah, OK. I do have a PhD in maths, I assure you.

[LAUGHTER] OK, so actually I made it even harder. I was crueller than I thought. I do apologise. And so typically people can remember– like a local telephone number they can remember.

Two, they struggle with. But what, actually, Steve did when he recited the numbers, he didn’t recite those individually. He said 610, 260, 1,000, 91. So actually what he did, he bunched the numbers together. He wasn’t reciting ten bits of information.

He was chunking it into a smaller amount, which puts it below that threshold that you can memorise. And actually in other countries, so France for instance, if you go, their telephone numbers tend to be paired together. Which actually makes it easier to remember the numbers, because it’s much easier for you to remember these chunks of numbers rather than just a single sequence. I can actually guarantee that all of you will remember this number when you go home tonight. And that’s actually if you split it apart, and add in some punctuation, and then flip it around, that’s just the time and date of this talk. So all of you now will know that number and be able to recite it.

**And the reason is you’ve gone from 10 bits of seemingly arbitrary information down to one that clearly has some meaning to you**. And this ability to chunk is something that card counters employ, because clearly memorising a whole deck of cards is incredibly difficult. So what they do is they use what’s known as bucketing. They will group into say, low cards, medium cards, high cards. And then rather than having to memorise a whole deck, they only have these three buckets to remember. And what’s more, it’s kind of a memoryless properties.

They don’t have to remember everything. They can just keep the tallies of these three values. Of course there are some people out there that can memorise vast numbers of cards. The top memory champions can memorise about a thousand cards in an hour– a thousand playing cards in an hour. That’s remarkable. And the way they do that is they actually attach characters to the cards.

This will make them people and objects. And they attach a story to that. And similarly while you will all remember this, because you’re not remembering a number. You’re remembering an event.

You’re remembering a single thing which is much more memorable. And that’s really kind of how humans can get around this idea of the limitation of memory. But there are some disadvantages to learning about your opponent and remembering things and trying to take advantage of them. And that’s if your opponent’s incredibly smart, they could teach you the wrong image of themselves. So it’s what’s known as the get taught and exploited problem. If you’re playing poker, for instance, your opponent could pretend to be very passive and pretend to be very timid.

And then once you learned that notion of how they play, they could actually switch their behaviour and exploit the fact that you’ve learned the incorrect perception of them. It’s not just poker this happens. A couple of months ago, you may have seen it, a Microsoft launch of a bot for Twitter to learn from– I see you can see where this is going– to try and learn language. And the idea was to have conversations and improve its ability to learn. Twitter users unfortunately decided to teach it some unfortunate tricks. What actually happened within 24 hours, it had to be taken down, because it was coming out with so many horrendous opinions.

I think that’s an example of you have quite an intelligent algorithm. But if it’s being fed the wrong image of what it should be doing, it can actually veer off track very quickly. And this point of here I’ve talked about poker bots who have played billions of games to refine their strategy.

I’ve talked about these language bots. But in many situations, these bots aren’t very complicated. In finance, for example, programmes are designed to be fast. If you’re trading– if you want to get a trade off, you need to do that quickly.

So having that huge amount of complexity, and nuance, and rationality in your algorithm isn’t going to do the job. You really want to strip it down as simple as possible. In many cases, these high speed algorithms, you might just have a few lines of code.

And there’s one economics researcher I talked to put it, when you’re at ten lines of code, you’re not even at insect level intelligence. You’ve got no rationality and no nuance in there. You’re just trying to execute the trades as quickly as possible. In some situations this means that you can run into trouble.

There’s a case recently in Norway, where two traders had noticed that a US stock broker had an algorithm that was feeding trades at the market. And the algorithm would always react to a trade in the same way. In other words, if you traded with it, it would change its price by the same amount no matter how big that trade was.

So what these people in Norway did was teach the algorithm what to do. So it made lots of little trades. So it would move its price up and then make a big trade and profit from the difference. Now this ended up in court. These two traders were charged with market manipulation and handed suspended sentences.

But then there’s a Robin Hood reputation in the media for them in Norway. And it went to appeal. And their appeal lawyer made the point of if they had been trading against a stupid human who was doing this, that wouldn’t be a problem. The issue is that they were trading at a stupid algorithm presumably created by a human that hadn’t been thinking what they were doing.

And how should this be different? How should the notion of skill and responsibility be different because as a kind of one step away for the algorithm? And actually this argument held in court.

And in this situation, they were actually– this sentence was revoked. And this isn’t the first it’s instance a very simple algorithm would fall into trouble. A similar point actually– a US stock broker was introducing a new algorithm to feed orders into the market.

So you have a lot of orders from clients coming into the stock broker. And it would want to feed them in. They had eight servers doing this. What they had is a counter actually to keep track, because obviously if you got lots of orders coming in, and you’re sending them out to the market, you want to keep track of how many you’ve completed.

You don’t want to accidentally make too many. And they had one of these counts at each server. And then they updated their software.

But by all accounts, they didn’t add the counter to the eighth server. So there are seven servers that knew what they were doing– the eighth one that was kind of doing its own thing. And when this went live, what happened was the seven were behaving as they should. The eighth just peppered the market with high speed trades. And actually by the time they worked out what was happening and shut it down, in 45 minutes it had lost about $450 million.

So that’s a $170,000 a second for this runaway algorithm, because it was acting so fast and so much beyond what humans could control. And you might call that bad luck. You might call that error in skill.

And I think those cases around these kind of games and chance events are developing actually. In the US in recent years, there’s been a big crackdown on poker, particularly online. And as well in 2012, there was a crackdown on New York on poker rooms on a gentleman who was running a poker room that was taken to court and charged with operating a gambling operation. Now many casino games in federal law are defined as gambling. But poker isn’t one of them. So actually whether it was gambling or not was up for debate.

And in federal law, gambling is defined as anything that is predominantly due to chance. So any game that’s predominantly the result of chance is defined as gambling. So what happened is this entire legal case rested on is poker a game of chance or a game of skill. And they got economists coming in– mathematicians. And they made the point that on a single game of poker, of course there’s an element of luck, because you got this deal.

But then equally in baseball, if someone’s pitching a single ball, there’s going to be an element of chance involved. But over the course of a poker game, typically the more skillful players won. And this was the first time actually that a US court had ruled on whether poker is a game of chance or a game of skill.

And they ruled that it was a game of skill. There’s a footnote to this story. The following year when it went to the State Appeals Court.

Now in New York state law, gambling is defined as anything that has a material element of chance. So if you think about this, this is a much narrower definition of gambling. It’s not predominantly chance. It’s anything with a material element, which clearly poker does have. And under this condition it’s defined as gambling. And this debate is ongoing.

If you look fancy sports in the US and a lot of these systems where– do we have something that’s luck. Do we have something that’s skill? Where do we– do we actually define these things as gambling?

I think there’s often a temptation in fact with these situations to put things in boxes. We like to say there’s a box with luck, and there’s a box with skill. I think typically if we’re good at something, it goes in the box on the right. If we’re bad at something, it goes in the box on the left. And that’s really tempting. But I don’t think it’s a realistic notion necessarily.

I think particularly through the history of how people have tackled games like roulette and with lotteries is much more of a spectrum. And actually games that we might think are the archetype of luck, things like roulette, actually if you have a skillful approach you can tame that chance. And you can convert it into some element of a game of skill.

And even games that we might think are incredibly, almost solely the work of skill, games like chess can have surprising results of chance. In the ’90s, famously, IBM’s Deep Blue chess computer played Gary Kasparov. And during the match in one of the early games, there was a situation where Deep Blue made a move that was so unexpected and almost so subtle that it threw Kasparov off a bit– all accounts convinced him that he was playing something that was just simply beyond what he was– ever seen before– just something completely beyond his capability.

It turned out actually that what happened there is Deep Blue had run into a situation where it couldn’t identify the best move. And in that situation it had been programmed to pick randomly. So this set of games that is one of the landmarks in artificial intelligence over humans in a game that is thought to be purely skill was actually really shaped by this chance event. And I think these kind of illustrations show why gambling and why these games of chance are so important. Because really whatever your views are of casinos and bookmakers, gambling is an inherent part of life.

Betting is an inherent part of what we do, whether it’s in health in prediction on this side– whether it’s in business– whether in finance. We have to make decisions with hidden information. We have to deal with uncertainty. We have to balance the risks against the rewards. I think that’s why historically so many researchers have been interested in gambling and continue to do so.

Because really if you want to understand luck, and decision making, and risk, then arguably there’s no way better to start than with a bet. Thank you. [APPLAUSE] What your view of where investing in the stock market might fall between luck and skill, should I pay somebody a 2% fee for their skill at investing my money?

Or should I just rely on buying the market?