Create solver_work_rate.py
Browse files- solver_work_rate.py +42 -0
solver_work_rate.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
from typing import Optional
|
| 5 |
+
|
| 6 |
+
from models import SolverResult
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def solve_work_rate(text: str) -> Optional[SolverResult]:
|
| 10 |
+
|
| 11 |
+
lower = text.lower()
|
| 12 |
+
|
| 13 |
+
if "together" not in lower and "work together" not in lower:
|
| 14 |
+
return None
|
| 15 |
+
|
| 16 |
+
times = [float(x) for x in re.findall(r"\d+(?:\.\d+)?", lower)]
|
| 17 |
+
|
| 18 |
+
if len(times) < 2:
|
| 19 |
+
return None
|
| 20 |
+
|
| 21 |
+
t1 = times[0]
|
| 22 |
+
t2 = times[1]
|
| 23 |
+
|
| 24 |
+
rate = (1 / t1) + (1 / t2)
|
| 25 |
+
|
| 26 |
+
if rate == 0:
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
+
total_time = 1 / rate
|
| 30 |
+
|
| 31 |
+
return SolverResult(
|
| 32 |
+
domain="quant",
|
| 33 |
+
solved=True,
|
| 34 |
+
topic="work_rate",
|
| 35 |
+
answer_value=f"{total_time:g}",
|
| 36 |
+
internal_answer=f"{total_time:g}",
|
| 37 |
+
steps=[
|
| 38 |
+
"Convert each time to a work rate.",
|
| 39 |
+
"Add the rates together.",
|
| 40 |
+
"Take the reciprocal to get the total time."
|
| 41 |
+
]
|
| 42 |
+
)
|