def make_problems(n, seed=0): rng = random.random(seed) output = []
for _ in vary(n): t = rng.selection([“discount”, “travel”, “wallet”, “chain”]) if t == “low cost”:unit = rng.selection([40, 60, 80, 120]) amount = rng.selection([5, 6, 8, 10]) disk = rng.selection([10, 20, 25, 50]) whole = unit * amount gold = whole – whole * disc // 100 q = (f”A retailer sells notebooks for {unit} rupees every. You purchase {qty} ” f” notebooks and get {disc}% off the entire value. ” f”What number of rupees do you need to pay in whole?”) elif t == “Journey”: s1, h1 = rng.selection([40, 50, 60]), rng.selection([2, 3]) s2, h2 = rng.selection([30, 45, 70]), rng.selection([1, 2, 3]) gold = s1 * h1 + s2 * h2 q = (f”The automobile drives at {s1} km/h for {h1} hours, then at {s2} km/h ” f” for {h2} hours. What’s the whole distance traveled?”) elif t == “pockets”: tens = rng.selection([3, 5, 7, 9]) 50s = rng.selection([2, 4, 6]) expenditure = rng.selection([50, 80, 110, 150]) gold = 10 * 10 + 50 * 50 – used q = (f”There are {10} 10 rupee notes and 50 rupee ” f” notes. You’ve spent {used} rupees. What number of rupees are left?”) else: x = rng.selection([6, 9, 12, 15]); y = rng.selection([4, 7, 10]); z = rng.selection([3, 8, 11]) gold = x * 2 – y + zq = (f”Begin with the quantity {x}. Double it, then subtract {y}, ” f”Then add {z}. What’s the quantity on the finish?”) out.append({“query”: q, “reply”: gold}) return out all_problems = make_problems(18, seed=42) random.Random(1).shuffle(all_problems) trainset = all issues[:12]
valset = all points[12:]
print(f”Dataset: {len(trainset)} practice / {len(valset)} val problemn”)
for _ in vary(n): t = rng.selection([“discount”, “travel”, “wallet”, “chain”]) if t == “low cost”:unit = rng.selection([40, 60, 80, 120]) amount = rng.selection([5, 6, 8, 10]) disk = rng.selection([10, 20, 25, 50]) whole = unit * amount gold = whole – whole * disc // 100 q = (f”A retailer sells notebooks for {unit} rupees every. You purchase {qty} ” f” notebooks and get {disc}% off the entire value. ” f”What number of rupees do you need to pay in whole?”) elif t == “Journey”: s1, h1 = rng.selection([40, 50, 60]), rng.selection([2, 3]) s2, h2 = rng.selection([30, 45, 70]), rng.selection([1, 2, 3]) gold = s1 * h1 + s2 * h2 q = (f”The automobile drives at {s1} km/h for {h1} hours, then at {s2} km/h ” f” for {h2} hours. What’s the whole distance traveled?”) elif t == “pockets”: tens = rng.selection([3, 5, 7, 9]) 50s = rng.selection([2, 4, 6]) expenditure = rng.selection([50, 80, 110, 150]) gold = 10 * 10 + 50 * 50 – used q = (f”There are {10} 10 rupee notes and 50 rupee ” f” notes. You’ve spent {used} rupees. What number of rupees are left?”) else: x = rng.selection([6, 9, 12, 15]); y = rng.selection([4, 7, 10]); z = rng.selection([3, 8, 11]) gold = x * 2 – y + zq = (f”Begin with the quantity {x}. Double it, then subtract {y}, ” f”Then add {z}. What’s the quantity on the finish?”) out.append({“query”: q, “reply”: gold}) return out all_problems = make_problems(18, seed=42) random.Random(1).shuffle(all_problems) trainset = all issues[:12]
valset = all points[12:]
print(f”Dataset: {len(trainset)} practice / {len(valset)} val problemn”)


