5 ms·
I, for one, prefer recursion to explicit iteration in most cases. Anyway, if you were going to write the answer in Haskell, it's a three-liner and it's recursiv
by Smaug123 6y ago
I, for one, prefer recursion to explicit iteration in most cases. Anyway, if you were going to write the answer in Haskell, it's a three-liner and it's recursive.
- eru 6y agoWhy do you need so many lines? fib = 1 : zipWith (+) (0 : fib) fib
- exdsq 6y agoBecause the three liner is easier to read
- eru 6y agoBtw, which three-liner do you mean?
- deleted 6y ago[deleted]
- exdsq 6y agofib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2)
- eru 6y agoOh, that version takes exponential time to compute. The one-liner I gave computes up to the n-th Fibonacci number in linear time.