Sazae-san's rock-paper-scissors I tried to verify the theoretical value and the measured value of the probability of the same hand 5 consecutive times with Ruby

TL;DR If you decide on a random move, the probability that the same move will appear 5 times in a row at least once in 30 years is The theoretical value is 99.999999%, and the measured value is 99.999%. Nevertheless, Sazae-san has never put out the same hand five times in a row for 30 years. Sazae-san is random and not rock-paper-scissors. There is a person inside.

In the first place

As I learned on Twitter, as shown in ↓, when I went around with "Sazae-san" and "rock-paper-scissors", the same hand of rock-paper-scissors appeared five times in a row, the first in 30 years of history. I will. https://nlab.itmedia.co.jp/nl/articles/2006/08/news108.html

For the first time in 30 years, I feel that it is super rare, but in fact, I will try "calculation (theory)" + "trial (actual measurement)" to see how rare it is. (Since the tool that can be used quickly at hand was Ruby, I wrote it in Ruby)

Premise

Which move to play with rock-paper-scissors is completely random (rand (3) equivalent randomness)

Calculation (theory)

Probability of getting the same hand 5 times in a row

First of all, the probability of getting the same hand of rock-paper-scissors five times in a row is Any first move (1) x 4 same moves (1/3 to the 4th power) Because it becomes

SERIES_COUNT = 5 #5 times in a row

rate_5 = 1.0 * (1.0 / 3.0) ** (SERIES_COUNT - 1)

=> 0.012345679012345677

It's about 1.2%.

Probability of getting the same hand 5 times in a row even once in 30 years

Rock-paper-scissors once a week, the first in 30 years of history, so the number of rock-paper-scissors so far is 1 [janken/week] * 30 [year] * 52 [week/year] = 1560 [janken] It becomes.

The probability that you will get the same hand 5 times in a row even once after playing rock-paper-scissors 1560 times 1-(Probability of not getting the same hand 5 times in a row out of 1560 times) You can think of it as.

Also, of the 1560 times, the last 4 times will not be 5 consecutive times, so The number of times you can challenge the same hand 5 times in a row out of 1560 times 1560 - (5 - 1) = 1556 It becomes.

For example, if it is 10 times in total, the image of trying ↓ 10-(5-1) = 6 times. ●●●●●○○○○○ ○●●●●●○○○○ ○○●●●●●○○○ ○○○●●●●●○○ ○○○○●●●●●○ ○○○○○●●●●●

The probability of not getting the same hand 5 times in a row is 1-(Probability of getting the same move 5 times in a row) So 1 - 0.012345679012345677 Will be

Of the 1560 times, the probability that the same move will not be made 5 times in a row means that the probability of ↑ will be 1556 times in a row. (1 - 0.012345679012345677) ^1556 = 0.00000000403024 It becomes.

The probability of getting the same hand 5 times in a row even once in 1560 rock-paper-scissors is 1 - 0.00000000403024 = 0.99999999596976

I can't go to Eleven Nine, but Eight Nine is almost 100%. If you play rock-paper-scissors every week for 30 years, you will have the same hand at least once five times in a row.

The one that let Ruby calculate


YEARS = 30
WEEKS_PER_YEAR = 52
SERIES_COUNT = 5

trial_probability = 1.0 * (1.0 / 3.0) ** (SERIES_COUNT - 1)
trial_n = YEARS * WEEKS_PER_YEAR
total_no_hit_probability = (1.0 - trial_probability) ** (trial_n - SERIES_COUNT + 1)
total_hit_probability = 1 - total_no_hit_probability

total_hit_probability
=> 0.9999999959697649

Trial (actual measurement)

Play rock-paper-scissors 1560 times with brute force to see if the same hand is out 5 times in a row. Try 1 million times and measure how many times you get the same hand for 5 consecutive times.

The one who let Ruby try


YEARS = 30
WEEKS_PER_YEAR = 52
SERIES_COUNT = 5

#A function that checks if the same value is consecutive 5 times in the passed array
def check_serial_same_5(values)
  hit_count = 0

  (values.size - SERIES_COUNT + 1).times { |i|
      if values[i] == values[i + 1] &&
          values[i] == values[i + 2] &&
          values[i] == values[i + 3] &&
          values[i] == values[i + 4]
        hit_count += 1
      end
  }

  return hit_count
end

N = 1000000 #1 million trials

