0

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?

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?

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.

Examples of Number Series:

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

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

MooingRawr
  • 4,901
  • 3
  • 24
  • 31
  • 1
    Your question is too broad, are you trying to solve a specific problem or ALL the possible series ? if the former: then yes, should be relatively easy to implement. If the latter - I don't think that there's such an option because there are infinite numbers of possible results. – Nir Alfasi Sep 01 '16 at 17:27
  • @alfasin, I think it's the broadness of the question, I'm not trying to cover just one series but as many as possible. I know that would be impossible or rather near it since people can make their own, but I would like to try and cover as many as possible. Is what I'm trying the only way? – MooingRawr Sep 01 '16 at 17:29
  • @levi, editted the question with what I tried (I'm out and I don't have exact code on my but that's the general idea – MooingRawr Sep 01 '16 at 17:29
  • https://www.khanacademy.org/math/cc-third-grade-math/cc-3rd-mult-div-topic/cc-3rd-grade-properties-patterns/v/practice-finding-patterns-in-numbers – Rockybilly Sep 01 '16 at 17:32
  • Honestly, the simplest solution would be to write a script that checks them in the [OEIS](http://oeis.org). There is no general way to solve for all the infinitely possible types of sequences there may be; your best bet is to check a huge database like the one linked. – gowrath Sep 01 '16 at 17:43
  • @gowrath, i think this is what I was looking for. Now time to find out if they have an API or an offline database that's open for downloading. Or I will have have to get permission to ping their database/send post/get packages to their servers.... But thanks. Oh but this database still has holes (can't figure out that second example of mine) guess at the end of the day you have to mix it up. – MooingRawr Sep 01 '16 at 17:53

1 Answers1

0

Consider using the OEIS. 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.

I'm not sure whether the OEIS has any kind of api, but you may find this helpful.

Wolfram also has a widget that attempts this but it has very limited uses.

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 :)

Community
  • 1
  • 1
gowrath
  • 3,136
  • 2
  • 17
  • 32