Haskell
Calculate the first 5 elements of the list f defined below using successive approximations. Don't count [ ] as one of the 5. If you like, you can cut down on the writing by defining extra variables. E.g., maybe apx1 is the first approximation, apx2 is the second, and so on.
f = (1,1) : [(b,a+b) | (a,b) <- f]
After the first pass the list will be
using only the element (1,1)
It becomes [(1,1),(1,1+1)]
After the second pass it becomes [(1,1),(1,2),(2,2+1)]
After the third pass it becomes [(1,1),(1,2),(2,3),(3,5)]
After the 4th pass it becomes [(1,1),(1,2),(2,3),(3,5),(5,8)]
which can be verified from terminal also
Do give a thumbs up and in case there are doubts leave a comment.
Get Answers For Free
Most questions answered within 1 hours.