[PYTHON] You will be an engineer in 100 days --Day 64 --Programming --Probability 2

Click here until yesterday

You will become an engineer in 100 days --Day 63 --Programming --Probability 1

You will become an engineer in 100 days-Day 59-Programming-Algorithms

You will become an engineer in 100 days --- Day 53 --Git --About Git

You will become an engineer in 100 days --Day 42 --Cloud --About cloud services

You will become an engineer in 100 days --Day 36 --Database --About the database

You will be an engineer in 100 days-Day 24-Python-Basics of Python language 1

You will become an engineer in 100 days --Day 18 --Javascript --JavaScript basics 1

You will become an engineer in 100 days --Day 14 --CSS --CSS Basics 1

You will become an engineer in 100 days --Day 6 --HTML --HTML basics 1

About expected value

The expected value is the average value obtained in one trial.

It is the product of all the values obtained and the probability that it will occur.

Consider the example of a dice.

The odds of getting a dice are as follows.

Eyes to come out(x) 1 2 3 4 5 6
probability(p) 1/6 1/6 1/6 1/6 1/6 1/6

The expected value of the roll is the sum of the roll * probability.

$ 1 * \frac{1}{6} + 2 * \frac{1}{6} +3 * \frac{1}{6} +4 * \frac{1}{6} +5 * \frac{1}{6} +6 * \frac{1}{6} = 3.5$

You can expect the average to roll the dice once to be 3.5.

Reduction rate

Gambling also has expectations. At that time, the ratio of the amount to be refunded to the bet It is called reduction rate.

For example, suppose you pay 10 million yen and have a 50% chance of getting 15 million yen, a 40% chance of 5 million yen, and a 10% chance of getting 0 yen.

The expected value is (50% x 1500 million yen) + (40% x 5 million yen) + (20% x 0 yen) = 9.5 million yen

The reduction rate is 9.5 million yen / 10 million yen, which is 95%.

Would you like to gamble like this? The more I keep doing it, the less money I think.

What is often said about the return rate of domestic gambling

type Reduction rate
Horse racing About 75%
Bicycle race About 75%
Boat race About 75%
Auto race About 75%
lottery About 46%
Soccer lottery About 50%
pachinko About 80-90%

The more you do, the less money you will get.

Even if you spend advertising expenses to attract customers The more people get together, the more profitable parents will be. It's an irresistible business.

Basically, gambling with a return rate of more than 100% cannot exist.

If there was gambling with a return rate of over 100% The money on the side of the spending will increase steadily.

Gambling probability

Consider the different gambling probabilities.

Horse racing

Horse racing is to rely on the order of arrival with 16,18 horses. How to buy will change depending on the order of arrival.

** Win **

I'm going to count on one.

In this case, the probability of hitting is 16 heads $ \ frac {1} {16} = 6.25 $% 18 heads $ \ frac {1} {18} = 5.556 $%

** Double win **

Hit the horse that fits in 1-3.

The expected horse can be 1st or 3rd It's simply three times the win.

In this case, the probability of hitting is 16 heads $ \ frac {3} {16} = 18.75 $% 18 heads $ \ frac {3} {18} = 16.667 $%

If it is a double win It's a probability of hitting once every six times.

However, the average refund is about double. It's not very delicious.

** Frame Ren **

Eighteen horses are placed in the nine frame. Each consists of 1-2 heads It is to guess the ranking in that frame.

Two frames are selected from the nine frames.

There are 36 ways \frac{1}{36} = 2.7778%

** Maren **

It is a way of buying that either 1-2 or 2-1 is acceptable as a combination of the two selected heads in 1-2.

16 heads $ \ frac {1} {120} = 0.83333 $% 18 heads $ \ frac {1} {153} = 0.65359 $%

** Single horse **

It is a way to buy 1-2 outfits by combining the two selected ones into 1-2 outfits.

16 heads $ \ frac {1} {240} = 0.41667 $% 18 heads $ \ frac {1} {306} = 0.3268 $%

wide

2 out of 3 combinations It is expected in no particular order regardless of the order of arrival.

I just need to wear 1-2, 1-3, 2-3 It's simply three times as likely as Maren.

16 heads $ \ frac {3} {120} = 2.5 $% 18 heads $ \ frac {3} {153} = 1.9608 $%

** Triple **

Predict the combination of 1st, 2nd and 3rd in no particular order Combination 16C3, 18C3

16 heads $ \ frac {1} {560} = 0.17857 $% 18 heads $ \ frac {1} {816} = 0.12255 $%

** Triple unit **

Predict the combination of 1st, 2nd and 3rd in the order of arrival Permutation 16P3, 18P3

16 heads $ \ frac {1} {3360} = 0.029762 $% 18 heads $ \ frac {1} {4896} = 0.020425 $%

WIN5

5 races designated by JRA I expect each one. It's a win to the 5th power

18 heads $ \ frac {1} {1889568} = 0.0000529221 $%

The probability is about 1 in 1.9 million.

Because the probability of lottery etc. is about 1 in 10 million I think WIN5 has a higher expected value.

The probability of horse racing is high

Double win> Single win> Frame series> Wide> Horse series> Horse single> Triple double> Triple single> WIN5

Will be.

Roto Six

Lotto 6 is a number from 1-43 to 6 real numbers and 1 bonus number A total of 7 numbers are selected and guessed, and there are 1-5 mag.

** 1st prize **

Match all 6 numbers 43C6

\frac{1}{6096454} = 0.0000164030%

1st prize has a probability of about 1/6 million.

** 2nd grade **

Matches 5 numbers, matches 1 bonus number

\frac{6}{6096454} = 0.0000984179%

The second prize has a probability of about 1 in 1,000,000.

** 3 etc. **

5 out of 6 match this number

\frac{216}{6096454} = 0.0035430432%

The probability is roughly 1 / 30,000.

** 4 etc. **

4 out of 6 match this number

$\frac{9990}{6096454} = 0.1638657488 $%

Is it the probability of hitting about once in 600 times?

** 5 etc. **

3 out of 6 match this number

$\frac{155400}{6096454} = 2.5490227598 $%

It's a probability of about once in 40 times.

Since 5th grade is 1000 yen, it only hits with a probability of2.5%. Even if I buy it 40 times, only 1000 yen will be returned.

If it is not the first place, it will be carried over by carryover and the amount will increase In the first place, there is almost no chance of hitting in life with a probability of 1 in 6 million.

poker

Poker is a game that uses 52 cards. Find out how many roles you have.

The role is

Role Contents
Royal straight flush A-K-Q-J-10
Straight flush With consecutive numbers(Picture)
5 cards of the same suit
Four Cards 4 cards of the same rank and 1 other car
Full house Three cards of the same rank and two other cards of the same rank.
flash Five cards of the same suit.
straight Five cards with consecutive numbers.
Three cards Three cards of the same rank and two side cards of different ranks.
Two pair Two sets of two cards of the same rank, two sets, and one side card.
One pair Two cards of the same rank and three side cards of different ranks.
High card A hand that does not fit into any of the above. pig

This time I made a program to judge the role Determine what the role is from the combination of all cards Find the number of combinations of roles.

The deck creates a function to judge it as 52 cards From the combination when 5 sheets are selected from all 52 sheets Count the number of roles in search of what the role is.

#Deck generation
deck=[b+':'+str(a) for a in range(1,14) for b in ['C','S','D','H']]

#Judgment of the role
def jadge_role(card):
    s = {}
    for c in card:
        k = int(c.split(':')[1])
        if k in s:
            s[k]+=1
        else:
            s[k] =1
    t = {c.split(':')[0] for c in card}
    n = sorted([c for c in s.keys()])
    if len(t)==1 and all([1 in n,10 in n ,11 in n,12 in n,13 in n]):
        return 'RSF'
    if len(t)==1 and (all([1 in n,10 in n ,11 in n,12 in n,13 in n]) or
             (max(n)-min(n)==4) and len(s)==5):
        return 'SF'
    if 4 in s.values():
        return '4C'
    if 3 in s.values() and 2 in s.values():
        return 'FH'
    if len(t)==1:
        return 'FL'
    if (all([1 in n,10 in n ,11 in n,12 in n,13 in n]) or
             (max(n)-min(n)==4) and len(s)==5):
        return 'ST'
    if 3 in s.values():
        return '3C'
    if list(s.values()).count(2)==2:
        return '2P'
    if list(s.values()).count(2)==1:
        return '1P'
    return 'BT'

#Calculate combination
cards = itertools.combinations(deck,5)
calc_dict = {}
for card in cards:
    role = jadge_role(card)
    if role in calc_dict:
        calc_dict[role] += 1
    else:
        calc_dict[role]  = 1

