ITT: Fibonacci

edited 2013-03-19 05:48:30 in General
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597,
2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418,
317811, 514229, 832040, 1346269 u.s.w.

Comments

  • Touch the cow. Do it now.
    I think I've seen this before
  • Not a hybrid rabbit-skink spirit
    fibonacci :: [Integer]
    fibonacci = 0 : 1 : zipWith (+) fibonacci (tail fibonacci)

    isFibonacci
    isFibonacci :: Integer -> Bool
    isFibonacci x = fibonacciCheck x 0

    fibonacciCheck :: Integer -> Integer -> Bool
    fibonacciCheck x y
    | x < z = False
    | x == z = True
    | otherwise = fibonacciCheck x (y + 1)
    where z = fibonacci !! fromIntegral y

Sign In or Register to comment.