Perl: the Markov chain saw PerlMonks

### Re: Fibonacci Sequence

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

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

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 (Monsignor) 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

Create A New User
Node Status?
node history
Node Type: note [id://1020822]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2018-06-17 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (107 votes). Check out past polls.

Notices?