Hi Michael,
I suppose this is where you got the code from?
https://www.quora.com/What-is-the-most-efficient-algorithm-to-check-if-a-number-is-a-Fibonacci-NumberIt's the sixth result of the Google search "haskell: get if a number is a fibonacci number"
On May 10, 2016 1:59 AM, "Michael Litchard" <michael@schmong.org> wrote:_______________________________________________I have some code that checks to see if a number is a fibonacci number. It's not mine, I got it from somewhere and I need to credit it. I am pretty sure I got it from Stack Exchange but my search for it went nowhere. If this looks familiar to you, or you can tell me better ways to search, please let me know.
isFib :: Integer -> Bool
isFib n = n == a where (_, a, _) = unFib (1, 1) n
unFib :: (Integer, Integer) -> Integer -> (Integer,Integer,Integer)
unFib (a, b) n
| n < a = (0, 0, 1)
| n < e = (2*k, c, d)
| otherwise = (2*k + 1, e, f)
where
(k, c, d) = unFib (fibPlus (a, b) (a, b)) n
(e, f) = fibPlus (a, b) (c, d)
fibPlus :: (Integer, Integer) -> (Integer, Integer) -> (Integer,Integer)
fibPlus (a, b) (c, d) = (bd - (b - a)*(d - c), a*c + bd)
where bd = b*d
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe