Solving/teaching Python to solve Number Series
<p>Is there a better way of solving Number Series questions using Python other than teaching it basic pattern rules and hoping the rules fit the question? For example. we would have a list of functions that has a rule for each of them and see if the series fits. Is there a Library that does this, and if not am I stuck writing functions every time a new pattern comes along?</p>

<pre><code>given_series = #random series 

def maybe_fib(series):
    #solve the fib
    throw error if wrong

def add_iterating_numbers(series):
    #solve the series
    throw error if wrong

.
.
.
.
.


list_of_possible_match = [maybe_fib, add_iterating_numbers, . . . ,  #list like fib, adding prime, taking the first 3 numbers and doing somethign with it]

for each_method in list_of_possible_match:
    try:
        each_method(given_series)
    catch error:
        print("didn't work out try another one")

if all_fail:
    #teach me new function/method?
</code></pre>

<p>Number Series is basically a series of numbers and you have to find the next number that follows up. They can range from simple math patterns, to counting the number of corners in a number like '7' would be 1. </p>

<p>Examples of Number Series:</p>

<p>1 1 2 3 5 8 13 21 34 55 89 (?) - The next number would be 144</p>

<p>1 2 4 7 11 16 (?) - The next number would be 22 </p>

<p>Consider using the <a href="http://oeis.org" rel="nofollow">OEIS</a>. It is a huge database of sequences the you can check against. I would say, because it probably doesn't have every possible arithmetic progression etc., you would get the best coverage by writing a program that checks basic sequences (trying to find common differences or quadratic differences etc.) and if nothing works, to check against the database. </p>

<p>I'm not sure whether the OEIS has any kind of api, but you may find <a href="http://stackoverflow.com/questions/5991756/programmatic-access-to-on-line-encyclopedia-of-integer-sequences">this</a> helpful.</p>

<p>Wolfram also has a <a href="http://www.wolframalpha.com/widgets/view.jsp?id=8e63b780a72059bb82ab69ee51cff12d" rel="nofollow">widget</a> that attempts this but it has very limited uses.</p>

<p>You should post a link to your code in a comment if you manage to finish it. It sounds like a cool program; I'd love to see it :)</p>

python