Skip to content

Comment on Common Species Of Code

Comments

Closed-form expression [0], good up to n == 71:

   def fibonacci(n):
        gr = (1 + (5**0.5)) / 2 
        return int((gr**int(n) - (-gr)**int(-n)) / 5**0.5)

[0] http://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_ex...

I wanted to mention this as well. There is actually a closed form (as you indicated). Also good to know: This is or was a interview question at Google. You had to know Moivre-Binet's closed formula from the top of your head to pass.

I don't even know what is Moivre-Binet what the fuck.

You had to know Moivre-Binet's closed formula from the top of your head to pass.

What's unfortunate about what you just said is that this is utterly irrelevant as a test of coding or problem solving ability.

See my other comment about MIT 6.00.1x

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.