Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Fibonacci Sequence

by tobyink (Abbot)
on Feb 27, 2013 at 08:41 UTC ( #1020822=note: print w/replies, xml ) Need Help??

in reply to Fibonacci Sequence

Perhaps not especially obscure, but:


Update: A variation, less obfuscated, but more golfy if you have a vaguely modern version of Perl...

# 1 2 3 # 12345678901234567890123456789012345678 perl -E'$a=1;map{$.=$a+$b;$b=$a;say$a=$.}0..71'
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: Fibonacci Sequence
by skunix (Novice) on Feb 27, 2013 at 14:59 UTC
    Today I learned, $/ :D

      Still not as short as yours but here is mine revised:

      $~=$^++;_:$~^=$^ ^=$~^=$^;$_.=($~=$~+$^.$/);($~<$$)?goto _:print

        Loopy version

        for($\=1;$/<1<<7;$\+=$/,$/=$\-$/){print $"}
Re^2: Fibonacci Sequence
by hdb (Prior) on Mar 05, 2013 at 12:01 UTC

    Loopy short version:

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

    Now can someone find a similar short expression for please?

      $"++;_: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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020822]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-02-21 23:50 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (321 votes). Check out past polls.