Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

One line Fibonacci generator

by jimt (Chaplain)
on Jul 16, 2006 at 22:02 UTC ( [id://561606]=obfuscated: print w/replies, xml ) Need Help??

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
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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://561606]
Approved by Hue-Bond
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2024-04-23 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found