"""Генератор задач: последовательности событий""" 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'