fix: Correct sequence generation and pattern rule application logic

This commit is contained in:
Andreas Koepf (aider) 2025-01-23 14:00:33 +01:00
parent 46601a2b8a
commit 7f27a2285c

View file

@ -46,7 +46,7 @@ class PatternRule:
def apply(self, sequence: List[int], position: int) -> int:
"""Apply the rule to generate the next number"""
result = sequence[position - 1] # Start with previous number
result = sequence[position] # Start with current number
for op, param in zip(self.operations, self.parameters):
if op == Operation.ADD:
@ -60,8 +60,8 @@ class PatternRule:
elif op == Operation.HALF:
result //= 2 # Integer division
elif op == Operation.PREV_PLUS:
if position > 1:
result += sequence[position - 2]
if position > 0:
result += sequence[position - 1]
return result
@ -180,7 +180,7 @@ class SequenceDataset:
# Generate remaining terms
try:
for i in range(1, num_terms + 1): # +1 for answer
for i in range(num_terms): # Generate terms
next_term = rule.apply(sequence, i)
sequence.append(next_term)