#result
poker_base = math.factorial(52) // (math.factorial(52 - 5) * math.factorial(5))
print(poker_base)
for k,v in sorted(calc_dict.items(),reverse=True,key=lambda x:x[1]):
    print(k,'\t',v,'\t','{0:.10f}%'.format(v/poker_base*100))

2598960

Role Number of times Percentage
BT 1302540 50.12%
1P 1098240 42.26%
2P 123552 4.75%
3C 54912 2.1128%
ST 10200 0.39246%
FL 5108 0.19654%
FH 3744 0.144057%
4C 624 0.024009%
SF 36 0.001385%
RSF 4 0.0001539%

The result is like this.

The royal straight flush is calculated to come out about once in about 640,000 times.

Of flash and straight, straight is twice as likely to appear. So if you're wondering which one, aim for a straight with a high probability. It may be a strategy.

Summary

If the probability and expected value are obtained, the return rate can also be calculated. Because gacha etc. are the same as roulette games etc. If you ask for the probability, how much money should you put in to win the character? You can simulate.

In games and gachas, we often ask for probabilities and expected values. It may be good to know how to calculate various probabilities.

36 days until you become an engineer

Author information

Otsu py's HP: http://www.otupy.net/

Youtube: https://www.youtube.com/channel/UCaT7xpeq8n1G_HcJKKSOXMw

Twitter: https://twitter.com/otupython

Recommended Posts

You will be an engineer in 100 days --Day 65 --Programming --Probability 3
You will be an engineer in 100 days --Day 64 --Programming --Probability 2
You will be an engineer in 100 days ――Day 71 ――Programming ――About scraping 2
You will be an engineer in 100 days ――Day 61 ――Programming ――About exploration
You will be an engineer in 100 days ――Day 74 ――Programming ――About scraping 5
You will be an engineer in 100 days ――Day 73 ――Programming ――About scraping 4
You will be an engineer in 100 days ――Day 75 ――Programming ――About scraping 6
You will be an engineer in 100 days --Day 68 --Programming --About TF-IDF
You will be an engineer in 100 days ――Day 70 ――Programming ――About scraping
You will be an engineer in 100 days ――Day 81 ――Programming ――About machine learning 6
You will be an engineer in 100 days ――Day 82 ――Programming ――About machine learning 7
You will be an engineer in 100 days ――Day 79 ――Programming ――About machine learning 4
You will be an engineer in 100 days ――Day 76 ――Programming ――About machine learning
You will be an engineer in 100 days ――Day 80 ――Programming ――About machine learning 5
You will be an engineer in 100 days ――Day 78 ――Programming ――About machine learning 3
You will be an engineer in 100 days ――Day 84 ――Programming ――About machine learning 9
You will be an engineer in 100 days ――Day 83 ――Programming ――About machine learning 8
You will be an engineer in 100 days ――Day 77 ――Programming ――About machine learning 2
You will be an engineer in 100 days ――Day 85 ――Programming ――About machine learning 10
You will be an engineer in 100 days --Day 34 --Python --Python Exercise 3
You will be an engineer in 100 days --Day 31 --Python --Python Exercise 2
You will be an engineer in 100 days --Day 86 --Database --About Hadoop
You will be an engineer in 100 days ――Day 24 ―― Python ―― Basics of Python language 1
You will be an engineer in 100 days ――Day 30 ―― Python ―― Basics of Python language 6
You will be an engineer in 100 days ――Day 25 ―― Python ―― Basics of Python language 2
You will be an engineer in 100 days ――Day 60 ――Programming ――About data structure and sorting algorithm
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
You will be an engineer in 100 days --Day 26 --Python --Basics of the Python language 3
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
You will be an engineer in 100 days --Day 32 --Python --Basics of the Python language 7
You will be an engineer in 100 days --Day 28 --Python --Basics of the Python language 4
You become an engineer in 100 days ――Day 67 ――Programming ――About morphological analysis
You become an engineer in 100 days ――Day 66 ――Programming ――About natural language processing
If you draw an Omikuji with a probability of 1% 100 times in a row, will you win once?
If you write the View decorator in urls.py in Django, the list will be higher.
If an exception occurs in the function, it will be transmitted to the caller 2
If an exception occurs in the function, it will be transmitted to the caller 1