So basically, at the start of the program, I have no success, and

I will attempt 10,000 of this tossing.

So, I will run through all this 10,000 attempts, and

this function randint just returned (0,1) with probability one-half.

So, I will just say that 1 is head and 0 is tail.

And I just sum up these 4 tosses.

And if it's gives me 3, it mean that I got 3 hat, for instance.

And then, I just say that success is incremented by 1.

Then, that's all.

I can now run this program, and see what's the result out of the number of attempts,

how many [INAUDIBLE] success I have.

And here, in this example out of my 10,000 attempts i get 2559 success.

Which is actually not so bad knowing that the official mathematical result is 1/4.

So, it's almost 1/4.

Of course, if instead of 10,000 I would have

100,000 I would have been closer to this exact result.

So, it shows that the Monte-Carlo is a sampling approach but

of course you may get some errors and you have to take that into account.

Of course, the coin tossing problem is very simple, and per I don't need to have

a Monte Carlo method to solve anything cuz the math is good enough for that.

But you can think of a more difficult problem for

which mathematics is probably hard to apply.

And as an example, I'd like to illustrate

a card game the card game which is called the war or the battle.

So, how does it work?

I have a deck of cards.

I already separated that into two parts for two players,

but that will be the two players at the same time.

So this has been shuffled properly.

And the idea is that each of the player, they showed a card on the top of the deck,

which is basically my example is two.

And the stronger card is this one, so

it takes the seven, and the winner put it below his deck.

So, now we just enter in this process and

her,e we see that those have the same value so those is called a battle or

a war and then, the way it goes is that you take a card result showing it,

and cover it, and then, you do it again with the new card.

And five is again stronger than four, so this player is taking everything.

And putting that under this deck.

And it goes on until there's no more cards.

So, one player has just all this deck.

So, the question is how long does it last.

On average, okay?

Maybe you play that game and you noticed that usually it lasts long.

So, this is just a simulation when you can just program in your computer this game.

It's very simple, okay?

And, here on this graph, you see has a function of the round.

So, how many times the player play.

The number of cards that one of the player has,

of course the other player has the complement to 52.

And you see that it fluctuates a lot.

Here, you may think the guy is almost losing.

But no there is fluctuation it goes up again.

And after about 898 rounds okay, finally, player number

one losses, this is just one instance of the game, playing the computer.

Now, I could start doing statistics and say okay, I can repeat this over and

over, and have an idea of what's the average duration of the game.

I will not show you the result here, but

I can tell you that, on our ready class very long.

So, 800 is not at all exceptional.

You can even have even game that are longer than 10,000 rounds, okay?

So, maybe it's of limited practical interest but it shows that here if I had

to apply a probability theory it would probably be very difficult.

I mean, everything is in the initial distribution of my card in the deck.

So, I should consider all possible distribution and then,

have a combinatorics to follow the story.

And I guess this is a bit too difficult.

That's actually card games also the motivation of this method.

It's due to the famous scientist of the 40's.