Search This Blog

Probability Problem - Competition with 5 players

This problem is from the book of M.G.Bulmer "Principles of Statistics"

Problem 2.6, page 28.

Five players enter a competition in which each plays a game against each of the others. 

The two players in each game have an equal chance of winning it; 

a game must end in a win for one of the players who then scores a point. 

The competition is won by the player or players scoring most points. 

What is the probability that a particular player will

(a) win the competition outright;

(b) share in winning with other players?

I could not solve this by paper and pencil so I wrote a Python program which solves it.

Here's the program. 


import pprint

def main():

    mapping = {}
    mp = {}
    
    # There are 10 games in total.
    # So there are 2^10 = 1024 possible outcomes
    # from the competition as a whole.
    
    k = 0
    for i in range(5):
        for j in range(5):
            if (i<j):
                mapping[k] = (i,j)
                k = k+1
    
    # print(mapping)
    for num in range(1024):
        lst = []
        deg = 1
        for q in range(10):
            lst.append(1 if (num & deg) else 0)
            deg = deg << 1
        mp[num] = lst
    
    pprint.pp(mp)
    
    
    player_0_wins = 0
    player_0_wins_outright = 0
    
    for competition in mp:
        
        print()
        print()
        print()
        
        points = {}
    
        n = 0
        
        for game in mp[competition]:
            
            (p,q) = mapping[n]
            
            if not p in points:
                points[p] = 0
            if not q in points:
                points[q] = 0
                
            points[p] = points[p] + game
            points[q] = points[q] + (1-game)
            
            print("Player", p, ":", "Player", q, " = ", game, " : ", 1-game)
            
            n = n+1
        
            
        print("points = ", points)
        
        # Here we suppose that:
        c1 = 1 # player 0 wins
        c2 = 1 # player 0 wins outright
        
        # Now we check if these suppositions are true:
        for p1 in points:
            if (p1 != 0) and points[p1] >= points[0]:
                c2 = 0 # does not win outright; p1 has the same number of points or more points than player 0
                break
                
        for p1 in points:
            if (p1 != 0) and points[p1] > points[0]:
                c1 = 0 # does not win; p1 has more points than player 0
                break
        
        print("Player 0 wins: ", 1==c1)
        print("Player 0 wins outright: ", 1==c2)
                
        player_0_wins = player_0_wins + c1
        player_0_wins_outright = player_0_wins_outright + c2
        
    
    print()
    print()
    print()
    
    print("Player 0 wins outright probability: ", player_0_wins_outright, '/', len(mp))
        
    print("Player 0 shares the win probability: ", player_0_wins - player_0_wins_outright, '/', len(mp))
    
    print()
    print()
    print()
    
    
    
if __name__ == "__main__":
    main()






No comments:

Post a Comment