[Haskell-cafe] origin of my fibonacci test
yoyoyonny at gmail.com
Tue May 10 00:08:46 UTC 2016
I suppose this is where you got the code from?
It's the sixth result of the Google search "haskell: get if a number is a
On May 10, 2016 1:59 AM, "Michael Litchard" <michael at 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)
> (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 at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe