Brainbench perl test?
Peter Sergeant
pete at clueball.com
Wed Sep 5 19:36:14 BST 2012
On Wednesday, September 5, 2012, Paul Makepeace wrote:
> On Wed, Sep 5, 2012 at 9:35 AM, Abigail <abigail at abigail.be <javascript:;>>
> wrote:
> > Your first instinct should be "Is there a generating function I can
> use?".
>
> Try not to blow your cache pipeline with all that silly branching,
>
> sub fib {
> my $n = shift;
> int(0.5 + (0.5+0.5*sqrt 5) ** $n / sqrt 5);
> }
>
> High five! :-)
>
My favourite, especially given that:
"Given that fib(n) is equal to fib(n-1) + fib(n-2)"
... in its current form arguably simplifies to fib(n) = ⊥
More information about the london.pm
mailing list