Haskell学习3

Problem 1:Define
fib n = fst (fib1 n (0, 1))
where
fib1 0 (a, b) = (a, b)
fib1 n (a, b) = fib1 (n-1) (b, a + b)
Show by induction on n that evaluating fib n yields the n-th Fibonacci number Fn.

--Problem 1:fib
--Name:Wenqi Sun
--Student ID:2010202521

--fib
fib n=fst(fib1 n (0,1))
      where
        fib1 0 (a,b)=(a,b)
        fib1 n (a,b)=fib1 (n-1) (b,a+b)


Problem 2:We have shown in class that fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
describes the sequence (Fn)n∈N of Fibonacci numbers. Develop a similar description for the factorial. Hence you are requested to produce an infinite list fact such that fact!!n = n! for n≥0.

--Problem 2:fact
--Name:Wenqi Sun
--Student ID:2010202521

--fac
fac(0)=1
fac(1)=1
fac(n)=n*fac(n-1)

--fact
fact=[fac(n)|n<-[0..]]


你可能感兴趣的:(haskell,Class,2010)