feat: Implement allow_negation to generate both positive and negative numbers in ChainSum

This commit is contained in:
Andreas Koepf (aider) 2025-01-23 12:01:21 +01:00
parent 358829cc60
commit 1ff01627cc
2 changed files with 41 additions and 2 deletions

View file

@ -83,7 +83,12 @@ class ChainSum:
min_value = 10 ** (num_digits - 1) # e.g., 100 for 3 digits
max_value = (10 ** num_digits) - 1 # e.g., 999 for 3 digits
constants = [rng.randint(min_value, max_value) for _ in range(num_terms)]
if self.config.allow_negation:
# Allow both positive and negative numbers in the range
constants = [rng.randint(-max_value, max_value) for _ in range(num_terms)]
else:
# Only positive numbers
constants = [rng.randint(min_value, max_value) for _ in range(num_terms)]
operators = [rng.choice(["+", "-"]) for _ in range(num_terms - 1)]
# Build expression and compute result