The math of some entrance exam question is awkward to think about, so I left it to python after all

Introduction

I was told to solve the mathematical probability of some entrance exam problem, and I didn't want to think about it, so I left it to python for a moment.

problem

There are 20 cards with integers from 1 to 20 written on them. Find the probability that the sum of the numbers on the 17 cards taken out at the same time will be a multiple of 3.

Solution

If you try to solve it by hand, think about the combination, and it's okay if 3 cards become 3 swords ...

code

I wrote it in python. It's so short that it doesn't matter what the processing speed is, so I use for statements all the time.

import numpy as np
import random

calculuse = []
result = []
for i in range(1, 20):
    for k in range (i+1, 21):
        for l in range(k+1, 21):
            a = i+k+l
            print('(i, k, l) =',i,(','),k,(','),l,('sum='),i+k+l) 
            array = a
            calculuse.append(array)
            if a%3 == 0:
                print('true')
            else:
                print('false')
            arr = [a, a%3==0]
            if a%3 ==0:
               result.append(arr)
print(len(result)) 
print(len(calculuse)) 

That's it!

(i, k, l) = 1 , 2 , 3 sum= 6
true
(i, k, l) = 1 , 2 , 4 sum= 7
false
(i, k, l) = 1 , 2 , 5 sum= 8
false
(i, k, l) = 1 , 2 , 6 sum= 9
true
(i, k, l) = 1 , 2 , 7 sum= 10
false
(i, k, l) = 1 , 2 , 8 sum= 11
false
(i, k, l) = 1 , 2 , 9 sum= 12
true
(i, k, l) = 1 , 2 , 10 sum= 13
false
(i, k, l) = 1 , 2 , 11 sum= 14
false
(i, k, l) = 1 , 2 , 12 sum= 15
true
(i, k, l) = 1 , 2 , 13 sum= 16
false
(i, k, l) = 1 , 2 , 14 sum= 17
false
(i, k, l) = 1 , 2 , 15 sum= 18
true
(i, k, l) = 1 , 2 , 16 sum= 19
false
(i, k, l) = 1 , 2 , 17 sum= 20
false
(i, k, l) = 1 , 2 , 18 sum= 21
:
:
:
:
384
1140

So the answer is 384/1140 Will be! I was told that I would like to know my thoughts when I gave it to a friend.

Recommended Posts

The math of some entrance exam question is awkward to think about, so I left it to python after all
I tried to solve the first question of the University of Tokyo 2019 math entrance exam with python sympy
What I thought about in the entrance exam question of "Bayesian statistics from the basics"
After all it is wrong to cat with python subprocess.
I made a function to crop the image of python openCV, so please use it.
[Super basics of Python] I learned the basics of the basics, so I summarized it briefly.
My friend seems to do python, so think about the problem ~ fizzbuzz ~
The Python project template I think of.
I wanted to use the find module of Ansible2, but it took some time, so make a note
I tried to verify the Big Bang theorem [Is it about to come back?]
I didn't understand the Resize of TensorFlow so I tried to summarize it visually.
I touched some of the new features of Python 3.8 ①
About the usefulness of the Python Counter class-You don't have to count it yourself anymore-
I used Python to find out about the role choices of the 51 "Yachts" in the world.
The command to generate RFC bibtex is convenient, so deliver it to all X students
I thought about why Python self is necessary with the feeling of a Python interpreter
[Python] About creating a tool to display all the pages of the website registered in the JSON file & where it got caught
Since memory_profiler of python is heavy, I measured it
I tried to summarize the string operations of Python
The sound of tic disorder at work is ... I managed to do it with the code
(Maybe) This is all you need to pass the Python 3 Engineer Certification Data Analysis Exam
[Confrontation! Human power vs Python] After all, which is faster, solving the mathematics of the center test with Python or solving it by yourself?
[Python] The status of each prefecture of the new coronavirus is only published in PDF, but I tried to scrape it without downloading it.
I tried to find the entropy of the image with python
Which is the most popular python visualization tool after all?
I want to initialize if the value is empty (python)
[Python] I tried to visualize the follow relationship of Twitter
I want to know the features of Python and pip
After all, the story of returning from Linux to Windows
I want to know the legend of the IT technology world
[Student version] I didn't have much information about the installation procedure of CPLEX, so I wrote it.
I want to clear up the question of the "__init__" method and the "self" argument of a Python class.