I used Python to find out about the role choices of the 51 "Yachts" in the world.

Introduction

https://youtu.be/iNAUzUEsgs4?t=8691

It was when Tomoe Shirayuki was playing "Yacht" in the "World's Asobi Taizen 51" distribution.

"Mottainai is a choice here"

(The score at that time was 20)

I suddenly wondered, so I did some research.

Yacht is a game of rolling 5 dice to make a hand, and Choice is one of them.

Choice is the sum of all eyes to score.

Conclusion

20 is a choice choice "Yes"

--The average choice is 17.5 --69.48% chance of being less than 20 ――The probability of becoming 21 or more is 22.14%

Preparation

When throwing a single die with 1 to 6 rolls, consider the average number of rolls.

(* The appearance of the eyes is also certain)

Here, the total number of dice rolls is 21, and each roll can be expected to appear evenly, so the average $ E (x) $ to be calculated is $ E(x) = \frac{1}{6} \times 21 = \frac{7}{2} $ Can be calculated.

The $ E (x) $ obtained in this way is called the expected value of $ X . $ \begin{eqnarray} E(x) &=& x_1p_1 + x_2p_2 + \cdots + x_np_n \ &=& \sum^n_{k=1}x_kp_k\ &&(X = x_1, x_2, ..., x_n)(P=p_1, p_2, ..., p_n) \end{eqnarray} $$ Is required.

Main subject

Now, if you throw 5 dice at the same time, consider the average of the total number of dice.

At this time, the probabilities for the five dice are independent, so the average can be obtained by simply adding them together.

In other words $ E(x) = \frac{7}{2} \times 5 = \frac{35}{2} $ Will be.

When $ X $ is a random variable and $ a $, $ b $ are constants $ E(aX+b) = aE(x)+b $ Is true, so you can substitute $ E (X) = \ frac {7} {2} $, $ a = 5 $, $ b = 0 $.

Practice

So far, I have used mathematics to find the average of choices.

~~ But I've forgotten so much, so I don't know if it's correct ... ~~

From now on, we will use Python to verify that the average we have calculated is correct.

In addition, all the following codes have been confirmed to work on Google Colab.

Average calculation

The strategy is simple.

Roll 5 dice 100 million times and find the total of the eyes. Next, if you find the average, you can find the average to find.

In other words, the law of large numbers.

The code I actually tried is below.

import numpy as np

#Number of trials
N = 1 * 10**8

#Choice execution
x = np.random.randint(1, 6+1, (N, 5))
x = x.sum(axis=1)

#Average calculation
print(np.mean(x))
# 17.4996012

The result was 17.4996012, which was almost the same as the calculation result.

A brief explanation.

On the 7th line, create random numbers 1 to 6 with size (N, 5).

On line 8, calculate the sum of each of the 5 dice.

histogram

It was easier than I expected, so I created a histogram as a bonus.

The code actually used is as follows.

import numpy as np
import matplotlib.pyplot as plt

#Number of trials
N = 1 * 10**8

#Choice execution
x = np.random.randint(1, 6+1, (N, 5))
x = x.sum(axis=1)

#Histogram generation
result = plt.hist(x, bins=26, alpha=0.5, color=(0.43, 0.25, 0.91))

#Auxiliary line
ex = 17.5
min_ylim, max_ylim = plt.ylim()
plt.axvline(17.5, color='k', linestyle='dashed', linewidth=1)
plt.text(ex*1.05, max_ylim*0.9, f"E(x)={ex}")
plt.axvline(20, color='w', linestyle='dashed', linewidth=1)

#label
plt.title('Distribution of Scores in "Choice"')
plt.xlabel("point")
plt.ylabel("frequency")

plt.savefig("fig.png ")

The resulting histogram is below.

fig.png

In this histogram, the black dotted line is the average and the white dotted line is 20.

From this, you can see at a glance that it is above the average.

Probability less than 20

Now, what is the probability that your choice score will be less than 20?

If this is known, it will be more persuasive.

So, ask Python to find it approximately.

import numpy as np

#Number of trials
N = 1 * 10**8

#Choice execution
x = np.random.randint(1, 6+1, (N, 5))
x = x.sum(axis=1)

#Frequency calculation
uni, counts = np.unique(x, return_counts=True)
d = {str(u): c for u, c in zip(uni, counts)}

#Probability of less than 20
temp = [v for k, v in d.items() if int(k) < 20]
print(f"{(sum(temp) / N)*100:.02f}%")
# 69.48%

The result was 69.48%, and it was found that about 70% of the total was less than 20.

Also, if you change the direction of the inequality sign on the 15th line of this program, you can easily check the probability of occurrence of 21 or more.

The result is 22.14%. In other words, the probability of getting a higher hand is about 20%.

It feels expensive because it is poisoned by the gacha of social games, but ...

in conclusion

Asobi encyclopedia game fun to analyze

Recommended Posts

I used Python to find out about the role choices of the 51 "Yachts" in the world.
[Note] About the role of underscore "_" in Python
I tried to find out the outline about Big Gorilla
Find out the apparent width of a string in python
Python --Find out number of groups in the regex expression
I wrote the code to write the code of Brainf * ck in python
I used the worldcup command to check the outcome of the World Cup.
I want to know the population of each country in the world.
I tried to find out the difference between A + = B and A = A + B in Python, so make a note
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I tried to streamline the standard role of new employees with Python
[Introduction to Python] Thorough explanation of the character string type used in Python!
I made a program to check the size of a file in Python
Find the solution of the nth-order equation in python
About the behavior of Model.get_or_create () of peewee in Python
I want to display the progress in Python!
[Completed version] Try to find out the number of residents in the town from the address list with Python
I used gawk to find out the maximum value that goes into NF.
How to find out what kind of files are stored in S3 in Python
I want to use Python in the environment of pyenv + pipenv on Windows 10
How to find the coefficient of the trendline that passes through the vertices in Python
I tried to graph the packages installed in Python
Find out the location of Python class definition files.
I checked out the versions of Blender and Python
I want to write in Python! (3) Utilize the mock
A reminder about the implementation of recommendations in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
I want to use the R dataset in python
I tried to summarize the string operations of Python
I tried to find out how to streamline the work flow with Excel x Python ②
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to find out how to streamline the work flow with Excel x Python ⑤
I tried to put out the frequent word ranking of LINE talk with Python
I just want to find the 95% confidence interval for the difference in population ratios in Python
I tried to find out how to streamline the work flow with Excel x Python ①
A story about trying to introduce Linter in the middle of a Python (Flask) project
I tried to find out how to streamline the work flow with Excel x Python ③
[Python] Find out about pip
Find the difference in Python
About the ease of Python
About the features of Python
How to find the optimal number of clusters in k-means
I tried to find the average of the sequence with TensorFlow
I tried to summarize the code often used in Pandas
[Python] I tried to visualize the follow relationship of Twitter
I tried to summarize the commands often used in business
I tried to implement the mail sending function in Python
I want to know the features of Python and pip
I want to know the legend of the IT technology world
Find the eigenvalues of a real symmetric matrix in Python
I tried to implement blackjack of card game in Python
Use hash to lighten collision detection of about 1000 balls in Python (related to the new coronavirus)
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
I tried to create a Python script to get the value of a cell in Microsoft Excel
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
I tried to find the trend of the number of ships in Tokyo Bay from satellite images.
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
I tried to find out how to streamline the work flow with Excel × Python, my article summary ★
How to determine the existence of a selenium element in Python