Predict the Next Draft Token Count
Context
A document-processing pipeline tracks token counts for the first two versions of an automatically expanded draft. Later versions follow a fixed recurrence, so the archive team wants to predict the count at a requested version without storing every earlier count.
Problem
The first two draft versions have token counts initial_terms[0] and initial_terms[1], corresponding to positions 0 and 1. For every position n at least 2, the count is defined as twice the count at position n-1 plus the count at position n-2. Return the count at position index. Compute the sequence forward from the two supplied initial counts; do not treat the input list as a complete sequence. Position 0 and position 1 must return their supplied values directly. The requested index is always valid and nonnegative.
Examples
index = 0initial_terms = [3, 5]3index = 1initial_terms = [2, 7]7index = 5initial_terms = [4, 6]222Constraints
2 <= len(initial_terms) <= 20 <= initial_terms[i] <= 1000 for every i0 <= index <= 30- Types:
initial_termsis int[],indexis int; result is int
Function signature
def predict_token_count(initial_terms: list[int], index: int) -> int
initial_termslist[int]- The token counts at draft positions 0 and 1, in order.
indexint- The zero-based draft position whose token count is requested.
- returns int
- The token count at the requested draft position under the stated second-order recurrence.
Adapted from MBPP problem task_169 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- The recurrence uses the two immediately preceding positions.
- Python integer arithmetic is suitable for the permitted range.