Skip to content

Commit

Permalink
swapped out symbols for numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
joesharratt1229 committed Mar 4, 2025
1 parent 6307adc commit cd02e7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion reasoning_gym/games/puzzle24.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ def __getitem__(self, idx: int) -> dict:
expr, numbers, syms = self._generate_candidate_expression(rng, 4)
if expr.subs({sym: num for sym, num in zip(syms, numbers)}) == 24:
break
expr_str = str(expr)
for i, sym in enumerate(syms):
expr_str = expr_str.replace(str(sym), str(numbers[i]))

question = QUESTION_TEMPLATE.format(
numbers=", ".join(map(str, numbers)), operators=", ".join(self.config.operators)
)
return {
"question": question,
"answer": str(expr),
"answer": expr_str,
"metadata": {
"numbers": numbers,
"expression": expr,
Expand Down
12 changes: 11 additions & 1 deletion tests/test_puzzle24.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ def test_puzzle24_basic_properties():
assert num_str in item["question"]


def test_puzzle24_score_answer():
def test_puzzle24_score_answer_correct():
"""Test the score_answer method for correct answers"""
config = Puzzle24Config(seed=42)
dataset = Puzzle24Dataset(config)
for item in dataset:
answer = item["answer"]
print(item)
assert dataset.score_answer(answer, item) == 1.0


def test_puzzle24_score_answer_individual():
"""Test the score_answer method"""
config = Puzzle24Config(seed=42)
dataset = Puzzle24Dataset(config)
Expand Down

0 comments on commit cd02e7d

Please sign in to comment.