http://www.perlmonks.org?node_id=1021812


in reply to Re: Fibonacci Sequence
in thread Fibonacci Sequence

Loopy short version:

for(++$\;$/<$$;$/=($\+=$/)-$/){print $"}

Now can someone find a similar short expression for oeis.org/A000040 please?

Replies are listed 'Best First'.
Re^3: Fibonacci Sequence
by tobyink (Canon) on Mar 05, 2013 at 14:48 UTC
    $"++;_:while(++$"){$"%$_||next(_)for 2..$"-1;print$",$/}

    Update: trizen has pointed out that this is more efficient:

    $"++;_:while(++$"){$"%$_||next(_)for 2..sqrt$";print$",$/}

    ... but I don't like the two extra keystrokes required. Meanwhile, this solution gives you a minor efficiency boost without any extra nasty keystroke things...

    $"++;_:while(++$"){$"%$_||next(_)for 2..$"/2;print$",$/}
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name