from datetime import datetime, timedelta from typing import Tuple def calculate_sm2(q: int, repetitions: int, ease_factor: float, previous_interval: int) -> Tuple[int, float]: """ Implements the standard SuperMemo-2 (SM-2) algorithm. q: quality of the response (0-5) 5: perfect response 4: correct response after a hesitation 3: correct response caught with serious difficulty 2: incorrect response; where the correct one seemed easy to recall 1: incorrect response; the correct one remembered 0: complete blackout """ if q < 3: # If the answer was incorrect, reset repetitions and schedule for immediate review (1 day) return 1, ease_factor # Calculate new Easiness Factor new_ef = ease_factor + (0.1 - (5 - q) * (0.08 + (5 - q) * 0.02)) if new_ef < 1.3: new_ef = 1.3 # Calculate next interval (in days) if repetitions == 0: new_interval = 1 elif repetitions == 1: new_interval = 3 # Calibrated for intense JEE/NEET daily sprint cycles elif repetitions == 2: new_interval = 7 else: new_interval = round(previous_interval * new_ef) return new_interval, new_ef