diff --git a/GALLERY.md b/GALLERY.md index e7ba9238..5aa6fc66 100644 --- a/GALLERY.md +++ b/GALLERY.md @@ -9,6 +9,7 @@ This gallery shows examples from all available datasets using their default conf - [base_conversion](#base_conversion) - [basic_arithmetic](#basic_arithmetic) - [bf](#bf) +- [binary_matrix](#binary_matrix) - [caesar_cipher](#caesar_cipher) - [calendar_arithmetic](#calendar_arithmetic) - [chain_sum](#chain_sum) @@ -751,6 +752,98 @@ Metadata: {'bfit_code': '\nint main() {\n print("under");\n}\n', 'bf_program' ```` +### binary_matrix +Generates Binary Matrix exercises with configurable difficulty + +Default configuration: +```python +max_n = 10 +p_zero = 0.25 +size = 500 +seed = 42 +``` + +Example tasks: +```` +Example 1: +Question: Given a square matrix, your job is to find the taxicab distance of the nearest 0 for each cell. + +Example: + +Input: Find the distance to the nearest 0 for each cell in the matrix below: +0 0 0 +0 1 0 +1 1 1 + +Output: +0 0 0 +0 1 0 +1 2 1 + +Find the distance to the nearest 0 for each cell in the matrix below: +0 0 +1 0 + +Answer: 0 0 +1 0 +Metadata: {'matrix': [[0, 0], [1, 0]], 'solution': [[0, 0], [1, 0]]} + +Example 2: +Question: Given a square matrix, your job is to find the taxicab distance of the nearest 0 for each cell. + +Example: + +Input: Find the distance to the nearest 0 for each cell in the matrix below: +0 0 0 +0 1 0 +1 1 1 + +Output: +0 0 0 +0 1 0 +1 2 1 + +Find the distance to the nearest 0 for each cell in the matrix below: +0 + +Answer: 0 +Metadata: {'matrix': [[0]], 'solution': [[0]]} + +Example 3: +Question: Given a square matrix, your job is to find the taxicab distance of the nearest 0 for each cell. + +Example: + +Input: Find the distance to the nearest 0 for each cell in the matrix below: +0 0 0 +0 1 0 +1 1 1 + +Output: +0 0 0 +0 1 0 +1 2 1 + +Find the distance to the nearest 0 for each cell in the matrix below: +1 0 1 1 0 1 1 +1 0 1 1 1 1 1 +1 1 1 1 0 1 1 +1 1 1 1 0 0 1 +0 1 1 1 1 1 0 +1 0 1 1 1 1 0 +1 1 1 1 1 1 1 + +Answer: 1 0 1 1 0 1 2 +1 0 1 2 1 2 3 +2 1 2 1 0 1 2 +1 2 2 1 0 0 1 +0 1 2 2 1 1 0 +1 0 1 2 2 1 0 +2 1 2 3 3 2 1 +Metadata: {'matrix': [[1, 0, 1, 1, 0, 1, 1], [1, 0, 1, 1, 1, 1, 1], [1, 1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 0, 0, 1], [0, 1, 1, 1, 1, 1, 0], [1, 0, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1]], 'solution': [[1, 0, 1, 1, 0, 1, 2], [1, 0, 1, 2, 1, 2, 3], [2, 1, 2, 1, 0, 1, 2], [1, 2, 2, 1, 0, 0, 1], [0, 1, 2, 2, 1, 1, 0], [1, 0, 1, 2, 2, 1, 0], [2, 1, 2, 3, 3, 2, 1]]} + +```` + ### caesar_cipher Generates Caesar cipher encryption/decryption tasks diff --git a/reasoning_gym/algorithmic/binary_matrix.py b/reasoning_gym/algorithmic/binary_matrix.py index 0fbe96b3..8ae122bb 100644 --- a/reasoning_gym/algorithmic/binary_matrix.py +++ b/reasoning_gym/algorithmic/binary_matrix.py @@ -5,14 +5,13 @@ https://leetcode.com/problems/01-matrix/description/ """ from collections import deque -from copy import deepcopy from dataclasses import dataclass from random import Random from typing import Optional from ..factory import ProceduralDataset, register_dataset -QUESTION_TEMPLATE = """Given a square matrix, your job is to find the distance of the nearest 0 for each cell. +QUESTION_TEMPLATE = """Given a square matrix, your job is to find the taxicab distance of the nearest 0 for each cell. Example: @@ -36,7 +35,7 @@ class BinaryMatrixConfig: """Configuration for Binary Matrix dataset generation""" max_n: int = 10 # Maximum size of the matrix - p_zero: float = 0.7 # Probability of a cell being 0 + p_zero: float = 0.25 # Probability of a cell being 0 size: int = 500 # Virtual dataset size seed: Optional[int] = None