M
M
Maga Izdaga2022-04-13 11:41:49
Probability theory
Maga Izdaga, 2022-04-13 11:41:49

How is such an answer obtained?

62568b7b85701814018891.png
there is such a problem, the result of the answer of which is 0.48, based on the explanation of the answer by the author of the problem. I found this to be too high for such a small sample, so I immediately ran to simulate it in python and represent this event in lines of code and play it many times. Here is the code, if anyone is interested, perhaps it is unclean, I will not argue.

from random import randint

p_copy = [] #это копия списка мест для присвоения далее
for i in range(26):
    p_copy.append(i)
c = 0 #это счётчик попаданий 7,4 в общую выборку, 7 и 4 тут предстаёт как два друга
v = 10**5 #просто указатель количества повторений события
for s in range(v):
    p = p_copy.copy()  #список мест
    plc = [] #список групп из двух человек в виде множества из двух значений (n, n)
    while p != []:
        i = randint(0, len(p)-1) #случайное число, отбирающее конкретного человека из всех
        fst = p[i]
        del p[i]
        n = randint(0, len(p)-1)
        scnd = p[n]
        del p[n]
        plc.append((fst, scnd)) #добавление в список группы группу из случайно отобранных из общего количества людей
    if (7,4) in plc:
        c+=1

print(c/v) #вычисление частоты выпадение того самого события

The bottom line is that I sort of double-checked the correctness of a random sample, but after working through the code on many repetitions, up to a million and repeatedly, I always got a value approximately equal to 0.2. Here I have two problems, firstly, my answer turned out to be 0.4, and secondly, I don’t fully understand whether I made a mistake in the code or the answer to the problem is incorrect, I would like to hear your answer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2022-04-13
@MagaVTanke

Event A - Andrey got into group 1
Event B - Andrey got into group 2
Event С - Sergey got into group 1
Event D - Sergey got into group 2
P = P(A) * P(C|A) + P(B) * P(D|B) = 1/2 * 12/25 + 1/2 * 12/25 = 12/25 = 0.48

const shuffle = (arr) => {
  for (let i = 0; i < arr.length - 1; i += 1) {
    const j = Math.floor(Math.random() * (i + 1));
    [arr[i], arr[j]] = [arr[j], arr[i]];
  }
}

const test = () => {
  let p = 0;
  for (let i = 0; i < 100000; i += 1) {
    const arr = Array(26).fill().map((el, idx) => idx % 2);
    shuffle(arr);
    p += arr[0] === arr[1] ? 1 : 0;
  }
  return p / 100000;
}

console.log(test()); // 0.47915
console.log(test()); // 0.48109
console.log(test()); // 0.47811
console.log(test()); // 0.47881
console.log(test()); // 0.48162
console.log(test()); // 0.48174

M
Maga Izdaga, 2022-04-13
@MagaVTanke

hell, I realized that I misunderstood the task, hammer it. Consider the comment above as a solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question