This idea can be

generalized.

Noung's writeup will allow you to solve any number sequence puzzle where the numbers are on a straight line (a first-order polynomial) or a parabola (a second-order polynomial), respectively.

Using Lagrange interpolation, any number sequence puzzle can be solved by fitting a polynomial of degree n-1 through the n numbers given. You can even prove your solution correct!

However, a polynomial may not always be the best fit - for instance, for the number sequence `1, 2, 1, 2, 1`

the 'obvious' next number is `2`

, but the underlying function that alternates between 1 and 2 is not a polynomial, and Lagrange interpolation will produce a different result. This can be solved by using an even more general method of interpolation that allows arbitrary functions to be fit onto the given points. But it seems more appropriate to discuss this under the more descriptive title "How to solve any number sequence puzzle".