Files
2025-05-23 22:01:00 +08:00

1.9 KiB

Cryptarithm

Task Description

Cryptarithm is a mathematical puzzle where letters represent digits, and different letters represent different digits. Players need to find the correspondence between letters and digits to make the equation true.

Example

Given: SEND + MORE = MONEY Each letter represents a digit (SEND, MORE each represent a four-digit number; MONEY represents a five-digit number), and no two letters represent the same digit. To make the equation true, find the numerical equation.

Answer: 9567 + 1085 = 10652

Code Logic

Generation Logic

  1. Randomly select num_letter digits (between 1-9)
  2. Randomly choose an operator (based on operator_level: 1=addition/subtraction, 2=addition/subtraction, 3=addition/subtraction/multiplication)
  3. Randomly generate numbers on the left side of the equation, then calculate the result
  4. Check if the number of different digits in the equation equals num_letter
  5. Verify that the equation has a unique solution
  6. Randomly replace digits with letters to create the problem

Verification Logic

Verify whether the numerical equation extracted from the model's answer is correct.

Answer Extraction Logic

Extract the final numerical equation from the model's answer, supporting various formats:

  • Chinese format: 答案是:1234 + 5678 = 6912
  • English format: The answer is: 1234 + 5678 = 6912
  • Direct equation format: 1234 + 5678 = 6912

Parameter Description

  • num_letter: Number of different letters in the equation (between 1-9)
  • operator_num: Number of calculations in the equation
  • operator_level: Difficulty level of operators (1=addition/subtraction, 2=addition/subtraction, 3=addition/subtraction/multiplication)
  • num_of_data: Number of samples to generate
  • max_attempts: Maximum number of attempts for each problem

Usage

# Using default parameters
./run.sh

Generated data will be saved in the data/ directory, organized according to parameter settings.