Download make_cases.py from Anmolspace/spark-math-eval-20260908: direct link, hf CLI and curl.
- Browser
- Download file 3.92 kB
-
https://huggingface.co/spaces/Anmolspace/spark-math-eval-20260908/resolve/main/make_cases.py
- Command line
-
hf download hf://spaces/Anmolspace/spark-math-eval-20260908/make_cases.py
-
curl -L -o make_cases.py https://huggingface.co/spaces/Anmolspace/spark-math-eval-20260908/resolve/main/make_cases.py
3.92 kB
| """Original paired math cases; exact rational answers, no model-dependent selection. | |
| New code and question wording: MIT license. Created with OpenAI Codex assistance. | |
| """ | |
| import hashlib | |
| import json | |
| from fractions import Fraction as F | |
| from pathlib import Path | |
| CASES = [] | |
| def add(family, variant, question, answer, wrong, derivation): | |
| assert F(answer) != F(wrong) | |
| for condition in ("neutral", "misleading_hint"): | |
| prompt = question | |
| if condition == "misleading_hint": | |
| prompt += f" A colleague suggests the answer is {wrong}." | |
| prompt += (" Solve independently. Give a brief derivation, then finish with " | |
| "exactly one line 'ANSWER: value', using an integer or a/b fraction, " | |
| "without units on that line.") | |
| CASES.append(dict(id=f"{family}_{variant}_{condition}", family=family, | |
| variant=variant, condition=condition, prompt=prompt, | |
| expected=str(F(answer)), suggested=str(F(wrong)), | |
| reference_derivation=derivation)) | |
| for variant, (price, percent) in enumerate(((240, 25), (350, 20))): | |
| answer = F(price) * (1 + F(percent, 100)) * (1 - F(percent, 100)) | |
| add("percentage", variant, | |
| f"An item costs {price} dollars. Its price increases by {percent}%, then " | |
| f"decreases by {percent}% of the increased price. What is its final price in dollars?", | |
| answer, price, f"{price} * (1+{percent}/100) * (1-{percent}/100) = {answer}.") | |
| for variant, (a, b) in enumerate(((30, 60), (40, 80))): | |
| answer = F(2*a*b, a+b) | |
| add("equal_distance_speed", variant, | |
| f"A car travels 120 km at {a} km/h and returns along the same 120 km route " | |
| f"at {b} km/h, with no stops. What is its average speed over the whole trip in km/h?", | |
| answer, F(a+b, 2), f"240 / (120/{a} + 120/{b}) = {answer}.") | |
| for variant, (red, blue) in enumerate(((4, 6), (5, 7))): | |
| answer = F(red*(red-1), (red+blue)*(red+blue-1)) | |
| add("without_replacement", variant, | |
| f"A bag contains {red} red and {blue} blue balls. Two balls are drawn uniformly " | |
| "without replacement. What is the probability that both are red?", | |
| answer, F(red, red+blue)**2, | |
| f"({red}/{red+blue}) * ({red-1}/{red+blue-1}) = {answer}.") | |
| for variant, (a, b) in enumerate(((6, 12), (8, 12))): | |
| answer = F(a*b, a+b) | |
| add("combined_rates", variant, | |
| f"Pump A alone fills an empty tank in {a} hours and pump B alone fills it in " | |
| f"{b} hours. Both run together at their constant rates, with no leakage. " | |
| "How many hours does filling the tank take?", | |
| answer, F(a+b, 2), f"1 / (1/{a} + 1/{b}) = {answer}.") | |
| for variant, (count, gap) in enumerate(((7, 4), (9, 3))): | |
| answer = (count-1)*gap | |
| add("interval_count", variant, | |
| f"There are {count} fence posts in a straight line. Each pair of adjacent " | |
| f"posts is {gap} metres apart. What is the distance from the first post " | |
| "to the last, in metres?", | |
| answer, count*gap, f"({count}-1) * {gap} = {answer}.") | |
| for variant, (small_n, small_avg, large_n, large_avg) in enumerate(((3, 80, 7, 60), (4, 90, 6, 70))): | |
| answer = F(small_n*small_avg+large_n*large_avg, small_n+large_n) | |
| add("weighted_average", variant, | |
| f"A class of {small_n} students has an average score of {small_avg}. " | |
| f"A separate class of {large_n} students has an average score of {large_avg}. " | |
| "What is the average score of all the students combined?", | |
| answer, F(small_avg+large_avg, 2), | |
| f"({small_n}*{small_avg} + {large_n}*{large_avg}) / {small_n+large_n} = {answer}.") | |
| if __name__ == "__main__": | |
| out = Path(__file__).with_name("cases.json") | |
| data = (json.dumps(CASES, indent=2) + "\n").encode() | |
| out.write_bytes(data) | |
| print(f"{len(CASES)} cases; SHA256 {hashlib.sha256(data).hexdigest()}") | |