j-js commited on
Commit
6c64c39
·
verified ·
1 Parent(s): df111d6

Update quant_solver.py

Browse files
Files changed (1) hide show
  1. quant_solver.py +24 -11
quant_solver.py CHANGED
@@ -337,16 +337,20 @@ def solve_percent_question(text: str, help_mode: str) -> Optional[SolverResult]:
337
 
338
  def solve_ratio_question(text: str, help_mode: str) -> Optional[SolverResult]:
339
  lower = text.lower()
 
340
 
341
- m = re.search(
342
  r"ratio of .*? is\s+(\d+)\s*:\s*(\d+).*?total (?:is|of)\s+(\d+(?:\.\d+)?)",
343
- lower,
344
- )
345
- if not m:
346
- m = re.search(
347
- r"(\d+)\s*:\s*(\d+).*?total (?:is|of)\s+(\d+(?:\.\d+)?)",
348
- lower,
349
- )
 
 
 
350
 
351
  if m:
352
  a = float(m.group(1))
@@ -359,23 +363,32 @@ def solve_ratio_question(text: str, help_mode: str) -> Optional[SolverResult]:
359
  first = total * a / parts
360
  second = total * b / parts
361
 
 
 
 
 
362
  if help_mode == "hint":
363
- reply = "Add the ratio parts, then convert each part into a fraction of the total."
364
  elif help_mode == "walkthrough":
365
  reply = (
366
  f"Total parts = {a:g} + {b:g} = {parts:g}.\n"
367
  f"First quantity = {a:g}/{parts:g} × {total:g} = {first:g}.\n"
368
  f"Second quantity = {b:g}/{parts:g} × {total:g} = {second:g}."
369
  )
 
 
370
  else:
371
- reply = f"The two quantities are {first:g} and {second:g}."
 
 
372
 
373
  return SolverResult(
374
  reply=reply,
375
  domain="quant",
376
  solved=True,
377
  help_mode=help_mode,
378
- answer_value=f"{first:g}, {second:g}",
 
379
  )
380
 
381
  return None
 
337
 
338
  def solve_ratio_question(text: str, help_mode: str) -> Optional[SolverResult]:
339
  lower = text.lower()
340
+ choices = extract_choices(text)
341
 
342
+ patterns = [
343
  r"ratio of .*? is\s+(\d+)\s*:\s*(\d+).*?total (?:is|of)\s+(\d+(?:\.\d+)?)",
344
+ r"(\d+)\s*:\s*(\d+).*?total (?:is|of)\s+(\d+(?:\.\d+)?)",
345
+ r"ratio of .*? is\s+(\d+)\s*:\s*(\d+).*?there (?:is|are)\s+(\d+(?:\.\d+)?).*?total",
346
+ r"(\d+)\s*:\s*(\d+).*?there (?:is|are)\s+(\d+(?:\.\d+)?).*?total",
347
+ ]
348
+
349
+ m = None
350
+ for pattern in patterns:
351
+ m = re.search(pattern, lower)
352
+ if m:
353
+ break
354
 
355
  if m:
356
  a = float(m.group(1))
 
363
  first = total * a / parts
364
  second = total * b / parts
365
 
366
+ letter = None
367
+ if choices:
368
+ letter = compare_to_choices_numeric(first, choices)
369
+
370
  if help_mode == "hint":
371
+ reply = "Add the ratio parts, then take that fraction of the total."
372
  elif help_mode == "walkthrough":
373
  reply = (
374
  f"Total parts = {a:g} + {b:g} = {parts:g}.\n"
375
  f"First quantity = {a:g}/{parts:g} × {total:g} = {first:g}.\n"
376
  f"Second quantity = {b:g}/{parts:g} × {total:g} = {second:g}."
377
  )
378
+ if letter:
379
+ reply += f"\nThat matches choice {letter}."
380
  else:
381
+ reply = f"The first quantity is {first:g}."
382
+ if letter:
383
+ reply += f" So the correct choice is {letter}."
384
 
385
  return SolverResult(
386
  reply=reply,
387
  domain="quant",
388
  solved=True,
389
  help_mode=help_mode,
390
+ answer_letter=letter,
391
+ answer_value=f"{first:g}",
392
  )
393
 
394
  return None