Extract the numerical answer from a math solution response using unified extraction. AIME problems expect integer answers between 0 and 999.
(response: str)
| 88 | raise ValueError(f"Unsupported year: {year}. Only 2024 and 2025 are supported.") |
| 89 | |
| 90 | def extract_answer(response: str) -> Optional[int]: |
| 91 | """ |
| 92 | Extract the numerical answer from a math solution response using unified extraction. |
| 93 | AIME problems expect integer answers between 0 and 999. |
| 94 | """ |
| 95 | if not response: |
| 96 | return None |
| 97 | |
| 98 | # Use unified answer extraction with AIME problem context |
| 99 | extracted_answer = unified_extract_answer( |
| 100 | response, |
| 101 | problem_type="aime", |
| 102 | problem_id=None |
| 103 | ) |
| 104 | |
| 105 | if extracted_answer is None: |
| 106 | return None |
| 107 | |
| 108 | # Math-verify returns a list of all possible matches |
| 109 | # Check if extracted_answer is a list and find first valid integer |
| 110 | if isinstance(extracted_answer, list): |
| 111 | for item in extracted_answer: |
| 112 | if isinstance(item, (int, float)): |
| 113 | answer = int(item) |
| 114 | if 0 <= answer <= 999: |
| 115 | return answer |
| 116 | elif isinstance(item, str) and item.isdigit(): |
| 117 | answer = int(item) |
| 118 | if 0 <= answer <= 999: |
| 119 | return answer |
| 120 | return None |
| 121 | |
| 122 | # Convert to integer if needed - AIME answers are always integers |
| 123 | if isinstance(extracted_answer, (int, float)): |
| 124 | answer = int(extracted_answer) |
| 125 | # AIME answers are typically 0-999 |
| 126 | if 0 <= answer <= 999: |
| 127 | return answer |
| 128 | elif isinstance(extracted_answer, str) and extracted_answer.isdigit(): |
| 129 | answer = int(extracted_answer) |
| 130 | if 0 <= answer <= 999: |
| 131 | return answer |
| 132 | |
| 133 | return None |
| 134 | |
| 135 | def analyze_thinking(response: str) -> Dict: |
| 136 | """ |
no outgoing calls
no test coverage detected