First I explain the game; heads, it’s game over. In how many steps does the game end on average?

This is the question to be solved, the first attempt at a solution is to do a thought experiment.Lets try first way;

If there is no cheat, the probability of the game ending in the first step is most probably converges to1/2.If it is considered as the first step, the probability of ending in step 2 is 1/4.Likewise in step 3 it is 1/8, 4. step 1/16, 5 is 1/32 , it goes like this. If we multiply each step by the number of steps, we calculate the average number of steps.Actually want to calculate these steps infinite, it can be written as in the photo.

sigma

Let’s write this sum in a table.

think its infinite

let’s calculate the lines and total of the all lines. Sum of all lines is 2. It is average of the steps.

The order of the 2nd way:

The number of computers determined in this way plays by itself.

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main(){
    int a;
    double b=0,c=0,d,x=0,r;
    srand(time(0));
    printf("How many times is a coin tossed?\n");
    scanf("%d",&a);
    for(int i=0;i!=a;i++){
        b=0;
        for(int k=0;b!=1;k++){
            c=rand()%(2);
            x++;
            if(c==1){
                b=1;
        }}}
    r=x/a;
    printf("\nAverage of steps tossed a coin%lf",r);
    }

Compile and run try some numbers

inconsistent results for a small number of trials are completely natural

Let big numbers:

Now the numbers are converging

Thank you for reading

Leave a Reply

Your email address will not be published. Required fields are marked *