views:

112

answers:

2

Say the input will always be the same number N of numbers (e.g., 5) and assume the integers actually have a mathematical relation (no lengths of the numbers 'one', 'two', days in the nth month, etc.). The output would be either the next integer and the rule discovered or a message that no rule could be detected. I was thinking to have in one-two-three order, a module that tries to find arithmetic sequence rules by doing sums and/or differences between numbers adjacent, one away, two away, etc. looking for patterns, then having a module focused on geometric sequences by multiplying and/or dividing in the same way, and then, if there is a general approach, a module for detecting recursive sequences.

Thanks!

+6  A: 

The On-Line Encyclopedia of Integer Sequences solves precisely this problem :-)

aioobe
+1: I do get the impression it's just a database though especially as you can submit a sequence.
Troubadour
I stuck in my lottery numbers I re-use each week and it was stumped. Probably because I haven't won yet.
Troubadour
@Troubadour, rofl!
aioobe
Ha, they even have the Lost Numbers. Enter 4 8 15 16 23 42
Pete
Yeah it is a database. They don't have any 'magic' going on!
Moron
+3  A: 

Given any sequence of numbers, we can come up with a formula which 'fits'!

Given a1, a2, ..., an

All you need to do is find an n-1 degree polynomial (using Polynomial interpolation) so that

P(i) = ai

and that's it, you have a formula. Polynomial interpolation can be as easy as solving a matrix equation Ax = b (with A being a Vandermonde matrix).

Check out: http://en.wikipedia.org/wiki/Polynomial_interpolation

That is one of the reasons I find these 'guess the next number' problems a bit silly (read: pathetic IQ tests). Not everyone thinks the same way.

Moron
+1: Good point. Given a list of integers there is no absolute, correct answer to "What is the next number in the sequence?".
Troubadour
But the polynomial has n parameters. You could just as well say "P(i)=ai for i<=n, P(i)=0 for i>n". A better question is "what formula produces this sequence with the fewest obvious ways you could tweak it to produce a different sequence?"
Beta
@Beta: 'fewest obvious' is a very subjective term and is meaningless to a computer which needs to come up with a formula. Maybe you can define it and give it more meaning...
Moron