in reply to Re: Golfing a fibonacci number generator
in thread Golfing a fibonacci number generator

@@=(1,1);push(@@,$@[0]+$@[1]),print(shift@@)for(1..20)
condenses to
@@=(1,1);$@[2]=$@[0]+$@[1],print shift@@for 1..20

For an extra character, you can print all 20 genereated fibs, instead of just 18:
@@=(1,1);push@@,$@[-2]+$@[-1]for 1..20;print for@@

Replies are listed 'Best First'.
Re^3: Golfing a fibonacci number generator
by cLive ;-) (Prior) on Nov 03, 2006 at 23:50 UTC
    let's chop another 6 chars off that: @x=(1);push@x,$x[-2]+$x[-1]for 1..21;print@x

      All your numbers are all concatened together, even with perl -l. I avoided that.

      Anyway, found something shorter still (42):
      print$@[@@]=$@[-1]+$@[-2]for(@@=(1,0))..21

      The following are my different solutions, all generating the same output under perl -l (except where noted):

      sub{$_[2]=$_[0]+$_[1],print shift for 1..20}->(1,1) #51 @@=(1,1);push@@,$@[-2]+$@[-1]for 1..18;print for@@ #50 @@=(1,1);$@[2]=$@[0]+$@[1],print shift@@for 1..20 #49 @@=(1,0);print$@[@@]=$@[-1]+$@[-2]for 1..20 #43 print$@[@@]=$@[-1]+$@[-2]for(@@=(1,0))..21 #42 Missing first "1": print$@[@@]=$@[-1]+$@[-2]for(@@=1)..19 #38 Loops forever: @@=(1,0);print$@[@@]=$_+$@[-1]for@@ #35 Missing first "1" and loops forever: @@=1;print$@[@@]=$_+$@[-2]for@@ #31