Talk:Fibonacci sequence: Difference between revisions

m (→‎Optional credits: changed wording in table. -- ~~~~)
Line 105:
:There seems to be enough in your proposal for a new task maybe called "Fibonacci-like sequences generator" in which the starting numbers/numbers of past numbers to sum to form the next, could be set.
:It would also be good to maybe confirm some of the Lucas/Fibonacci identities mentioned in the Lucas wp article. --[[User:Paddy3118|Paddy3118]] 20:33, 24 May 2012 (UTC)
 
===[http://mathworld.wolfram.com/Fibonaccin-StepNumber.html Fibonacci n-Step Numbers]===
The name is from Mathworld. I doodled the following:
<lang python>>>> def fiblike(start):
addnum = len(start)
def fibber(n):
try:
return fibber.memo[n]
except:
ans = sum(fibber(i) for i in range(n-addnum, n))
fibber.memo.append(ans)
return ans
fibber.memo = start[:]
return fibber
 
>>> f = fiblike([1,1])
>>> [f(i) for i in range(10)]
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> l = fiblike([2,1])
>>> [l(i) for i in range(10)]
[2, 1, 3, 4, 7, 11, 18, 29, 47, 76]
>>> f3= fiblike([1,1,2])
>>> [f3(i) for i in range(10)]
[1, 1, 2, 4, 7, 13, 24, 44, 81, 149]
>>> f4 = fiblike([1,1,2,4])
>>> [f4(i) for i in range(10)]
[1, 1, 2, 4, 8, 15, 29, 56, 108, 208]
>>> f5 = fiblike([1,1,2,4,8])
>>> [f5(i) for i in range(10)]
[1, 1, 2, 4, 8, 16, 31, 61, 120, 236]
>>> f6 = fiblike([1,1,2,4,8,16])
>>> [f6(i) for i in range(10)]
[1, 1, 2, 4, 8, 16, 32, 63, 125, 248]
>>> f7 = fiblike([1,1,2,4,8,16,32])
>>> [f7(i) for i in range(10)]
[1, 1, 2, 4, 8, 16, 32, 64, 127, 253]
>>> </lang>
 
I will try and write a task, although I have flu so it could be interesting! --[[User:Paddy3118|Paddy3118]] 21:12, 24 May 2012 (UTC)
Anonymous user