Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
The Fibonacci sequence is the sequence defined by F(0) = 0, F(1) = 1, F(n + 2) = F(n) + F(n + 1). The first few terms are 0, 1, 1, 2, 3, 5, 8.
7
votes
1
answer
558
views
Implement Fibonacci with `iterate`
I implemented the Fibonacci sequence using iterate.
import Data.List
fib :: Int -> Maybe Int
fib n
| n < 0 = Nothing
| otherwise = (fmap (snd . fst)) $ find (\(_,i) -> n == i) (zip res [0..]) …
2
votes
1
answer
370
views
O(n) Fibonacci?
I attempted to write an \$O(N)\$ Fibonacci.
fibMemo :: Integer -> Map Integer Integer -> Integer
fibMemo n map
| n == 0 = 0
| n == 1 = 1
| otherwise = case maybeMember of Just x -> x
…
2
votes
2
answers
2k
views
Tail Recursive Fibonacci
Please critique my implementation of a tail-recursive method for generating the Fibonacci sequence:
def fib(n: Int): Option[Int] = {
@tailrec
def go(count: Int, prev: Int, acc: Int): Option[I …