list - Fibonacci sequence value in haskell -
how sum of fibonacci sequence using code:
fibs= 0 : 1 : zipwith (+) fibs (tail fibs)
edit: take 5 fibs gives list of [0,1,1,2,3], value of 5th element 3, extract have type : 'last(take(5 fibs))' , 3. , on
if use interpreter seek 5th element list of [ 0, 1, 2, 3] last element same value of 5th element, how last element of list? can 'make' using last
, have ideas, you?
i'm not entirely clear you're asking, if have non-empty non-infinite (i.e., not fibs
but, example, take n fibs
n
) list, can indeed obtain last element applying last
it. alternatively, if want n-th element of list (starting @ 0 , assuming list has @ least n+1 elements), can listname !! n
extract it.
Comments
Post a Comment