33
ClySuva
7y

At a job interview.

Them: Can you please write a function that calculates fibonacci numbers on the whiteboard please.

Me:

fib=_=>($=>$.round(($.pow((1+$.sqrt(5))/2,_)-$.pow(-2/(1+$.sqrt(5)),_))/$.sqrt(5)))(Math)

Comments
  • 3
    The hell is that dollar sign in there for?
  • 0
    Php I think? I'm not a php dev. Also looks like you're calculating some form of approximation of the fib sequence, reference?
  • 1
    I was listening to a podcast recently that mentioned that a lot of people try hard to do something clever that they lose sight of the goal of the code and end up with use case scenario errors or problems with readability...

    Especially the latter.
  • 0
    @Crazed can I ask for the source of such podcast? It sounds interesting
  • 1
    @araxhiel I believe it was the full stack podcast, or one of those more popular ones, in the first episode about CSS. Yeahhh that was definitely it, he spoke of some dev creating massive lists of selectors using mixins for a single style haha
  • 1
    @araxhiel I believe it's "1: Matt Stauffer - CSS Semantics" on fullstack radio
  • 0
    @Crazed LOL 😂 certainly I need to listen that...

    Thanks!
  • 3
    @jmclemo6 for obfuscation. (Hint: $ === Math)

    @alwaysmpe it looked like js to me, then I noticed the tag. It's js.
  • 0
    @shellbug if it is JavaScript the $ is probably jQuery
  • 4
    @alwaysmpe

    actually there is an explicit/closed-form formula for Nth Fibonacci number which does not include recursion.

    after quick googling for proof: http://community.wvu.edu/~krsubrama...
  • 2
    @jmclemo6 it's javascript. $ sign is aliased to Math so you wouldn't have to write Math.pow, Math.sqrt
  • 3
    @alwaysmpe it's the closed form solution for Fibonacci number, aka the Binet's Formula.
  • 0
    Nice.... Most people wont understand this..but it gives you a chance to show them ur mathematical prowess...
  • 2
    To all those who dont get it.. This uses the golden ratio..that is (1+/-sqrt(5))/2..Powers of the golden ratio gives nth fibonacci number..
  • 0
    @aEEEdev fun fact: limit of fibo(n+1)/fibo(n) approaches the golden ratio. It is known. :)
  • 2
    @theCreativeOne no dude, it's Math in this case. $ here is a function argument, and that function is being called with Math.
  • 1
    @shellbug ah, I saw the js tags and dollar signs, thought it was jquery, and immediately thought of this https://stackoverflow.com/a/...
  • 1
    @nukasev I didnt say it was a forbidden secret.. Not many know that golden ratios has got something to do with fibonacci numbers.. By the way ur statement and mine doesnt make much difference..Both are almost the same..
Add Comment