total_hit = 0 #Number of times the same hand was made 5 times in a row out of 1 million times

N.times {
  #Rock-paper-scissors for 30 years
  values = []
  (YEARS * WEEKS_PER_YEAR).times {
    values << rand(3) #Rock-paper-scissors hand rand(3)Alternative with
  }

  hit = check_serial_same_5(values)

  if hit != 0
    total_hit += 1
  end
}

real_trial_probability = total_hit.to_f / N.to_f

real_trial_probability
=> 0.999998 #1st 1 million trials
=> 1.0      #Second trial of one million trials
=> 0.999996 #3rd trial of 1 million times

In principle, if you try 1 million times, it will not be eight nines, but This is also almost 100%. If you play rock-paper-scissors every week for 30 years, you will have the same hand at least once five times in a row.

Postscript (tried 1 billion times)

Rock-paper-scissors every week for 30 years, at least once, the probability of getting the same hand 5 times in a row, I tried it 1 billion times and confirmed it. Result is, 0.999998264 The probability is almost the same as 1 million trials (five nines).

Summary

Sazae-san, who has been playing rock-paper-scissors every week for about 30 years, The fact that I've never done the same thing five times in a row Sazae-san isn't deciding what to do at random. It suggests that the will of a person may intervene there.

If you've been playing rock-paper-scissors every week for 30 years at completely random, you should have a 99.999% or higher chance of getting the same hand 5 times in a row. Contrary to theory means that human will is involved.

Afterword

When the integers n, N, are n <N, Probability of playing rock-paper-scissors N times and having the same hand n times in a row It is a little suspicious whether the calculation of is correct by the method described in ↑.

N = 10 n = 5 At that time, the number of lottery is 6 times to see if the same hand can be obtained 5 times in a row.

The theoretical value is eight nine and the measured value is five nine, which is almost the same in the sense that it is almost 100%. Since the precision is different in digits, there is a possibility that the calculation of the theoretical value is incorrect.

Does that mean that there are other conditions that are lower than the probability calculated in ↑ (= more difficult to get the same hand in a row)? .. ..

---///

Recommended Posts

Sazae-san's rock-paper-scissors I tried to verify the theoretical value and the measured value of the probability of the same hand 5 consecutive times with Ruby
I tried to measure and compare the speed of GraalVM with JMH
[Beginner's point of view] I tried to solve the FizzBuzz problem "easily" with Ruby!
I tried to summarize the basics of kotlin and java
I tried to summarize the basic grammar of Ruby briefly
I tried to express the result of before and after of Date class with a number line
I tried to build the environment of PlantUML Server with Docker
I tried to summarize the methods of Java String and StringBuilder
I want to change the value of Attribute in Selenium of Ruby
I tried to make a parent class of a value object in Ruby
I tried to summarize the key points of gRPC design and development
[Ruby] I tried to diet the if statement code with the ternary operator
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I tried to make full use of the CPU core in Ruby
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I tried to compare the infrastructure technology of engineers these days with cooking.
I tried to get the distance from the address string to the nearest station with ruby
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I checked the number of taxis with Ruby
I want to get the value in Ruby
Since the argument of link_to is nil (null) and an unexpected link was generated, I tried to verify it
I tried to check the operation of http request (Put) with Talented API Tester
[ruby] How to assign a value to a hash by referring to the value and key of another hash
I tried to investigate the mechanism of Emscripten by using it with the Sudoku solver
I tried to read and output CSV with Outsystems
I tried to summarize the state transition of docker
I tried to reduce the capacity of Spring Boot
I tried to solve the Ruby karaoke machine problem (there is an example of the answer)
I tried to solve the Ruby bonus drink problem (there is an example of the answer)
[For Swift beginners] I tried to summarize the messy layout cycle of ViewController and View
I tried to increase the processing speed with spiritual engineering
[Swift] I tried to implement the function of the vending machine
I tried JAX-RS and made a note of the procedure
I tried to automate LibreOffice Calc with Ruby + PyCall.rb (Ubuntu 18.04)
I tried to build the environment of WSL2 + Docker + VSCode
[Ruby] I want to reverse the order of the hash table
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
How to deal with different versions of rbenv and Ruby
I tried to solve the Ruby bingo card creation problem (there is an example of the answer)
[Spring Boot] I want to add my own property file and get the value with env.getProperty ().
I tried to take a look at the flow of Android development environment construction with Android Studio