mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-25 17:10:51 +00:00
refactor: Simplify LCM number generation with break and single return
This commit is contained in:
parent
20069b2a7d
commit
71b13cda07
1 changed files with 5 additions and 7 deletions
|
|
@ -43,17 +43,15 @@ class LCMDataset(ProceduralDataset):
|
|||
def calculate_product(nums: List[int]) -> int:
|
||||
return reduce(lambda x, y: x * y, nums)
|
||||
|
||||
for _ in range(3): # Try up to 3 times to get LCM < product
|
||||
# Try up to 3 times to get LCM < product
|
||||
for _ in range(3):
|
||||
num_count = rng.randint(self.config.min_numbers, self.config.max_numbers)
|
||||
numbers = [rng.randint(self.config.min_value, self.config.max_value) for _ in range(num_count)]
|
||||
result = reduce(lcm, numbers)
|
||||
if result < calculate_product(numbers):
|
||||
return numbers, result
|
||||
|
||||
# If we failed to find LCM < product after 3 tries, generate one final set
|
||||
num_count = rng.randint(self.config.min_numbers, self.config.max_numbers)
|
||||
numbers = [rng.randint(self.config.min_value, self.config.max_value) for _ in range(num_count)]
|
||||
result = reduce(lcm, numbers)
|
||||
break
|
||||
|
||||
# Return the last generated numbers, whether they met the criteria or not
|
||||
return numbers, result
|
||||
|
||||
def __getitem__(self, idx: int) -> dict:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue