File size: 1,957 Bytes
d2213a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Генератор задач: последовательности событий"""

from core.base_generator import BaseTaskGenerator
from models.task import Task
from config import COMPLEXITY_CONFIG
import random


class SequencesGenerator(BaseTaskGenerator):
    """Генератор задач про последовательности"""

    def generate(self) -> Task:
        """Генерация задачи"""
        config = COMPLEXITY_CONFIG[self.complexity]

        attempts = random.choice([4, 5])
        hit_prob = random.choice([0.8, 0.9])

        shooters = ['биатлонист', 'стрелок', 'спортсмен']
        shooter = random.choice(shooters)

        question = f"{shooter.capitalize()} {attempts} раз стреляет по мишеням. Вероятность попадания в мишень при одном выстреле равна {hit_prob}. Найдите вероятность того, что {shooter} первые {attempts - 1} раза попал в мишени, а последний раз промахнулся."

        answer = round((hit_prob ** (attempts - 1)) * (1 - hit_prob), 4)

        steps = [
            f"1. Вероятность попадания {attempts - 1} раз подряд: {hit_prob}^{attempts - 1} = {hit_prob ** (attempts - 1):.4f}",
            f"2. Вероятность промаха: 1 - {hit_prob} = {1 - hit_prob:.2f}",
            f"3. Общая вероятность (независимые события): {hit_prob ** (attempts - 1):.4f} × {1 - hit_prob:.2f} = {answer}"
        ]

        return Task(
            type='sequences',
            question=question,
            answer=answer,
            answer_fraction=f"{answer:.4f}",
            solution=f"Вероятность = {answer}",
            steps=steps,
            complexity=self.complexity
        )

    def get_type(self) -> str:
        return 'sequences'