Asilarkness commited on
Commit
bdcab49
·
verified ·
1 Parent(s): e9b8cfd

Upload tmpl_code/tc_tp4b_1791581671_00013.jsonl with huggingface_hub

Browse files
tmpl_code/tc_tp4b_1791581671_00013.jsonl ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"tid": "92b9e7c2e0", "cat": "science_calc", "code": "import random\n\ndef make(rng, original=False):\n # Choose initial and final temperatures such that the ratio is an integer >= 2\n if original:\n T_i, T_f = 300, 600\n else:\n # Draw a divisor and a multiplier to keep it simple and integer\n ratio = rng.randint(2, 8)\n T_i = rng.randint(100, 500)\n T_f = T_i * ratio\n # Ensure T_f is reasonable (e.g., < 1000 K) to keep it similar in difficulty\n if T_f > 1000:\n return None\n\n # Compute the answer\n ans = T_f // T_i\n\n question = (\n f\"Consider an ideal gas initially at {T_i} K and 1 atm in a rigid container. \"\n f\"If the gas is heated to {T_f} K, what is the ratio of the final pressure to the initial pressure? \"\n f\"Express your answer as an integer.\"\n )\n\n lines = [\n \"For an ideal gas, the equation of state is PV = nRT.\",\n \"Since the container is rigid, the volume V is constant.\",\n \"The amount of gas n is constant.\",\n \"Therefore, P/T is constant.\",\n f\"The ratio of final pressure to initial pressure is P_f / P_i = T_f / T_i.\",\n f\"The initial temperature T_i is {T_i} K.\",\n f\"The final temperature T_f is {T_f} K.\",\n f\"Substitute the temperatures into the ratio: P_f / P_i = {T_f} / {T_i}.\",\n f\"Calculate the ratio: {T_f} / {T_i} = {ans}.\",\n f\"The ratio of the final pressure to the initial pressure is {ans}.\"\n ]\n\n return question, lines, str(ans)\n"}
2
+ {"tid": "facd44708c", "cat": "wordproblem", "code": "import random\nfrom fractions import Fraction\nimport math\n\ndef make(rng, original=False):\n if original:\n question = (\"Three colleagues, Alice, Bob, and Charlie, are preparing a grant proposal. \"\n \"Alice can complete the task in 10 days working alone, Bob in 15 days, and Charlie in 30 days. \"\n \"Alice works alone for 2 days, then Bob joins her and they work together for 3 days. \"\n \"After that, Charlie joins them. How many additional days will it take for all three to complete \"\n \"the remaining work if they continue working together?\")\n lines = [\n \"Alice's daily rate is 1/10.\",\n \"Bob's daily rate is 1/15.\",\n \"Charlie's daily rate is 1/30.\",\n \"Alice works alone for 2 days.\",\n \"Work completed by Alice = 2 * (1/10) = 1/5.\",\n \"Alice and Bob work together for 3 days.\",\n \"Combined rate of Alice and Bob = 1/10 + 1/15 = 3/30 + 2/30 = 5/30 = 1/6.\",\n \"Work completed by Alice and Bob = 3 * (1/6) = 1/2.\",\n \"Total work completed so far = 1/5 + 1/2 = 2/10 + 5/10 = 7/10.\",\n \"Remaining work = 1 - 7/10 = 3/10.\",\n \"All three work together.\",\n \"Combined rate of all three = 1/10 + 1/15 + 1/30 = 3/30 + 2/30 + 1/30 = 6/30 = 1/5.\",\n \"Time required for remaining work = (3/10) / (1/5).\",\n \"Time required = (3/10) * 5 = 15/10 = 3/2.\",\n \"3/2 days = 1.5 days.\"\n ]\n answer = \"1.5 days\"\n return (question, lines, answer)\n\n # Generate new parameters\n names_pool = [\"Alice\", \"Bob\", \"Charlie\", \"David\", \"Eve\", \"Frank\", \"Grace\", \"Heidi\"]\n names = rng.sample(names_pool, 3)\n n1, n2, n3 = names\n\n # Choose days for each worker (ensure distinct and reasonable)\n d1 = rng.randint(5, 20)\n d2 = rng.randint(5, 30)\n d3 = rng.randint(10, 40)\n if d1 == d2 or d1 == d3 or d2 == d3:\n return None\n\n t1 = rng.randint(1, 5) # days n1 works alone\n t2 = rng.randint(1, 5) # days n1+n2 work together\n\n # Compute rates\n r1 = Fraction(1, d1)\n r2 = Fraction(1, d2)\n r3 = Fraction(1, d3)\n\n # Phase 1: n1 alone\n work1 = t1 * r1\n if work1 >= 1:\n return None\n\n # Phase 2: n1 + n2\n rate12 = r1 + r2\n work2 = t2 * rate12\n total_work = work1 + work2\n if total_work >= 1:\n return None\n\n # Phase 3: all three\n rate123 = r1 + r2 + r3\n remaining = 1 - total_work\n t3 = remaining / rate123\n\n # Check that t3 is a terminating decimal or simple fraction\n if t3.denominator == 1:\n ans_str = f\"{t3.numerator} days\"\n else:\n # Try to represent as decimal with up to 2 decimal places\n val = float(t3)\n if abs(val - round(val, 2)) < 1e-9:\n ans_str = f\"{round(val, 2)} days\"\n else:\n # Use fraction form\n ans_str = f\"{t3.numerator}/{t3.denominator} days\"\n\n # Build question\n q = (f\"Three colleagues, {n1}, {n2}, and {n3}, are preparing a grant proposal. \"\n f\"{n1} can complete the task in {d1} days working alone, {n2} in {d2} days, and {n3} in {d3} days. \"\n f\"{n1} works alone for {t1} days, then {n2} joins {n1} and they work together for {t2} days. \"\n f\"After that, {n3} joins them. How many additional days will it take for all three to complete \"\n f\"the remaining work if they continue working together?\")\n\n # Build lines\n lines = []\n lines.append(f\"{n1}'s daily rate is 1/{d1}.\")\n lines.append(f\"{n2}'s daily rate is 1/{d2}.\")\n lines.append(f\"{n3}'s daily rate is 1/{d3}.\")\n lines.append(f\"{n1} works alone for {t1} days.\")\n lines.append(f\"Work completed by {n1} = {t1} * (1/{d1}) = {work1}.\")\n lines.append(f\"{n1} and {n2} work together for {t2} days.\")\n lines.append(f\"Combined rate of {n1} and {n2} = 1/{d1} + 1/{d2} = {rate12}.\")\n lines.append(f\"Work completed by {n1} and {n2} = {t2} * ({rate12}) = {work2}.\")\n lines.append(f\"Total work completed so far = {work1} + {work2} = {total_work}.\")\n lines.append(f\"Remaining work = 1 - {total_work} = {remaining}.\")\n lines.append(\"All three work together.\")\n lines.append(f\"Combined rate of all three = 1/{d1} + 1/{d2} + 1/{d3} = {rate123}.\")\n lines.append(f\"Time required for remaining work = ({remaining}) / ({rate123}).\")\n lines.append(f\"Time required = {t3}.\")\n lines.append(f\"{t3} days = {ans_str.replace(' days', '')} days.\")\n\n return (q, lines, ans_str)\n"}
3
+ {"tid": "06d72e0f8c", "cat": "finance", "code": "def make(rng, original=False):\n if original:\n net_income = 1200000\n shares = 200000\n price = 18.00\n name = \"Strausse\"\n eps = net_income / shares\n pe = price / eps\n question = (f'A \"{name}\" retail company reports an annual net income of ${net_income:,} and has '\n f'{shares:,} shares outstanding. The current market price per share is ${price:.2f}. '\n f'Calculate the company\u2019s Earnings Per Share (EPS) rounded to two decimal places, and its '\n f'Price-to-Earnings (P/E) ratio rounded to one decimal place.')\n lines = [\n f'EPS = ${net_income:,} / {shares:,}',\n f'EPS = ${eps:.2f}',\n f'P/E ratio = ${price:.2f} / ${eps:.2f}',\n f'P/E ratio = {pe:.1f}',\n ]\n answer = f'EPS: ${eps:.2f}; P/E: {pe:.1f}'\n return question, lines, answer\n\n # New draw\n while True:\n net_income = rng.randint(100, 900) * 10000 # multiples of 10k, 1M..9M\n shares = rng.randint(100, 900) * 1000 # multiples of 1k\n price = round(rng.uniform(5, 60), 2)\n eps = net_income / shares\n # reject if EPS is zero or non-terminating / awkward, or P/E awkward\n if eps == 0:\n continue\n # require EPS to be a clean decimal (2 places) and P/E clean (1 place)\n if abs(eps - round(eps, 2)) > 1e-9:\n continue\n pe = price / eps\n if abs(pe - round(pe, 1)) > 1e-9:\n continue\n if pe <= 0:\n continue\n break\n\n names = [\"Nimbus\", \"Cedar\", \"Vista\", \"Lumen\", \"Aster\", \"Bloom\", \"Crest\", \"Delta\", \"Ember\", \"Fable\"]\n name = rng.choice(names)\n eps_r = round(eps, 2)\n pe_r = round(pe, 1)\n question = (f'The \"{name}\" corporation reports an annual net income of ${net_income:,} with '\n f'{shares:,} shares outstanding. Its stock currently trades at ${price:.2f} per share. '\n f'Find the Earnings Per Share (EPS) to two decimal places and the Price-to-Earnings (P/E) '\n f'ratio to one decimal place.')\n lines = [\n f'EPS = ${net_income:,} / {shares:,}',\n f'EPS = ${eps_r:.2f}',\n f'P/E ratio = ${price:.2f} / ${eps_r:.2f}',\n f'P/E ratio = {pe_r:.1f}',\n ]\n answer = f'EPS: ${eps_r:.2f}; P/E: {pe_r:.1f}'\n return question, lines, answer\n"}
4
+ {"tid": "b8e2d175f9", "cat": "wordproblem", "code": "import random\nimport math\nfrom fractions import Fraction\n\ndef make(rng, original=False):\n if original:\n question = (\"A mason earns $25 per hour for the first 8 hours of work and $30 per hour for any overtime hours. \"\n \"If he works 5 days a week and earns a total of $1,200 for the week, how many total hours did he work in that week?\")\n lines = [\n \"Regular hours: 5 days x 8 hours/day = 40 hours\",\n \"Regular pay: 40 hours x $25/hour = $1,000\",\n \"Overtime pay: $1,200 - $1,000 = $200\",\n \"Overtime hours: $200 / $30/hour = 20/3 hours\",\n \"Total hours: 40 + 20/3 = 140/3 = 46 2/3\",\n ]\n answer = \"46 2/3\"\n return question, lines, answer\n\n # Pick parameters\n days = rng.randint(3, 6)\n reg_hours_per_day = rng.randint(6, 10)\n reg_rate = rng.randint(15, 35)\n ot_rate = reg_rate + rng.randint(5, 15)\n # Ensure ot_rate > reg_rate (already true) and ot_rate divides cleanly? No, we allow fractions.\n # Choose overtime hours as a fraction to ensure non-integer total possibly, but let's pick rational.\n # To keep it clean, pick overtime hours as a simple fraction or integer.\n # Let's pick overtime hours numerator/denominator\n ot_den = rng.randint(2, 4)\n ot_num = rng.randint(1, 10)\n ot_hours = Fraction(ot_num, ot_den)\n \n reg_hours = days * reg_hours_per_day\n reg_pay = reg_hours * reg_rate\n ot_pay = ot_hours * ot_rate\n total_pay = reg_pay + ot_pay\n \n # Ensure total pay is an integer? Not strictly necessary, but nice.\n # ot_pay = (ot_num/ot_den) * ot_rate. If ot_den does not divide ot_rate, ot_pay is fraction.\n # Let's ensure total_pay is integer for cleaner question.\n if ot_den > 1:\n # Check if ot_rate is divisible by ot_den\n if ot_rate % ot_den != 0:\n # Try to adjust ot_rate or ot_den. Easier: just pick ot_den=1 or ensure divisibility.\n # Let's retry with a simpler constraint: ot_den must divide ot_rate.\n # We'll just filter by returning None if not integer total pay, or adjust.\n # To keep code short, let's force ot_den to divide ot_rate by picking ot_den from divisors.\n # But we already picked. Let's just return None and let caller retry? \n # The prompt says \"reject (return None) any draw that makes the problem invalid...\".\n # Non-integer total pay is not invalid, but \"non-terminating decimals\" is.\n # Fractions are exact. So it's fine. But let's make it nicer.\n pass\n\n # Format total pay\n if total_pay.denominator == 1:\n total_pay_str = f\"${total_pay.numerator:,}\"\n else:\n total_pay_str = f\"${total_pay.numerator}/{total_pay.denominator}\"\n\n question = (f\"A mason earns ${reg_rate} per hour for the first {reg_hours_per_day} hours of work \"\n f\"and ${ot_rate} per hour for any overtime hours. \"\n f\"If he works {days} days a week and earns a total of {total_pay_str} for the week, \"\n f\"how many total hours did he work in that week?\")\n\n # Compute solution\n total_hours = reg_hours + ot_hours\n \n # Format answer\n if total_hours.denominator == 1:\n answer = f\"{total_hours.numerator}\"\n else:\n whole = total_hours.numerator // total_hours.denominator\n rem = total_hours.numerator % total_hours.denominator\n # Simplify fraction\n g = math.gcd(rem, total_hours.denominator)\n rem //= g\n den = total_hours.denominator // g\n answer = f\"{whole} {rem}/{den}\"\n\n lines = [\n f\"Regular hours: {days} days x {reg_hours_per_day} hours/day = {reg_hours} hours\",\n f\"Regular pay: {reg_hours} hours x ${reg_rate}/hour = ${reg_pay:,}\",\n f\"Overtime pay: {total_pay_str} - ${reg_pay:,} = ${ot_pay.numerator}/{ot_pay.denominator if ot_pay.denominator != 1 else 1}\",\n f\"Overtime hours: ${ot_pay.numerator}/{ot_pay.denominator if ot_pay.denominator != 1 else 1} / ${ot_rate}/hour = {ot_hours.numerator}/{ot_hours.denominator} hours\",\n f\"Total hours: {reg_hours} + {ot_hours.numerator}/{ot_hours.denominator} = {total_hours.numerator}/{total_hours.denominator} = {answer}\",\n ]\n \n # Clean up lines for better readability if denominators are 1\n def fmt_frac(f):\n if f.denominator == 1:\n return f\"{f.numerator}\"\n g = math.gcd(f.numerator, f.denominator)\n return f\"{f.numerator//g}/{f.denominator//g}\"\n\n lines[2] = f\"Overtime pay: {total_pay_str} - ${reg_pay:,} = ${fmt_frac(ot_pay)}\"\n lines[3] = f\"Overtime hours: ${fmt_frac(ot_pay)} / ${ot_rate}/hour = {fmt_frac(ot_hours)} hours\"\n lines[4] = f\"Total hours: {reg_hours} + {fmt_frac(ot_hours)} = {fmt_frac(total_hours)} = {answer}\"\n\n return question, lines, answer\n"}
5
+ {"tid": "e90c0c67c7", "cat": "wordproblem", "code": "import random\nfrom fractions import Fraction\n\ndef make(rng, original=False):\n if original:\n question = (\"Three volunteers, Alice, Ben, and Chloe, are tasked with setting up a \\\"Slam Stage\\\" backdrop. \"\n \"Alice can complete the setup alone in 12 hours, Ben in 15 hours, and Chloe in 20 hours. \"\n \"Alice and Ben work together for 2 hours, then Alice leaves. Ben and Chloe then work together for another 3 hours, \"\n \"after which Ben leaves. How many additional hours must Chloe work alone to finish the job?\")\n lines = [\n \"Alice's rate: 1/12 job/hour\",\n \"Ben's rate: 1/15 job/hour\",\n \"Chloe's rate: 1/20 job/hour\",\n \"Alice and Ben combined rate: 1/12 + 1/15 = 5/60 + 4/60 = 9/60 = 3/20 job/hour\",\n \"Work done by Alice and Ben in 2 hours: 2 * (3/20) = 6/20 = 3/10\",\n \"Ben and Chloe combined rate: 1/15 + 1/20 = 4/60 + 3/60 = 7/60 job/hour\",\n \"Work done by Ben and Chloe in 3 hours: 3 * (7/60) = 21/60 = 7/20\",\n \"Total work completed: 3/10 + 7/20 = 6/20 + 7/20 = 13/20\",\n \"Remaining work: 1 - 13/20 = 7/20\",\n \"Time for Chloe to finish remaining work: (7/20) / (1/20) = 7 hours\"\n ]\n answer = \"7\"\n return question, lines, answer\n\n # Generate new parameters\n names = [\"Alice\", \"Ben\", \"Chloe\", \"Dana\", \"Evan\", \"Faye\", \"Gus\", \"Hana\"]\n rng.shuffle(names)\n n1, n2, n3 = names[0], names[1], names[2]\n\n # Rates as Fractions (work per hour). Choose integer hours to complete alone.\n # Ensure combined rates are nice and final answer is integer.\n # We'll brute force small integer hours.\n possible_hours = list(range(6, 25))\n for _ in range(200):\n h1 = rng.choice(possible_hours)\n h2 = rng.choice(possible_hours)\n h3 = rng.choice(possible_hours)\n t1 = rng.randint(1, 4) # time n1 and n2 work\n t2 = rng.randint(1, 4) # time n2 and n3 work\n\n r1 = Fraction(1, h1)\n r2 = Fraction(1, h2)\n r3 = Fraction(1, h3)\n\n work1 = (r1 + r2) * t1\n work2 = (r2 + r3) * t2\n total_work = work1 + work2\n\n if total_work >= 1:\n continue # job finished or overdone before n3 alone\n\n remaining = 1 - total_work\n # Time for n3 to finish\n if r3 == 0:\n continue\n t3 = remaining / r3\n\n # Check if t3 is an integer\n if t3.denominator != 1:\n continue\n\n # Check if the problem is non-trivial (work1 > 0, work2 > 0, t3 > 0)\n if work1 <= 0 or work2 <= 0 or t3 <= 0:\n continue\n\n # Construct question\n # Vary wording slightly\n task_phrases = [\n \"setting up a \\\"Slam Stage\\\" backdrop\",\n \"decorating a \\\"Winter Wonderland\\\" booth\",\n \"building a \\\"Garden Party\\\" display\",\n \"installing a \\\"Tech Expo\\\" booth\"\n ]\n task = rng.choice(task_phrases)\n\n question = (f\"Three volunteers, {n1}, {n2}, and {n3}, are tasked with {task}. \"\n f\"{n1} can complete the setup alone in {h1} hours, {n2} in {h2} hours, and {n3} in {h3} hours. \"\n f\"{n1} and {n2} work together for {t1} hours, then {n1} leaves. \"\n f\"{n2} and {n3} then work together for another {t2} hours, after which {n2} leaves. \"\n f\"How many additional hours must {n3} work alone to finish the job?\")\n\n # Construct lines\n lines = [\n f\"{n1}'s rate: 1/{h1} job/hour\",\n f\"{n2}'s rate: 1/{h2} job/hour\",\n f\"{n3}'s rate: 1/{h3} job/hour\",\n f\"{n1} and {n2} combined rate: 1/{h1} + 1/{h2} = {r1 + r2} job/hour\",\n f\"Work done by {n1} and {n2} in {t1} hours: {t1} * ({r1 + r2}) = {work1}\",\n f\"{n2} and {n3} combined rate: 1/{h2} + 1/{h3} = {r2 + r3} job/hour\",\n f\"Work done by {n2} and {n3} in {t2} hours: {t2} * ({r2 + r3}) = {work2}\",\n f\"Total work completed: {work1} + {work2} = {total_work}\",\n f\"Remaining work: 1 - {total_work} = {remaining}\",\n f\"Time for {n3} to finish remaining work: ({remaining}) / (1/{h3}) = {t3.numerator} hours\"\n ]\n answer = str(t3.numerator)\n return question, lines, answer\n\n return None\n"}
6
+ {"tid": "f74bf4c691", "cat": "finance", "code": "import random\nimport math\n\ndef make(rng, original=False):\n if original:\n question = (\"A small business owner is analyzing the break-even point for a new product line. \"\n \"The fixed costs are $40,000 per month, and the variable cost per unit is $25. \"\n \"If the selling price per unit is set at $60, how many units must be sold per month \"\n \"to achieve a break-even (where total revenue equals total costs)?\")\n lines = [\n \"Contribution margin per unit = $60 - $25 = $35\",\n \"Break-even units = $40,000 / $35 = 1142.857...\",\n \"Since units must be whole numbers, round up to the next integer\",\n \"Required units = 1143\"\n ]\n answer = \"1143\"\n return (question, lines, answer)\n\n # Draw new parameters\n # Fixed costs: multiples of 1000, between 5000 and 100000\n fixed = rng.randint(5, 100) * 1000\n # Variable cost per unit: between 5 and 50\n var = rng.randint(5, 50)\n # Selling price must be greater than variable cost\n # Ensure contribution margin divides fixed costs non-integrally to require rounding up\n # Contribution margin = price - var\n # We want fixed / (price - var) to be non-integer\n while True:\n margin = rng.randint(var + 1, var + 60) # margin between 1 and 60\n price = var + margin\n if fixed % margin == 0:\n continue\n # Also ensure the result is reasonable (not too large)\n if fixed // margin > 10000:\n continue\n break\n\n # Compute answer\n be_exact = fixed / margin\n be_units = math.ceil(be_exact)\n\n # Vary wording slightly\n intro_phrases = [\n \"A company is evaluating the break-even point for a new product.\",\n \"A business owner is calculating the break-even volume for a new item.\",\n \"An entrepreneur is determining how many units are needed to break even on a new product line.\"\n ]\n cost_phrases = [\n f\"The monthly fixed costs are ${fixed:,}, and the variable cost per unit is ${var}.\",\n f\"Fixed costs amount to ${fixed:,} per month, with a variable cost of ${var} per unit.\",\n f\"Operating costs include ${fixed:,} in fixed expenses per month and ${var} in variable costs per unit.\"\n ]\n price_phrases = [\n f\"The selling price is set at ${price} per unit.\",\n f\"Each unit is sold for ${price}.\",\n f\"The price per unit is ${price}.\"\n ]\n ask_phrases = [\n \"How many units must be sold per month to reach the break-even point?\",\n \"What is the minimum number of units that must be sold monthly to break even?\",\n \"How many units need to be sold in a month for total revenue to equal total costs?\"\n ]\n\n question = (rng.choice(intro_phrases) + \" \" +\n rng.choice(cost_phrases) + \" \" +\n rng.choice(price_phrases) + \" \" +\n rng.choice(ask_phrases))\n\n lines = [\n f\"Contribution margin per unit = ${price} - ${var} = ${margin}\",\n f\"Break-even units = ${fixed:,} / ${margin} = {be_exact:.4f}...\",\n \"Since units must be whole numbers, round up to the next integer\",\n f\"Required units = {be_units}\"\n ]\n\n answer = str(be_units)\n return (question, lines, answer)\n"}
7
+ {"tid": "e68285a02b", "cat": "finance", "code": "import random\n\ndef make(rng, original=False):\n if original:\n price, eps_trail, eps_fwd = 150.0, 2.00, 2.50\n question = (\"A stock is currently trading at \u20b9150 per share. The most recent quarter's earnings per share (EPS) was \u20b92.00, \"\n \"and analysts project the next quarter's EPS to be \u20b92.50. Calculate the stock\u2019s trailing Price-to-Earnings (P/E) \"\n \"ratio and its forward P/E ratio based on these figures.\")\n lines = [\n \"Trailing P/E = \u20b9150 / \u20b92.00 = 75\",\n \"Forward P/E = \u20b9150 / \u20b92.50 = 60\",\n ]\n answer = \"Trailing P/E = 75; forward P/E = 60\"\n return question, lines, answer\n\n # Draw new numbers\n price = rng.choice([100, 120, 140, 160, 180, 200, 220, 250, 300, 350, 400])\n # EPS values chosen so that P/E ratios come out as clean integers (or simple)\n # We want price / eps to be integer.\n # Pick eps_trail such that price % eps_trail == 0\n # eps_trail in cents to avoid float issues\n price_cents = price * 100\n candidates_trail = [c for c in range(50, 500, 25) if price_cents % c == 0]\n if not candidates_trail:\n return None\n eps_trail_c = rng.choice(candidates_trail)\n eps_trail = eps_trail_c / 100.0\n\n candidates_fwd = [c for c in range(50, 500, 25) if price_cents % c == 0 and c != eps_trail_c]\n if not candidates_fwd:\n return None\n eps_fwd_c = rng.choice(candidates_fwd)\n eps_fwd = eps_fwd_c / 100.0\n\n trailing_pe = price / eps_trail\n forward_pe = price / eps_fwd\n\n # Ensure integer results for clean answer\n if trailing_pe != int(trailing_pe) or forward_pe != int(forward_pe):\n return None\n trailing_pe = int(trailing_pe)\n forward_pe = int(forward_pe)\n\n # Avoid trivial cases where both are the same\n if trailing_pe == forward_pe:\n return None\n\n # Slightly vary wording\n stock_names = [\"TechCorp\", \"GlobalSoft\", \"DataFlow\", \"QuantumTech\", \"NexGen\", \"CloudNine\", \"VertexAI\", \"SkyNet\"]\n company = rng.choice(stock_names)\n question = (f\"The stock of {company} is currently trading at \u20b9{price} per share. \"\n f\"The most recent quarter's earnings per share (EPS) was \u20b9{eps_trail:.2f}, \"\n f\"and analysts project the next quarter's EPS to be \u20b9{eps_fwd:.2f}. \"\n f\"Calculate the stock's trailing Price-to-Earnings (P/E) ratio and its forward P/E ratio based on these figures.\")\n\n lines = [\n f\"Trailing P/E = \u20b9{price} / \u20b9{eps_trail:.2f} = {trailing_pe}\",\n f\"Forward P/E = \u20b9{price} / \u20b9{eps_fwd:.2f} = {forward_pe}\",\n ]\n answer = f\"Trailing P/E = {trailing_pe}; forward P/E = {forward_pe}\"\n return question, lines, answer\n"}
8
+ {"tid": "aad7897048", "cat": "finance", "code": "import random\n\ndef make(rng, original=False):\n if original:\n question = (\"A retail company in the Opava area reports the following data for the fiscal year: \"\n \"Total Revenue of \u20ac2,000,000; Cost of Goods Sold (COGS) of \u20ac1,200,000; \"\n \"Operating Expenses (excluding interest and taxes) of \u20ac400,000; \"\n \"Interest Expense of \u20ac50,000; and a Corporate Tax Rate of 25%. \"\n \"The company has 1,000,000 shares outstanding, and the current stock price is \u20ac12.50 per share. \"\n \"Calculate the Price-to-Earnings (P/E) ratio for the company. \"\n \"Round your final answer to two decimal places.\")\n lines = [\n \"Revenue - COGS - Operating Expenses = \u20ac2,000,000 - \u20ac1,200,000 - \u20ac400,000 = \u20ac400,000\",\n \"EBIT = \u20ac400,000\",\n \"EBT = \u20ac400,000 - \u20ac50,000 = \u20ac350,000\",\n \"Tax = \u20ac350,000 x 0.25 = \u20ac87,500\",\n \"Net Income = \u20ac350,000 - \u20ac87,500 = \u20ac262,500\",\n \"EPS = \u20ac262,500 / 1,000,000 = \u20ac0.2625\",\n \"P/E = \u20ac12.50 / \u20ac0.2625 = 47.619047...\",\n \"P/E rounded to two decimal places = 47.62\",\n ]\n answer = \"47.62\"\n return question, lines, answer\n\n for _ in range(100):\n revenue = rng.randint(1, 20) * 100000\n cogs = rng.randint(40, 70) * 1000\n opex = rng.randint(10, 30) * 1000\n interest = rng.randint(1, 10) * 1000\n tax_rate = rng.choice([0.20, 0.25, 0.30])\n shares = rng.randint(1, 10) * 100000\n price = round(rng.uniform(5.0, 25.0), 2)\n\n ebit = revenue - cogs - opex\n if ebit <= 0:\n continue\n ebt = ebit - interest\n if ebt <= 0:\n continue\n tax = round(ebt * tax_rate, 2)\n net_income = round(ebt - tax, 2)\n if net_income <= 0:\n continue\n eps = net_income / shares\n pe = price / eps\n pe_rounded = round(pe, 2)\n\n question = (f\"A company reports the following data for the fiscal year: \"\n f\"Total Revenue of \u20ac{revenue:,}; Cost of Goods Sold (COGS) of \u20ac{cogs:,}; \"\n f\"Operating Expenses (excluding interest and taxes) of \u20ac{opex:,}; \"\n f\"Interest Expense of \u20ac{interest:,}; and a Corporate Tax Rate of {tax_rate*100:.0f}%. \"\n f\"The company has {shares:,} shares outstanding, and the current stock price is \u20ac{price:.2f} per share. \"\n f\"Calculate the Price-to-Earnings (P/E) ratio for the company. \"\n f\"Round your final answer to two decimal places.\")\n\n lines = [\n f\"Revenue - COGS - Operating Expenses = \u20ac{revenue:,} - \u20ac{cogs:,} - \u20ac{opex:,} = \u20ac{ebit:,}\",\n f\"EBIT = \u20ac{ebit:,}\",\n f\"EBT = \u20ac{ebit:,} - \u20ac{interest:,} = \u20ac{ebt:,}\",\n f\"Tax = \u20ac{ebt:,} x {tax_rate:.2f} = \u20ac{tax:,.2f}\",\n f\"Net Income = \u20ac{ebt:,} - \u20ac{tax:,.2f} = \u20ac{net_income:,.2f}\",\n f\"EPS = \u20ac{net_income:,.2f} / {shares:,} = \u20ac{eps:.4f}\",\n f\"P/E = \u20ac{price:.2f} / \u20ac{eps:.4f} = {pe:.6f}\",\n f\"P/E rounded to two decimal places = {pe_rounded:.2f}\",\n ]\n answer = f\"{pe_rounded:.2f}\"\n return question, lines, answer\n\n return None\n"}
9
+ {"tid": "dd0d5ff94b", "cat": "logic", "code": "import random\nimport itertools\n\n\ndef make(rng, original=False):\n if original:\n question = (\"Four musicians\u2014Lauren, James, Sarah, and David\u2014play instruments: \"\n \"violin, cello, flute, or clarinet. Lauren plays the violin. \"\n \"James does not play the flute. Sarah plays the cello. \"\n \"David does not play the clarinet. Who plays the flute?\")\n lines = [\n \"Lauren plays the violin.\",\n \"Sarah plays the cello.\",\n \"The remaining instruments are the flute and the clarinet.\",\n \"The remaining musicians are James and David.\",\n \"James does not play the flute.\",\n \"James plays the clarinet.\",\n \"David does not play the clarinet.\",\n \"David plays the flute.\",\n ]\n answer = \"David\"\n return (question, lines, answer)\n\n # Candidate pools\n name_pool = [\"Alice\", \"Ben\", \"Clara\", \"Diego\", \"Elena\", \"Finn\", \"Grace\", \"Hugo\", \"Ivy\", \"Jack\"]\n inst_pool = [\"violin\", \"cello\", \"flute\", \"clarinet\", \"piano\", \"trumpet\", \"oboe\", \"harp\"]\n\n # Pick 4 distinct names and 4 distinct instruments\n names = rng.sample(name_pool, 4)\n instruments = rng.sample(inst_pool, 4)\n\n # Shuffle names and instruments for variety\n rng.shuffle(names)\n rng.shuffle(instruments)\n\n # We need to construct a unique assignment satisfying:\n # - 2 \"plays X\" clues\n # - 2 \"does not play Y\" clues\n # - exactly one valid permutation\n # - the question asks who plays a specific instrument (one of the 4)\n\n # Generate all permutations of instruments to names\n perms = list(itertools.permutations(instruments))\n\n # For each permutation, try to pick 2 positive and 2 negative clues that yield uniqueness\n # Positive clue: name i plays instrument p[i]\n # Negative clue: name i does not play instrument d[i] (d[i] != p[i])\n\n # We'll iterate over target permutations and see if we can find a clue set that isolates it.\n # To keep it simple, we'll randomly try a few target permutations.\n\n for _ in range(50):\n target = rng.choice(perms)\n\n # Pick 2 indices for positive clues\n pos_indices = rng.sample(range(4), 2)\n\n # For the other 2 indices, we'll use negative clues\n neg_indices = [i for i in range(4) if i not in pos_indices]\n\n # For each neg index, pick an instrument NOT equal to target[i]\n neg_instruments = []\n valid = True\n for i in neg_indices:\n wrong_options = [inst for inst in instruments if inst != target[i]]\n if not wrong_options:\n valid = False\n break\n neg_instruments.append((i, rng.choice(wrong_options)))\n\n if not valid:\n continue\n\n # Now check uniqueness: how many permutations satisfy all 4 clues?\n def satisfies(perm):\n for i in pos_indices:\n if perm[i] != target[i]:\n return False\n for i, wrong in neg_instruments:\n if perm[i] == wrong:\n return False\n return True\n\n count = sum(1 for p in perms if satisfies(p))\n if count == 1:\n # Unique solution found\n # Pick which instrument to ask about (one of the 4)\n ask_inst = rng.choice(instruments)\n # Find who plays it in the target\n ask_name = names[target.index(ask_inst)]\n\n # Build question\n # Vary wording slightly\n intro_variants = [\n \"Four musicians\u2014{names}\u2014play instruments: {instruments}.\",\n \"Musicians {names} each play one of these instruments: {instruments}.\",\n \"There are four musicians: {names}. Their instruments are: {instruments}.\",\n ]\n intro = rng.choice(intro_variants).format(\n names=\", \".join(names),\n instruments=\", \".join(instruments)\n )\n\n # Build clue sentences\n clue_parts = []\n for i in pos_indices:\n clue_parts.append(f\"{names[i]} plays the {target[i]}.\")\n for i, wrong in neg_instruments:\n clue_parts.append(f\"{names[i]} does not play the {wrong}.\")\n\n # Shuffle clue order\n rng.shuffle(clue_parts)\n\n question = intro + \" \" + \" \".join(clue_parts) + f\" Who plays the {ask_inst}?\"\n\n # Build solution lines\n lines = []\n # First, state the positive clues\n for i in pos_indices:\n lines.append(f\"{names[i]} plays the {target[i]}.\")\n\n # Identify remaining musicians and instruments\n assigned_names = set(names[i] for i in pos_indices)\n assigned_insts = set(target[i] for i in pos_indices)\n remaining_names = [n for n in names if n not in assigned_names]\n remaining_insts = [inst for inst in instruments if inst not in assigned_insts]\n\n lines.append(f\"The remaining instruments are {' and '.join(remaining_insts)}.\")\n lines.append(f\"The remaining musicians are {' and '.join(remaining_names)}.\")\n\n # Process negative clues for the remaining musicians\n # Order: process in the order of remaining_names\n for name in remaining_names:\n i = names.index(name)\n # Find the negative clue for this person if exists\n neg_for_i = None\n for ni, wrong in neg_instruments:\n if ni == i:\n neg_for_i = wrong\n break\n\n if neg_for_i is not None:\n lines.append(f\"{name} does not play the {neg_for_i}.\")\n # Determine what they must play\n # They can't play neg_for_i, and the other remaining instrument is the only option\n other_inst = [inst for inst in remaining_insts if inst != neg_for_i][0]\n lines.append(f\"{name} plays the {other_inst}.\")\n # Remove from remaining\n remaining_insts.remove(other_inst)\n remaining_names.remove(name)\n\n # If there's still one left (shouldn't happen if logic is correct, but just in case)\n if remaining_names:\n name = remaining_names[0]\n inst = remaining_insts[0]\n lines.append(f\"{name} plays the {inst}.\")\n\n answer = ask_name\n return (question, lines, answer)\n\n return None\n"}
10
+ {"tid": "ff0ccb5c90", "cat": "science_calc", "code": "import random\n\ndef make(rng, original=False):\n if original:\n question = (\"A bacterial culture exhibits exponential growth described by the differential equation \"\n \"dN/dt = rN, where N is the population size and r is the growth rate constant. \"\n \"If the population doubles every 20 minutes, and a toxin is introduced that reduces the \"\n \"growth rate to 0.1 times its original value, calculate the new doubling time in minutes.\")\n lines = [\n \"The doubling time T satisfies e^(rT) = 2, so T = ln(2) / r.\",\n \"Original doubling time is 20 minutes, so r = ln(2) / 20.\",\n \"New growth rate is r_new = 0.1 * r.\",\n \"Substituting r: r_new = 0.1 * (ln(2) / 20) = ln(2) / 200.\",\n \"New doubling time is T_new = ln(2) / r_new.\",\n \"Substituting r_new: T_new = ln(2) / (ln(2) / 200) = 200.\"\n ]\n return question, lines, \"200\"\n\n # Parameters\n original_T = rng.randint(10, 100)\n factor = rng.choice([0.1, 0.2, 0.25, 0.5, 0.2, 0.5])\n new_T = original_T / factor\n\n # Check if new_T is an integer to avoid non-terminating decimals in the final answer if required,\n # though the problem asks for the time. The verified answer was an integer.\n # Let's ensure the result is clean.\n if not new_T.is_integer():\n return None\n\n new_T_int = int(new_T)\n\n # Generate question\n # Vary wording slightly\n verbs = [\"exhibits\", \"shows\", \"follows\"]\n verb = rng.choice(verbs)\n q = (f\"A bacterial culture {verb} exponential growth described by the differential equation \"\n f\"dN/dt = rN, where N is the population size and r is the growth rate constant. \"\n f\"If the population doubles every {original_T} minutes, and a toxin is introduced that reduces the \"\n f\"growth rate to {factor} times its original value, calculate the new doubling time in minutes.\")\n\n # Solution lines\n lines = [\n f\"The doubling time T satisfies e^(rT) = 2, so T = ln(2) / r.\",\n f\"Original doubling time is {original_T} minutes, so r = ln(2) / {original_T}.\",\n f\"New growth rate is r_new = {factor} * r.\",\n f\"Substituting r: r_new = {factor} * (ln(2) / {original_T}) = ln(2) / {new_T_int}.\",\n f\"New doubling time is T_new = ln(2) / r_new.\",\n f\"Substituting r_new: T_new = ln(2) / (ln(2) / {new_T_int}) = {new_T_int}.\"\n ]\n\n return q, lines, str(new_T_int)\n"}
11
+ {"tid": "70bfcf1df7", "cat": "probability", "code": "import random\nfrom math import comb\nfrom fractions import Fraction\n\ndef make(rng, original=False):\n if original:\n question = (\"Jessie is organizing a charity book drive and has a collection of 4 distinct novels and 3 \"\n \"distinct non-fiction books. If she randomly selects 2 books to be the \\\"featured display,\\\" \"\n \"what is the probability that she selects exactly one novel and one non-fiction book?\")\n lines = [\n \"Total number of books is 4 + 3 = 7.\",\n \"Total ways to select 2 books from 7 is C(7, 2) = 21.\",\n \"Ways to select exactly one novel from 4 is C(4, 1) = 4.\",\n \"Ways to select exactly one non-fiction book from 3 is C(3, 1) = 3.\",\n \"Number of favorable outcomes is 4 * 3 = 12.\",\n \"Probability is 12 / 21.\",\n \"Simplifying the fraction gives 4 / 7.\",\n ]\n return (question, lines, \"4/7\")\n\n # Draw parameters for a similar combinatorial probability problem.\n # We keep the structure: two groups, select k total, want exactly one from each group.\n # To keep difficulty similar, use small integers.\n # Ensure the probability is a valid fraction (denominator != 0) and not trivial (numerator > 0, denominator > numerator).\n # Also ensure the combination numbers are valid (n >= k).\n\n # Group sizes\n a = rng.randint(2, 8) # size of group A\n b = rng.randint(2, 8) # size of group B\n k = 2 # number of items selected (keep at 2 for \"exactly one from each\" to make sense as a single event)\n \n # We want exactly 1 from A and 1 from B. This requires k=2.\n # Total ways = C(a+b, 2)\n # Favorable ways = C(a, 1) * C(b, 1) = a * b\n \n # Check validity:\n # 1. a+b >= 2 (always true since a,b >= 2)\n # 2. Denominator C(a+b, 2) > 0 (always true)\n # 3. Numerator a*b > 0 (always true)\n # 4. Probability < 1 (a*b < C(a+b, 2))\n # C(a+b, 2) = (a+b)(a+b-1)/2\n # We need a*b < (a+b)(a+b-1)/2\n # 2ab < (a+b)^2 - (a+b) = a^2 + 2ab + b^2 - a - b\n # 0 < a^2 + b^2 - a - b\n # Since a,b >= 2, a^2 - a >= 2, b^2 - b >= 2, so sum >= 4 > 0. Always true.\n # 5. Probability > 0 (always true)\n \n # However, we should avoid cases where the fraction is 1 (impossible here) or 0 (impossible here).\n # Also, ensure the answer is not an integer (1 or 0) which is trivial.\n # The problem asks for a probability, usually a fraction.\n \n # Let's add some variation to the wording and names.\n names = [\"Alex\", \"Sam\", \"Jordan\", \"Taylor\", \"Morgan\", \"Casey\"]\n name = rng.choice(names)\n \n # Contexts\n contexts = [\n \"organizing a charity book drive\",\n \"preparing for a library event\",\n \"setting up a bookstore display\",\n \"planning a reading club selection\"\n ]\n context = rng.choice(contexts)\n \n # Item types\n types_a = [\"novels\", \"fiction books\", \"mystery books\", \"romance novels\"]\n types_b = [\"non-fiction books\", \"biographies\", \"history books\", \"science books\"]\n type_a = rng.choice(types_a)\n type_b = rng.choice(types_b)\n \n # Selection description\n selection_desc = rng.choice([\n \"randomly selects 2 books to be the \\\"featured display\\\"\",\n \"picks 2 books at random for the \\\"staff pick\\\" shelf\",\n \"chooses 2 books without replacement for the \\\"new arrivals\\\" table\"\n ])\n \n question = (f\"{name} is {context} and has a collection of {a} distinct {type_a} and {b} distinct {type_b}. \"\n f\"If {name} {selection_desc}, what is the probability that {name} selects exactly one {type_a.split()[0]} and one {type_b.split()[0]}?\")\n \n # Calculate values\n total_books = a + b\n total_ways = comb(total_books, 2)\n ways_a = comb(a, 1)\n ways_b = comb(b, 1)\n favorable = ways_a * ways_b\n prob = Fraction(favorable, total_ways)\n \n # Check if the problem is valid (not trivial, etc.)\n # If prob is 1 or 0, reject. (Already checked above, but double check)\n if prob.numerator == 0 or prob.denominator == 1:\n return None\n \n # Construct lines\n lines = [\n f\"Total number of books is {a} + {b} = {total_books}.\",\n f\"Total ways to select 2 books from {total_books} is C({total_books}, 2) = {total_ways}.\",\n f\"Ways to select exactly one {type_a.split()[0]} from {a} is C({a}, 1) = {ways_a}.\",\n f\"Ways to select exactly one {type_b.split()[0]} from {b} is C({b}, 1) = {ways_b}.\",\n f\"Number of favorable outcomes is {ways_a} * {ways_b} = {favorable}.\",\n f\"Probability is {favorable} / {total_ways}.\",\n f\"Simplifying the fraction gives {prob.numerator} / {prob.denominator}.\",\n ]\n \n answer = f\"{prob.numerator}/{prob.denominator}\"\n \n return (question, lines, answer)\n"}
12
+ {"tid": "02c32d72da", "cat": "wordproblem", "code": "import random\nfrom fractions import Fraction\n\ndef make(rng, original=False):\n if original:\n question = (\"In a political economy model of elite consolidation, the \\\"Effective Power Index\\\" (EPI) is calculated for a governing group of 12 members. \"\n \"The EPI is defined as the sum of each member's individual influence score, weighted by the square of their tenure in years. \"\n \"If 4 members have a tenure of 5 years and an influence score of 10, 5 members have a tenure of 2 years and an influence score of 20, \"\n \"and the remaining 3 members have a tenure of 10 years but an unknown identical influence score x, and the total EPI for the group is 1,200, \"\n \"what is the value of x?\")\n lines = [\n \"4 \u00d7 10 \u00d7 5\u00b2 = 1000\",\n \"5 \u00d7 20 \u00d7 2\u00b2 = 400\",\n \"3 \u00d7 x \u00d7 10\u00b2 = 300x\",\n \"1000 + 400 + 300x = 1200\",\n \"1400 + 300x = 1200\",\n \"300x = -200\",\n \"x = -2/3\",\n ]\n answer = \"-2/3\"\n return question, lines, answer\n\n # Draw new parameters\n # We need n1 + n2 + n3 = 12\n # We need total = n1*s1*t1^2 + n2*s2*t2^2 + n3*x*t3^2\n # x = (total - known) / (n3 * t3^2)\n # We want x to be a simple fraction (denominator divides nicely or small).\n \n total = None\n while total is None:\n # Choose group sizes\n n1 = rng.randint(1, 5)\n n2 = rng.randint(1, 5)\n n3 = 12 - n1 - n2\n if n3 < 1:\n continue\n \n # Choose tenures\n t1 = rng.randint(1, 12)\n t2 = rng.randint(1, 12)\n t3 = rng.randint(1, 12)\n \n # Choose scores\n s1 = rng.randint(1, 30)\n s2 = rng.randint(1, 30)\n \n known_sum = n1 * s1 * (t1 ** 2) + n2 * s2 * (t2 ** 2)\n coeff = n3 * (t3 ** 2)\n \n # We want x to be a fraction with a small denominator.\n # Let's pick a numerator for x such that x is a fraction.\n # Or just pick total such that (total - known_sum) is divisible by coeff?\n # The original problem had a negative fraction. Let's allow fractions.\n # Let x = p / q where q is small (2, 3, 4, 5, 6).\n # Then total = known_sum + coeff * p / q\n # For total to be an integer, coeff * p must be divisible by q.\n \n q = rng.choice([2, 3, 4, 5, 6])\n # Ensure coeff * p is divisible by q\n # Let p be an integer.\n # We need (coeff * p) % q == 0.\n # Let's pick p such that this holds.\n # The order of q modulo (coeff/q_gcd) ... simpler:\n # Let p = k * (q / gcd(coeff, q))\n # Then coeff * p = coeff * k * q / gcd(coeff, q) = (coeff / gcd(coeff, q)) * k * q\n # This is divisible by q.\n \n import math\n g = math.gcd(coeff, q)\n p_base = q // g\n # Pick k to make x not too large and not zero\n k = rng.randint(-10, 10)\n if k == 0:\n continue\n p = k * p_base\n x = Fraction(p, q)\n \n total_val = known_sum + coeff * x\n # Total must be an integer\n if not total_val.is_integer():\n continue\n \n total_int = int(total_val)\n # Ensure total is positive and reasonable\n if total_int <= 0 or total_int > 10000:\n continue\n \n # Check for ambiguity/triviality: x should not be 0 or 1\n if x == 0 or x == 1:\n continue\n \n total = total_int\n break\n\n # Construct question\n # Vary wording slightly\n group_names = [\"governing body\", \"council\", \"committee\", \"board\"]\n gname = rng.choice(group_names)\n \n # Format numbers\n def fmt_frac(fr):\n if fr.denominator == 1:\n return str(fr.numerator)\n return f\"{fr.numerator}/{fr.denominator}\"\n\n question = (\n f\"In a model of institutional stability, the \\\"Stability Index\\\" (SI) is calculated for a {gname} of 12 members. \"\n f\"The SI is defined as the sum of each member's authority score, weighted by the square of their service years. \"\n f\"If {n1} members have a service of {t1} years and an authority score of {s1}, \"\n f\"{n2} members have a service of {t2} years and an authority score of {s2}, \"\n f\"and the remaining {n3} members have a service of {t3} years but an unknown identical authority score x, \"\n f\"and the total SI for the group is {total}, what is the value of x?\"\n )\n\n # Construct solution lines\n term1 = n1 * s1 * (t1 ** 2)\n term2 = n2 * s2 * (t2 ** 2)\n coeff_x = n3 * (t3 ** 2)\n \n lines = [\n f\"{n1} \u00d7 {s1} \u00d7 {t1}\u00b2 = {term1}\",\n f\"{n2} \u00d7 {s2} \u00d7 {t2}\u00b2 = {term2}\",\n f\"{n3} \u00d7 x \u00d7 {t3}\u00b2 = {coeff_x}x\",\n f\"{term1} + {term2} + {coeff_x}x = {total}\",\n f\"{term1 + term2} + {coeff_x}x = {total}\",\n f\"{coeff_x}x = {total - (term1 + term2)}\",\n ]\n \n x_frac = Fraction(total - (term1 + term2), coeff_x)\n lines.append(f\"x = {fmt_frac(x_frac)}\")\n \n answer = fmt_frac(x_frac)\n \n return question, lines, answer\n"}
13
+ {"tid": "f9bff436f9", "cat": "wordproblem", "code": "import random\n\ndef make(rng, original=False):\n if original:\n question = \"Neal\u2019s book has chapters whose page counts form an arithmetic sequence: 12, ?, 20, 24. What is the missing chapter\u2019s page count?\"\n lines = [\n \"Common difference = (24 - 12)/3 = 4\",\n \"Second term = 12 + 4 = 16\",\n ]\n return (question, lines, \"16\")\n\n # Generate a new arithmetic sequence of 4 terms with one term missing (index 1, 2, or 3)\n # Ensure positive integers and non-zero common difference.\n a = rng.randint(5, 50)\n d = rng.choice([-1, 1]) * rng.randint(2, 10)\n terms = [a + i * d for i in range(4)]\n if any(t <= 0 for t in terms):\n return None\n\n missing_idx = rng.randint(1, 3)\n visible = [terms[i] for i in range(4) if i != missing_idx]\n\n # Build question with a placeholder\n placeholders = [\"?\", \"?\", \"?\", \"?\"]\n placeholders[missing_idx] = \"?\"\n seq_str = \", \".join(str(terms[i]) if i != missing_idx else \"?\" for i in range(4))\n names = [\"Aiden\", \"Bella\", \"Carter\", \"Diana\", \"Evan\", \"Fiona\", \"Gavin\", \"Holly\"]\n name = rng.choice(names)\n objects = [\"book\", \"notebook\", \"journal\", \"diary\", \"ledger\"]\n obj = rng.choice(objects)\n question = f\"{name}\u2019s {obj} has sections whose page counts form an arithmetic sequence: {seq_str}. What is the missing section\u2019s page count?\"\n\n # Compute solution lines\n # We know two non-adjacent or adjacent visible terms; derive d from any pair.\n # Use first and last visible if both present; otherwise use adjacent visible terms.\n # Since only one term is missing, at least two visible terms are adjacent or we can use first/last.\n # Find two visible terms with known indices to compute d.\n vis_idx = [i for i in range(4) if i != missing_idx]\n i1, i2 = vis_idx[0], vis_idx[-1]\n d_val = (terms[i2] - terms[i1]) / (i2 - i1)\n # d_val should be integer\n if d_val != int(d_val):\n return None\n d_int = int(d_val)\n\n # Determine missing term\n missing_val = terms[missing_idx]\n\n # Build deduction lines\n # Line 1: compute common difference using two known terms\n line1 = f\"Common difference = ({terms[i2]} - {terms[i1]}) / {i2 - i1} = {d_int}\"\n\n # Line 2: compute missing term from nearest known term\n # Find a known term adjacent to the missing index\n if missing_idx == 1:\n base_idx = 0\n sign = \"+\"\n line2 = f\"Second term = {terms[0]} + {d_int} = {missing_val}\"\n elif missing_idx == 2:\n base_idx = 1\n sign = \"+\"\n line2 = f\"Third term = {terms[1]} + {d_int} = {missing_val}\"\n elif missing_idx == 3:\n base_idx = 2\n sign = \"+\"\n line2 = f\"Fourth term = {terms[2]} + {d_int} = {missing_val}\"\n\n lines = [line1, line2]\n answer = str(missing_val)\n return (question, lines, answer)\n"}
14
+ {"tid": "c5ffed7139", "cat": "logic", "code": "import random\nfrom itertools import permutations\n\ndef make(rng, original=False):\n if original:\n question = ('Five collectors are arranging their first-edition \"McCaffrey\" biographies on a shelf: A, B, C, D, and E. '\n 'The following conditions apply: (1) A is to the left of B; (2) C is immediately to the right of B; '\n '(3) D is not next to E; (4) A is in the middle position (3rd); (5) E is to the left of D. '\n 'What is the correct order of the books from left to right?')\n lines = [\n \"A is in position 3.\",\n \"A is to the left of B, so B is in position 4 or 5.\",\n \"C is immediately to the right of B, so B cannot be in position 5.\",\n \"B is in position 4 and C is in position 5.\",\n \"Positions 1 and 2 are occupied by D and E.\",\n \"E is to the left of D, so E is in position 1 and D is in position 2.\",\n \"D and E are adjacent, which violates the condition that D is not next to E.\",\n \"No arrangement satisfies all conditions.\"\n ]\n answer = \"No valid order\"\n return question, lines, answer\n\n # Generate a new problem with similar structure: 5 items, one fixed middle,\n # one immediate-right constraint, one left-of constraint, one not-adjacent constraint,\n # one left-of constraint.\n # We'll pick random letters and constraints, then check if a unique solution exists\n # or if no solution exists. We want to keep the \"no valid order\" flavor sometimes,\n # but the original is \"No valid order\". To keep similar difficulty, we can generate\n # problems that may have 0, 1, or multiple solutions, and return None if not exactly one\n # or zero? The instruction says: \"reject any draw that makes the problem invalid, trivial, ambiguous, or gives non-terminating decimals\".\n # Ambiguous means multiple solutions. Invalid might mean no solution? But original has no solution.\n # However, the template should return None if ambiguous (multiple solutions). If no solution, is that valid?\n # The original problem has no solution. So we should allow \"No valid order\" as a valid answer.\n # But we must ensure it's not trivial. Let's generate constraints and count solutions.\n # If count == 1, answer is the order. If count == 0, answer is \"No valid order\".\n # If count > 1, return None.\n\n letters = rng.sample(list(\"ABCDEFGHJKLMNPQRST\"), 5) # Avoid I, O, U for clarity? Or just use 5 distinct letters\n a, b, c, d, e = letters\n\n # Define constraints randomly\n # Constraint types:\n # 1. X is in position k (1-5)\n # 2. X is to the left of Y\n # 3. X is immediately to the right of Y\n # 4. X is not next to Y\n \n # To keep structure similar to original:\n # - One item fixed in middle (pos 3)\n # - One immediate right constraint\n # - Two \"left of\" constraints\n # - One \"not next to\" constraint\n \n # Let's assign roles:\n # fixed_item: in position 3\n # imm_right: C is immediately right of B -> B at pos i, C at i+1\n # left1: A left of B\n # left2: E left of D\n # not_adj: D not next to E\n \n # Randomize which letter is which role\n roles = rng.sample(letters, 5)\n fixed_item = roles[0]\n left1_item = roles[1]\n imm_right_left = roles[2]\n imm_right_right = roles[3]\n left2_item1 = roles[4]\n # We need 5 distinct items. Let's pick 5 distinct letters.\n # left2_item2 is the remaining one? No, we have 5 items.\n # Let's define:\n # Item 1: fixed in pos 3\n # Item 2: left of Item 3\n # Item 3: immediate right of Item 4? No, \"C is immediately to the right of B\" means B is left, C is right.\n # Let's use:\n # fixed: F\n # left_of: L1 < L2\n # imm_right: R1 immediately left of R2 (so R2 is immediately right of R1)\n # not_adj: N1 not next to N2\n # left_of2: L3 < L4\n \n # We have 5 items. Let's assign:\n # F: fixed in pos 3\n # A, B: A left of B\n # C, D: C immediately left of D\n # E, F: E left of F? But F is already used.\n # Let's pick 5 distinct letters: X1, X2, X3, X4, X5\n # Constraint 1: X1 is in position 3\n # Constraint 2: X2 is to the left of X3\n # Constraint 3: X4 is immediately to the left of X5\n # Constraint 4: X2 is not next to X4\n # Constraint 5: X3 is to the left of X4\n \n # This structure might yield 0 or 1 solutions.\n \n x1, x2, x3, x4, x5 = rng.sample(list(\"ABCDE\"), 5)\n \n # Randomize the constraints slightly to avoid being too similar\n # But keep the types.\n \n def check(arr):\n pos = {item: i for i, item in enumerate(arr)}\n # X1 in pos 3 (index 2)\n if pos[x1] != 2:\n return False\n # X2 left of X3\n if pos[x2] >= pos[x3]:\n return False\n # X4 immediately left of X5\n if pos[x4] + 1 != pos[x5]:\n return False\n # X2 not next to X4\n if abs(pos[x2] - pos[x4]) == 1:\n return False\n # X3 left of X4\n if pos[x3] >= pos[x4]:\n return False\n return True\n\n solutions = []\n for perm in permutations([x1, x2, x3, x4, x5]):\n if check(perm):\n solutions.append(perm)\n \n if len(solutions) > 1:\n return None\n if len(solutions) == 1:\n sol = solutions[0]\n answer = \" \".join(sol)\n else:\n answer = \"No valid order\"\n \n # Construct question\n question = (f\"Five collectors are arranging their first-edition \\\"{rng.choice(['McCaffrey', 'Doe', 'Smith', 'Jones'])}\\\" biographies on a shelf: \"\n f\"{x1}, {x2}, {x3}, {x4}, and {x5}. The following conditions apply: \"\n f\"(1) {x1} is in the middle position (3rd); \"\n f\"(2) {x2} is to the left of {x3}; \"\n f\"(3) {x4} is immediately to the left of {x5}; \"\n f\"(4) {x2} is not next to {x4}; \"\n f\"(5) {x3} is to the left of {x4}. \"\n f\"What is the correct order of the books from left to right?\")\n \n # Construct lines\n # We need to generate a deduction path. This is complex for a template.\n # Instead, we can list the logical steps generically.\n lines = [\n f\"{x1} is in position 3.\",\n f\"{x2} is to the left of {x3}, so {x2} is in position 1 or 2 and {x3} is in a higher position.\",\n f\"{x4} is immediately to the left of {x5}, so they occupy two adjacent positions.\",\n f\"{x3} is to the left of {x4}, so {x3} must be in a position lower than {x4}.\",\n f\"{x2} is not next to {x4}.\"\n ]\n \n # If no solution, add a line indicating no arrangement works.\n if len(solutions) == 0:\n lines.append(\"No arrangement satisfies all conditions.\")\n else:\n sol = solutions[0]\n lines.append(f\"The only valid order is {' '.join(sol)}.\")\n \n return question, lines, answer\n"}
15
+ {"tid": "43f5ed74e8", "cat": "probability", "code": "import math\nimport random\n\ndef make(rng, original=False):\n if original:\n question = (\"A publisher is preparing a limited edition box set containing all 12 of Lillian Stewart Carl's novels. \"\n \"The spines are to be arranged in a row. If the novel *The Last Song of the Whale* must be placed \"\n \"immediately to the left of *A Heart of Fire*, how many distinct arrangements of the 12 spines are possible?\")\n lines = [\n \"Treat the two constrained novels as a single fixed block.\",\n \"This block plus the remaining 10 novels forms 11 distinct objects.\",\n \"The number of distinct arrangements of 11 objects is 11!.\",\n \"11! = 39916800.\"\n ]\n answer = \"39916800\"\n return question, lines, answer\n\n # Generate a new problem with the same structure\n # Choose total number of items between 6 and 15\n n = rng.randint(6, 15)\n \n # Ensure we have at least 2 items to form a pair\n if n < 2:\n return None\n\n # Generate unique names for the items\n adjectives = [\"Silent\", \"Crimson\", \"Golden\", \"Broken\", \"Eternal\", \"Hidden\", \"Forgotten\", \"Ancient\", \"Mystic\", \"Wild\", \"Deep\", \"Bright\", \"Dark\", \"Silver\", \"Iron\", \"Stone\", \"Shadow\", \"Light\", \"Storm\", \"River\"]\n nouns = [\"Song\", \"Heart\", \"Whale\", \"Fire\", \"Moon\", \"Star\", \"Tree\", \"River\", \"Mountain\", \"Ocean\", \"Sky\", \"Earth\", \"Wind\", \"Rain\", \"Snow\", \"Sun\", \"Cloud\", \"Flower\", \"Bird\", \"Fish\"]\n \n used = set()\n names = []\n attempts = 0\n while len(names) < n and attempts < 1000:\n adj = rng.choice(adjectives)\n noun = rng.choice(nouns)\n name = f\"{adj} {noun}\"\n if name not in used:\n used.add(name)\n names.append(name)\n attempts += 1\n \n if len(names) < n:\n return None\n\n # Pick two distinct items to be the constrained pair\n i, j = rng.sample(range(n), 2)\n left_name = names[i]\n right_name = names[j]\n\n # The constraint is that left_name must be immediately to the left of right_name\n # This forms a block of size 2\n # Total objects to arrange = n - 1\n objects = n - 1\n answer_val = math.factorial(objects)\n\n # Check for trivial cases or issues\n if objects < 1:\n return None\n\n # Build the question\n question = (f\"A collector is arranging {n} unique books on a shelf. \"\n f\"If the book *{left_name}* must be placed immediately to the left of *{right_name}*, \"\n f\"how many distinct arrangements of the {n} books are possible?\")\n\n # Build the solution lines\n lines = [\n f\"Treat the two constrained books ({left_name} and {right_name}) as a single fixed block.\",\n f\"This block plus the remaining {n - 2} books forms {objects} distinct objects.\",\n f\"The number of distinct arrangements of {objects} objects is {objects}!.\",\n f\"{objects}! = {answer_val}.\"\n ]\n\n answer = str(answer_val)\n\n return question, lines, answer\n"}
16
+ {"tid": "7e9b19d82b", "cat": "wordproblem", "code": "import random\n\ndef make(rng, original=False):\n if original:\n question = (\"A local market in a coastal town inspired by the name Mart\u00edn Rico sells fresh oysters. \"\n \"The price per pound fluctuates based on supply; if the daily catch is under 500 pounds, the price is $12 per pound, \"\n \"but if it exceeds 500 pounds, the price drops to $8 per pound. On a specific Tuesday, a restaurant purchased 620 pounds of oysters. \"\n \"Due to a 10% spoilage rate during transport, only 90% of the purchased oysters were sellable. \"\n \"If the restaurant sells the remaining good oysters for $15 per pound, what is the total profit made on that day?\")\n lines = [\n \"620 pounds exceeds the 500-pound threshold, so the purchase price is $8 per pound.\",\n \"Total cost = 620 \u00d7 8 = $4960.\",\n \"Sellable oysters = 620 \u00d7 0.90 = 558 pounds.\",\n \"Total revenue = 558 \u00d7 15 = $8370.\",\n \"Profit = 8370 \u2212 4960 = $3410.\",\n ]\n return question, lines, \"$3410\"\n\n # New parameters\n threshold = rng.choice([300, 400, 500, 600, 700])\n high_price = rng.choice([10, 12, 14, 16])\n low_price = rng.choice([6, 8, 10])\n if low_price >= high_price:\n low_price = high_price - 2\n purchase = rng.randint(threshold + 1, threshold + 400)\n spoilage_pct = rng.choice([5, 10, 15, 20])\n keep = 100 - spoilage_pct\n if (purchase * keep) % 100 != 0:\n return None\n sell_price = rng.choice([12, 15, 18, 20, 22])\n if sell_price <= high_price:\n sell_price = high_price + 3\n\n town = rng.choice([\"Cape Harbor\", \"Bayview\", \"Seaside\", \"Port Haven\", \"Coastal Ridge\"])\n product = rng.choice([\"oysters\", \"clams\", \"mussels\", \"shrimp\"])\n day = rng.choice([\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\"])\n\n cost = purchase * low_price\n sellable = purchase * keep // 100\n revenue = sellable * sell_price\n profit = revenue - cost\n\n question = (f\"A local market in a coastal town named {town} sells fresh {product}. \"\n f\"The price per pound fluctuates based on supply; if the daily catch is under {threshold} pounds, the price is ${high_price} per pound, \"\n f\"but if it exceeds {threshold} pounds, the price drops to ${low_price} per pound. On a specific {day}, a restaurant purchased {purchase} pounds of {product}. \"\n f\"Due to a {spoilage_pct}% spoilage rate during transport, only {keep}% of the purchased {product} were sellable. \"\n f\"If the restaurant sells the remaining good {product} for ${sell_price} per pound, what is the total profit made on that day?\")\n lines = [\n f\"{purchase} pounds exceeds the {threshold}-pound threshold, so the purchase price is ${low_price} per pound.\",\n f\"Total cost = {purchase} \u00d7 {low_price} = ${cost}.\",\n f\"Sellable {product} = {purchase} \u00d7 {keep/100:.2f} = {sellable} pounds.\",\n f\"Total revenue = {sellable} \u00d7 {sell_price} = ${revenue}.\",\n f\"Profit = {revenue} \u2212 {cost} = ${profit}.\",\n ]\n return question, lines, f\"${profit}\"\n"}
17
+ {"tid": "b3f2ea196c", "cat": "probability", "code": "import math\nimport random\n\ndef make(rng, original=False):\n if original:\n question = (\"A video editor has 5 different intro clips, 3 different body segments, and 2 different outro clips \"\n \"available for editing a single home movie. Each clip must be used exactly once, and the order of clips \"\n \"within the final movie must follow the sequence: Intro -> Body -> Outro. How many distinct home movie \"\n \"variations can the editor create?\")\n lines = [\n \"All 5 intro clips must be arranged in the intro section: 5! = 120\",\n \"All 3 body segments must be arranged in the body section: 3! = 6\",\n \"All 2 outro clips must be arranged in the outro section: 2! = 2\",\n \"Total variations = 120 \u00d7 6 \u00d7 2\",\n \"Total variations = 720 \u00d7 2\",\n \"Total variations = 1440\",\n ]\n answer = \"1440\"\n return question, lines, answer\n\n # Draw new numbers\n # Ensure non-trivial: at least one section has >= 2 items\n a = rng.randint(1, 7)\n b = rng.randint(1, 6)\n c = rng.randint(1, 5)\n if max(a, b, c) < 2:\n return None\n\n # Vary the context\n contexts = [\n (\"A video editor\", \"intro clips\", \"body segments\", \"outro clips\", \"home movie\"),\n (\"A graphic designer\", \"header banners\", \"main content blocks\", \"footer widgets\", \"web page\"),\n (\"A chef\", \"appetizer plates\", \"main course dishes\", \"dessert items\", \"tasting menu\"),\n (\"A music producer\", \"intro tracks\", \"verse sections\", \"outro tracks\", \"album\"),\n (\"A stage manager\", \"opening acts\", \"main performances\", \"closing acts\", \"theater show\"),\n ]\n ctx = rng.choice(contexts)\n actor, s1, s2, s3, obj = ctx\n\n # Compute answer\n ans = math.factorial(a) * math.factorial(b) * math.factorial(c)\n\n question = (f\"{actor} has {a} different {s1}, {b} different {s2}, and {c} different {s3} \"\n f\"available for producing a single {obj}. Each item must be used exactly once, and the order of items \"\n f\"within the final {obj} must follow the sequence: {s1.split()[0].capitalize()} -> {s2.split()[0].capitalize()} -> {s3.split()[0].capitalize()}. \"\n f\"How many distinct {obj} variations can be created?\")\n\n f1 = math.factorial(a)\n f2 = math.factorial(b)\n f3 = math.factorial(c)\n mid = f1 * f2\n\n lines = [\n f\"All {a} {s1} must be arranged in the first section: {a}! = {f1}\",\n f\"All {b} {s2} must be arranged in the second section: {b}! = {f2}\",\n f\"All {c} {s3} must be arranged in the third section: {c}! = {f3}\",\n f\"Total variations = {f1} \u00d7 {f2} \u00d7 {f3}\",\n f\"Total variations = {mid} \u00d7 {f3}\",\n f\"Total variations = {ans}\",\n ]\n answer = str(ans)\n return question, lines, answer\n"}
18
+ {"tid": "227f052f2c", "cat": "wordproblem", "code": "import random\n\ndef make(rng, original=False):\n if original:\n question = (\"A conservation team at the Art Institute of Chicago needs to restore a large mural on the building's exterior. \"\n \"The mural covers an area of 1,200 square feet. One technician can apply the protective sealant at a rate of 15 square feet per hour, \"\n \"while an apprentice can apply it at 5 square feet per hour. If they work together for 4 hours and then the technician leaves, \"\n \"how many additional hours will the apprentice need to complete the remaining area alone?\")\n lines = [\n \"Combined rate of technician and apprentice: 15 + 5 = 20 square feet per hour\",\n \"Area covered in 4 hours: 20 \u00d7 4 = 80 square feet\",\n \"Remaining area to cover: 1200 - 80 = 1120 square feet\",\n \"Apprentice's rate: 5 square feet per hour\",\n \"Additional hours needed: 1120 \u00f7 5 = 224 hours\",\n ]\n return (question, lines, \"224\")\n\n # Generate parameters ensuring integer answer\n t_rate = rng.randint(8, 40)\n a_rate = rng.randint(2, 10)\n t_hours = rng.randint(1, 10)\n combined = t_rate + a_rate\n covered = combined * t_hours\n # Choose remaining such that remaining % a_rate == 0\n # remaining = total - covered\n # Let remaining = k * a_rate, k >= 1\n k = rng.randint(1, 200)\n remaining = k * a_rate\n total = covered + remaining\n if total < 100:\n return None\n\n # Ensure not trivial\n if a_rate == 0:\n return None\n\n # Vary wording\n locations = [\"Art Institute of Chicago\", \"National Gallery\", \"Museum of Modern Art\", \"City Hall\", \"Historic Theatre\"]\n roles = [(\"painter\", \"helper\"), (\"worker\", \"intern\"), (\"expert\", \"trainee\")]\n loc = rng.choice(locations)\n r1, r2 = rng.choice(roles)\n\n question = (f\"A restoration crew at the {loc} needs to finish coating a large wall on the building's exterior. \"\n f\"The wall covers an area of {total} square feet. One {r1} can apply the coating at a rate of {t_rate} square feet per hour, \"\n f\"while a {r2} can apply it at {a_rate} square feet per hour. If they work together for {t_hours} hours and then the {r1} leaves, \"\n f\"how many additional hours will the {r2} need to complete the remaining area alone?\")\n\n lines = [\n f\"Combined rate of {r1} and {r2}: {t_rate} + {a_rate} = {combined} square feet per hour\",\n f\"Area covered in {t_hours} hours: {combined} \u00d7 {t_hours} = {covered} square feet\",\n f\"Remaining area to cover: {total} - {covered} = {remaining} square feet\",\n f\"{r2}'s rate: {a_rate} square feet per hour\",\n f\"Additional hours needed: {remaining} \u00f7 {a_rate} = {k} hours\",\n ]\n answer = str(k)\n return (question, lines, answer)\n"}
19
+ {"tid": "5d107ba914", "cat": "planning", "code": "import random\nfrom itertools import permutations\n\ndef make(rng, original=False):\n if original:\n question = (\"A conference organizer is arranging seating for four delegates (P, Q, R, S) at a round table \"\n \"with four distinct chairs (North, East, South, West). Delegate P must sit in the North chair. \"\n \"Delegate Q cannot sit in the East chair. Delegate R must sit immediately clockwise from \"\n \"Delegate S. Delegate S cannot sit in the North chair. Determine the specific chair (by cardinal \"\n \"direction) in which Delegate Q is seated.\")\n lines = [\n \"P is in the North chair.\",\n \"The remaining chairs are East, South, and West.\",\n \"Delegate S cannot be in the North chair.\",\n \"If Delegate S is in the East chair, Delegate R must be in the South chair (immediately clockwise).\",\n \"This leaves Delegate Q in the West chair.\",\n \"If Delegate S is in the South chair, Delegate R must be in the West chair.\",\n \"This leaves Delegate Q in the East chair, which is forbidden.\",\n \"If Delegate S is in the West chair, Delegate R must be in the North chair.\",\n \"This conflicts with Delegate P being in the North chair.\",\n \"Therefore, the only valid arrangement is S in East, R in South, and Q in West.\"\n ]\n return question, lines, \"West\"\n\n # Generate new problem\n chairs = [\"North\", \"East\", \"South\", \"West\"]\n clockwise = {\n \"North\": \"East\",\n \"East\": \"South\",\n \"South\": \"West\",\n \"West\": \"North\"\n }\n delegates = [\"A\", \"B\", \"C\", \"D\"]\n \n # Randomly assign constraints\n # One delegate is fixed to a chair\n fixed_delegate = rng.choice(delegates)\n fixed_chair = rng.choice(chairs)\n \n # Another delegate cannot sit in a specific chair\n forbidden_delegate = rng.choice([d for d in delegates if d != fixed_delegate])\n forbidden_chair = rng.choice([c for c in chairs if c != fixed_chair])\n \n # Two delegates have a clockwise relationship: X must be immediately clockwise from Y\n # Choose two delegates for this relationship\n remaining_delegates = [d for d in delegates if d not in [fixed_delegate, forbidden_delegate]]\n if len(remaining_delegates) < 2:\n return None\n x, y = rng.sample(remaining_delegates, 2)\n \n # Ensure the problem is solvable and unique\n valid_assignments = []\n for perm in permutations(chairs):\n assignment = dict(zip(delegates, perm))\n # Check fixed delegate\n if assignment[fixed_delegate] != fixed_chair:\n continue\n # Check forbidden delegate\n if assignment[forbidden_delegate] == forbidden_chair:\n continue\n # Check clockwise relationship: x is immediately clockwise from y\n if clockwise[assignment[y]] != assignment[x]:\n continue\n valid_assignments.append(assignment)\n \n if len(valid_assignments) != 1:\n return None\n \n solution = valid_assignments[0]\n target_delegate = forbidden_delegate # We want to find where the forbidden delegate sits\n answer = solution[target_delegate]\n \n # Build question\n question = (f\"A conference organizer is arranging seating for four delegates ({', '.join(delegates)}) at a round table \"\n f\"with four distinct chairs (North, East, South, West). Delegate {fixed_delegate} must sit in the {fixed_chair} chair. \"\n f\"Delegate {forbidden_delegate} cannot sit in the {forbidden_chair} chair. Delegate {x} must sit immediately clockwise from \"\n f\"Delegate {y}. Determine the specific chair (by cardinal direction) in which Delegate {target_delegate} is seated.\")\n \n # Build solution lines\n lines = [\n f\"{fixed_delegate} is in the {fixed_chair} chair.\",\n f\"The remaining chairs are {', '.join([c for c in chairs if c != fixed_chair])}.\",\n f\"Delegate {forbidden_delegate} cannot be in the {forbidden_chair} chair.\",\n ]\n \n # Enumerate possibilities for y (the one that x is clockwise from)\n for y_chair in [c for c in chairs if c != fixed_chair]:\n x_chair = clockwise[y_chair]\n if x_chair == fixed_chair:\n lines.append(f\"If Delegate {y} is in the {y_chair} chair, Delegate {x} must be in the {x_chair} chair.\")\n lines.append(f\"This conflicts with Delegate {fixed_delegate} being in the {fixed_chair} chair.\")\n continue\n # Assign y and x, then determine where forbidden_delegate can go\n remaining = [c for c in chairs if c not in [fixed_chair, y_chair, x_chair]]\n if len(remaining) != 1:\n continue\n forbidden_chair_actual = remaining[0]\n if forbidden_chair_actual == forbidden_chair:\n lines.append(f\"If Delegate {y} is in the {y_chair} chair, Delegate {x} must be in the {x_chair} chair.\")\n lines.append(f\"This leaves Delegate {forbidden_delegate} in the {forbidden_chair_actual} chair, which is forbidden.\")\n else:\n lines.append(f\"If Delegate {y} is in the {y_chair} chair, Delegate {x} must be in the {x_chair} chair.\")\n lines.append(f\"This leaves Delegate {forbidden_delegate} in the {forbidden_chair_actual} chair.\")\n \n lines.append(f\"Therefore, the only valid arrangement is {y} in {solution[y]}, {x} in {solution[x]}, and {forbidden_delegate} in {answer}.\")\n \n return question, lines, answer\n"}
20
+ {"tid": "85086db343", "cat": "logic", "code": "import random, itertools\n\ndef make(rng, original=False):\n if original:\n names = [\"Barnaby\", \"Xala\", \"Dr. Vex\"]\n question = (\"Three friends, named after characters from a chaotic sci-fi novel \"\n \"(Barnaby, Xala, and Dr. Vex), are standing in a line. \"\n \"Barnaby is not first. Xala is immediately behind Barnaby. \"\n \"Dr. Vex is not last. Determine the exact order of the three friends from first to last.\")\n lines = [\n \"Barnaby is not first, so Barnaby is in position 2 or 3.\",\n \"Xala is immediately behind Barnaby, so Xala is in position 3 if Barnaby is in position 2, or position 4 if Barnaby is in position 3.\",\n \"Position 4 does not exist, so Barnaby cannot be in position 3.\",\n \"Barnaby is in position 2.\",\n \"Xala is in position 3.\",\n \"Dr. Vex is in position 1.\",\n \"Dr. Vex is not last, which is consistent with position 1.\",\n \"The order from first to last is Dr. Vex, Barnaby, Xala.\",\n ]\n answer = \"Dr. Vex, Barnaby, Xala\"\n return question, lines, answer\n\n # Build a 3-person ordering puzzle with one \"not first\", one \"immediately behind\",\n # and one \"not last\" clue, guaranteed to have a unique solution.\n pool = [\"Zeph\", \"Kora\", \"Dr. Mael\", \"Tess\", \"Ivo\", \"Nyla\", \"Quinn\", \"Rhea\"]\n names = rng.sample(pool, 3)\n a, b, c = names # a is the one not first, b is immediately behind a, c is not last\n\n # The clue \"b is immediately behind a\" forces (a,b) to be adjacent with a before b.\n # Possible (a,b) position pairs: (1,2) or (2,3).\n # Clue \"a is not first\" removes (1,2), leaving (2,3). Then c is at position 1.\n # Clue \"c is not last\" is consistent with position 1.\n # So the unique order is c, a, b.\n order = [c, a, b]\n\n # Verify uniqueness by brute force.\n solutions = []\n for perm in itertools.permutations(names):\n pos = {name: i + 1 for i, name in enumerate(perm)}\n if pos[a] == 1:\n continue\n if pos[b] != pos[a] + 1:\n continue\n if pos[c] == 3:\n continue\n solutions.append(perm)\n if len(solutions) != 1:\n return None\n\n # Vary wording slightly.\n intro = rng.choice([\n \"Three friends, named after characters from a chaotic sci-fi novel\",\n \"Three friends, named after characters from a mysterious sci-fi novel\",\n \"Three friends, named after characters from a wild sci-fi novel\",\n ])\n q = (f\"{intro} ({a}, {b}, and {c}), are standing in a line. \"\n f\"{a} is not first. {b} is immediately behind {a}. \"\n f\"{c} is not last. Determine the exact order of the three friends from first to last.\")\n\n lines = [\n f\"{a} is not first, so {a} is in position 2 or 3.\",\n (f\"{b} is immediately behind {a}, so {b} is in position 3 if {a} is in position 2, \"\n f\"or position 4 if {a} is in position 3.\"),\n f\"Position 4 does not exist, so {a} cannot be in position 3.\",\n f\"{a} is in position 2.\",\n f\"{b} is in position 3.\",\n f\"{c} is in position 1.\",\n f\"{c} is not last, which is consistent with position 1.\",\n f\"The order from first to last is {order[0]}, {order[1]}, {order[2]}.\",\n ]\n answer = f\"{order[0]}, {order[1]}, {order[2]}\"\n return q, lines, answer\n"}
21
+ {"tid": "87eadfabcb", "cat": "finance", "code": "import random\nimport math\n\ndef make(rng, original=False):\n if original:\n face_value = 50_000_000\n coupon_rate = 0.05\n market_yield = 0.04\n years = 10\n question = (\"A state-owned forestry firm in the Pine Barrens region is valued at $1.2 billion \"\n \"with a net income of $100 million per year. If the firm issues a new bond with a face value \"\n \"of $50 million at a coupon rate of 5% (annual payment) when the current market yield is 4%, \"\n \"what is the current market price of the bond, assuming it has a 10-year maturity?\")\n lines = [\n f\"Annual coupon payment = face value * coupon rate = {face_value} * {coupon_rate} = ${face_value * coupon_rate:,.2f}\",\n f\"Present value of coupons = {face_value * coupon_rate} * (1 - (1 + {market_yield})^-{years}) / {market_yield} = ${face_value * coupon_rate * (1 - (1 + market_yield) ** -years) / market_yield:,.2f}\",\n f\"Present value of face value = {face_value} / (1 + {market_yield})^{years} = ${face_value / (1 + market_yield) ** years:,.2f}\",\n f\"Market price = PV of coupons + PV of face value = ${face_value * coupon_rate * (1 - (1 + market_yield) ** -years) / market_yield + face_value / (1 + market_yield) ** years:,.2f}\",\n f\"Rounded to two decimal places in millions = ${ (face_value * coupon_rate * (1 - (1 + market_yield) ** -years) / market_yield + face_value / (1 + market_yield) ** years) / 1_000_000 :.2f} million\"\n ]\n answer = f\"${(face_value * coupon_rate * (1 - (1 + market_yield) ** -years) / market_yield + face_value / (1 + market_yield) ** years) / 1_000_000 :.2f} million\"\n return question, lines, answer\n\n # Generate new parameters\n face_value_millions = rng.choice([20, 30, 40, 50, 60, 70, 80, 90, 100])\n coupon_rate = rng.choice([0.03, 0.04, 0.05, 0.06, 0.07, 0.08])\n market_yield = rng.choice([0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08])\n years = rng.choice([5, 7, 10, 15, 20])\n \n # Ensure non-trivial (coupon != yield to avoid trivial par value, though not strictly required, but good for variety)\n if coupon_rate == market_yield:\n return None\n\n face_value = face_value_millions * 1_000_000\n \n # Calculate values\n annual_coupon = face_value * coupon_rate\n pv_coupons = annual_coupon * (1 - (1 + market_yield) ** -years) / market_yield\n pv_face = face_value / (1 + market_yield) ** years\n market_price = pv_coupons + pv_face\n price_millions = market_price / 1_000_000\n \n # Check for non-terminating decimals that might cause rounding issues in display if we wanted exact, \n # but we are rounding to 2 decimals so it's fine.\n # Ensure the result is not ambiguous or trivial.\n \n industry = rng.choice([\"forestry\", \"energy\", \"telecom\", \"railway\", \"mining\"])\n region = rng.choice([\"Pine Barrens\", \"Appalachia\", \"Sierra Nevada\", \"Great Basin\", \"Cascadia\"])\n firm_val_millions = rng.randint(500, 5000)\n net_income_millions = rng.randint(20, 200)\n \n question = (f\"A state-owned {industry} firm in the {region} region is valued at ${firm_val_millions} million \"\n f\"with a net income of ${net_income_millions} million per year. If the firm issues a new bond with a face value \"\n f\"of ${face_value_millions} million at a coupon rate of {coupon_rate*100:.0f}% (annual payment) when the current market yield is {market_yield*100:.0f}%, \"\n f\"what is the current market price of the bond, assuming it has a {years}-year maturity?\")\n \n lines = [\n f\"Annual coupon payment = face value * coupon rate = {face_value:,} * {coupon_rate} = ${annual_coupon:,.2f}\",\n f\"Present value of coupons = {annual_coupon:,.2f} * (1 - (1 + {market_yield})^-{years}) / {market_yield} = ${pv_coupons:,.2f}\",\n f\"Present value of face value = {face_value:,} / (1 + {market_yield})^{years} = ${pv_face:,.2f}\",\n f\"Market price = PV of coupons + PV of face value = ${market_price:,.2f}\",\n f\"Rounded to two decimal places in millions = ${price_millions:.2f} million\"\n ]\n \n answer = f\"${price_millions:.2f} million\"\n \n return question, lines, answer\n"}
22
+ {"tid": "ca1016555b", "cat": "probability", "code": "import random\nimport math\n\ndef make(rng, original=False):\n if original:\n question = ('David Linde is curating a special exhibition and has selected 12 distinct artifacts. '\n 'If he randomly arranges 5 of these artifacts in a row for display, what is the probability '\n 'that a specific artifact, the \"Linde Vase,\" is included in the display?')\n lines = [\n \"Total arrangements of 5 artifacts from 12 is P(12, 5)\",\n \"P(12, 5) = 12 \u00d7 11 \u00d7 10 \u00d7 9 \u00d7 8\",\n \"Favorable arrangements include the Linde Vase in one of 5 positions\",\n \"Remaining 4 positions are filled by 4 artifacts from the remaining 11\",\n \"Number of favorable arrangements is 5 \u00d7 P(11, 4)\",\n \"P(11, 4) = 11 \u00d7 10 \u00d7 9 \u00d7 8\",\n \"Favorable arrangements = 5 \u00d7 11 \u00d7 10 \u00d7 9 \u00d7 8\",\n \"Probability = (5 \u00d7 11 \u00d7 10 \u00d7 9 \u00d7 8) / (12 \u00d7 11 \u00d7 10 \u00d7 9 \u00d7 8)\",\n \"Cancel 11 \u00d7 10 \u00d7 9 \u00d7 8 from numerator and denominator\",\n \"Probability = 5 / 12\",\n ]\n return question, lines, \"5/12\"\n\n # Parameters: total items n, selected k, specific item name\n n = rng.randint(6, 15)\n k = rng.randint(2, min(5, n - 1))\n # Ensure k < n so that the specific item can be included and the probability is non-trivial\n if k >= n:\n return None\n\n # Generate a random name for the specific artifact\n names = [\n \"the Ancient Urn\", \"the Jade Figurine\", \"the Obsidian Idol\", \"the Bronze Mask\",\n \"the Crystal Sphere\", \"the Silver Chalice\", \"the Marble Bust\", \"the Golden Crown\",\n \"the Ivory Carving\", \"the Terracotta Horse\", \"the Amethyst Ring\", \"the Emerald Pendant\",\n ]\n specific_name = rng.choice(names)\n\n # Compute probability: k/n\n # Use fractions to get exact simplified form\n from fractions import Fraction\n prob = Fraction(k, n)\n answer = f\"{prob.numerator}/{prob.denominator}\"\n\n # Build question with slight wording variation\n phrasings = [\n f\"{specific_name} is included in the display\",\n f\"the display contains {specific_name}\",\n f\"{specific_name} appears among the displayed items\",\n f\"one of the displayed items is {specific_name}\",\n ]\n question = (f\"A museum curator has selected {n} distinct artifacts for a special exhibition. \"\n f\"If {k} of these artifacts are randomly arranged in a row for display, \"\n f\"what is the probability that {rng.choice(phrasings)}?\")\n\n # Build solution lines\n lines = [\n f\"Total arrangements of {k} artifacts from {n} is P({n}, {k})\",\n f\"P({n}, {k}) = \" + \" \u00d7 \".join(str(n - i) for i in range(k)),\n f\"Favorable arrangements include {specific_name} in one of {k} positions\",\n f\"Remaining {k - 1} positions are filled by {k - 1} artifacts from the remaining {n - 1}\",\n f\"Number of favorable arrangements is {k} \u00d7 P({n - 1}, {k - 1})\",\n f\"P({n - 1}, {k - 1}) = \" + \" \u00d7 \".join(str(n - 1 - i) for i in range(k - 1)),\n f\"Favorable arrangements = {k} \u00d7 \" + \" \u00d7 \".join(str(n - 1 - i) for i in range(k - 1)),\n f\"Probability = ({k} \u00d7 \" + \" \u00d7 \".join(str(n - 1 - i) for i in range(k - 1)) + \") / (\" + \" \u00d7 \".join(str(n - i) for i in range(k)) + \")\",\n f\"Cancel \" + \" \u00d7 \".join(str(n - 1 - i) for i in range(k - 1)) + \" from numerator and denominator\",\n f\"Probability = {k} / {n}\",\n ]\n\n return question, lines, answer\n"}