I feel tired to do "find the pattern" exercise such as
1 2 3 4 (5) 1 2 4 8 (16) 1 2 3 5 8 (13)
Please write a program that finds the pattern for me.
Here, we define the pattern as a recurrence relation that fits the given input, with the smallest score. If there are multiple answers with the same smallest score, using any one is fine.
Let the \$k\$ first terms be initial terms (for the recurrence relation, etc.), and the \$i\$'th term be \$f(i)\$ (\$i>k,i\in\mathbb N\$).
- A non-negative integer \$x\$ adds\$\lfloor\log_2\max(|x|,1)\rfloor+1\$ to the score
- The current index \$i\$ adds \$1\$ to the score
/(round down or towards zero, as you decide) and
a mod balways equal to
a-b*(a/b)) each add \$1\$ to the score
- For each initial term \$x\$, add \$\lfloor\log_2\max(|x|,1)\rfloor+2\$ to the score
- \$f(i-n)\$ (with \$n\le k\$) adds \$n\$ to the score. E.g. Using the latest value \$f(i-1)\$ add \$1\$ to the score, and there must be at least 1 initial term.
- Changing the calculation order doesn't add anything to the score. It's fine if you write
1 i +,
+(i,1)or any format you like.
input -> [score] expression 1 2 3 4 ->  f(i) = i 1 2 4 8 ->  f(1) = 1, f(i) = f(i-1)+f(i-1) 1 2 3 5 8 ->  f(1) = 1, f(2) = 2, f(i) = f(i-1)+f(i-2)
Shortest program in each language wins. It's fine if your program only solve the problem theoretically.