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

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:

$"++,grep{$.=$"+$^,print$.,$/;$^=$",$"=$.}$[..0x10

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


Comment on Re: Fibonacci Sequence
Select or Download Code
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 oeis.org/A000040 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020822]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-12-18 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (51 votes), past polls