Coming up on another great week! We'll start off with a simple one.
Given a number less than 2^30, determine if the number is a Fibonacci Number or not. If it is return true, else false. Bonus points for optimized calculations of the Fibonacci Numbers.
Comments:
safi - 10 years, 7 months ago
reply permalink
Pearce Keesling - 10 years, 7 months ago
Here is an estimate which I hope remains accurate that high, but I'm not sure. The formula is all that really matters, but I wrote it in ruby just to make my life easy.
reply permalink
Pearce Keesling - 10 years, 7 months ago
I realized I hadn't fixed my operators :P.
reply permalink
Karl - 10 years, 7 months ago
Whaaaaaaaat :D.
I don't want to waste your time - I know that's Ruby but could you provide a brief little snippet as to what each thing is for? (why that number, the double asterisk, asterisk minus, etc.)
Thanks :D.
reply permalink
Pearce Keesling - 10 years, 7 months ago
Sorry, I didn't see that for a few days haha. The number is the golden ratio. I totally stole this formula from wolfram alpha. The formula is here, http://www.wolframalpha.com/share/clip?f=d41d8cd98f00b204e9800998ecf8427e2snclf2p88.
Phi is the golden ratio.
the double asterisks are power notation (ruby version of ), the *-1 is just to make n negative.
reply permalink
Anonymous - 10 years, 7 months ago
(from Wikipedia) I guess from Binet's formula one can assert that given a Fibonacci number x , one or both of the expressions 5x2 +4 and 5x2 - 4 should yield a perfect square number.
Reference: http://en.wikipedia.org/wiki/Fibonacci_number#Recognizing_Fibonacci_numbers
Should be pretty simple to implement.
reply permalink
Nick Krichevsky - 10 years, 7 months ago
A bit long, but it works
reply permalink
Anonymous - 10 years, 7 months ago
This is in Clojure.
reply permalink
Pyro - 10 years, 7 months ago
reply permalink
ujjl - 10 years, 7 months ago
Haskell
reply permalink
Jack The Stripper - 10 years, 7 months ago
I had tumbleweed in mind when writing this:
reply permalink
Anonymous - 10 years, 6 months ago
reply permalink