除了教授基本模式规则并希望规则符合问题之外,是否有更好的方法使用Python解决数字系列问题?例如。我们将有一个函数列表,每个函数都有一个规则,并查看该系列是否适合。是否有一个库可以执行此操作,如果不是,我每次出现新模式时都会写入函数吗?
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?
数字系列基本上是一系列数字,您必须找到后续的下一个数字。它们的范围从简单的数学模式到计算像#7; 7'等数字中的角数。将是1.
数字系列的例子:
1 1 2 3 5 8 13 21 34 55 89(?) - 下一个数字是144
1 2 4 7 11 16(?) - 下一个数字是22