I'm stuck in the airport in Baltimore waiting for my flight home. Normal people read magazines or books or stare off blankly into space. Me? I write one-liners to generate the fibonacci sequence.
print$,and$_||=!$!and$\=$/and print and($,,$_)=($,+$_,2*$_+$,)while$;

Replies are listed 'Best First'.
Re: One line Fibonacci generator
by davidrw (Prior) on Jul 17, 2006 at 03:38 UTC
    some other solutions:

    On a related note, I have a pdf titled "Perlgolf History" (first page is a big image of a squaking ostrich if anyone knows of it) -- i don't remember where I d/l'd it from and at the moment w/just a brief google search I can't find it..

    But anyways, in its "Terje's PGAS season 0" section, it covers "Modular Fibonacci" (note that 2m is '2<super>m</super>'):
    5.12. Modular Fibonacci
    http://terje2.perlgolf.org/~pgas/score.pl?func=rules&hole=12&season=0 The game started 2002-10-21 21:30:00 and ended 2002-10-27 19:00:00. 5.12.1. Rules The Fibonacci numbers (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...) are defi +ned by the recurrence: F1 = 1 F2 = 1 Fi = Fi-1 + Fi-2 for i > 2 Write a program which calculates Mn = Fn mod 2m for given pair of n an +d m. 0 < n < 10000 and 0 < m < 20 . Note that a mod b gives the remainder when a is divided by b. Input consists of one newline-terminated line specifying a pair of n a +nd m separated by a space. Output should be corresponding Mn, and a newline. Sample Input 11 7 Sample Output 89
    5.12.2. Solutions
    38, mtve (rejected) -p $\=$.%2**$'%[$.+=$\].$/for/ /..$`}{ 39, mtve (rejected) -pl $_=$.%2**$'%[$.+=$_]for($_=!/ /)x$` 39, ton (post-mortem) -p $\=$.%2**$'+!($.+=$\).$/for/ /..$`}{ 40, mtve (post-mortem) -pl $_=$.%2**$'+!($.+=$_)for($_=!/ /)x$` 40, ton (rejected) -lp $_=$b%2**$'%[$b+=$_]for(/ /+0)x$`,$_ 41, ton -lp $a=$_+0+($_=$a%2**$')for(/ /+0)x$_,$_ 42, mtve -pl $_=$b%2**$'+!($b+=$_)for($_=/ /)x$`,$_ 42, tybalt89 -lp $_="$."+($.=$_)&2**$'-1for($_=!/ /)x$` 43, andys -pl eval'$_=(/ /||~~$~+($~=$_))%2**$\';'x$_ 43, p.kailasa -lp ($_)=($}%2**$',$}+=$_)for($_=/ /)x$`,$_ 45, Peter Haworth -lp ($.,$;)=($.+$;&2**$'-1,$.)for/ /..$_;$_=$ 46, m.wrenn -lp $_=/ /;$_=(($i+=$_)-$_)%2**$' until$k++>$` 46, terje -pl ($_,$b)=(($_+$b)%2**$',$_)for($_=/ /)x~-$` 46, Petri Mikkelä -pl ($i,$.)=($.,($i+$.)%2**$')for/ /..$`;$_=$i 46, terje (alternative) -pl ($_,$b)=($b%2**$',$_+$b)for($_=/ /)x($`+1) 46, Wesley Darlington -apl $.=(($,+=$.)%=1<<$F[1])-$.while$_--;$_=$, 46, Wesley Darlington (alternative) -apl map$.=(($,+=$.)%=1<<$F[1])-$.,1..$_;$_=$, 46, Jasper -lp $;=(0+$b+($b=$;)||1)%2**$' for/ /..$`;$_=$ 47, Honza Pazdziora -alp $_=1;$_=(($.+=$_)-$_)%2**$F[1]while--$F[0] 48, sorrow -lp / /;map$;=(0+$b+($b=$;)||1)%2**$',1..$`;$_=$ 48, brohm -lp $;=$k%2**$',$k+=$m,$m=$;for($k=/ /)..$`;$_=$ 48, Wladimir Palant -pal $_=1;$_=(-$a-($a=-$_))%2**$F[1]while--$F[0] 49, tinita -lnap $_=1;$_=($y/1+($y=$_))%2**$F[1]while--$F[0] 49, banshee -lp $b=1;($a,$b)=($b%2**$',$a+$b)for/ /..$`;$_=$a 50, zxc -lp $a=/ /;($a,$b)=($b%2**$',$a+$b)for 0..$`;$_=$a 51, m.thelen -lpa $_=1;($_,$^F)=($^F%2**$F[1],$_+$^F)while--$F[0]>1 52, FatPhil -pl $r=/ /;($l,$r)=($r%(1<<$'),$l+$r)for 1..$`;$_=$l 68, tinita (alternative) -lnap $s=1;$s=~s/.*/(($x=$y)+($y=$&))%2**$F[1]/efor 0..$F[0]-2;$_=$s
Re: One line Fibonacci generator
by liverpole (Monsignor) on Jul 16, 2006 at 23:14 UTC
    The world needs more one-line Fibonacci sequence generators, especially obfuscated ones!

    ++Very nice!


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      Not sure if this is obfuscated (actually I'm pretty sure it isn't) but here's one:
      ++$*;while(1){($_,$*)=($_+$*,$_);print;} #By fatalserpent; code in Public Domain
      I'm also a bit worried that it goes dry in less than a second... number generation justs stops..., it says it's reached infinity. Is this a problem with the code, or is my CPU just too fast?