Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Fibonacci golf with one state variable

by JavaFan (Canon)
on Oct 05, 2008 at 11:43 UTC ( #715421=note: print w/replies, xml ) Need Help??


in reply to Fibonacci golf with one state variable

Without eval, without quotes, without explicit assignment and without arithmetic:
perl -lE 's//:o/;say length$1 while s/(.*):(.*)/$2:$1$2/'

Replies are listed 'Best First'.
Re^2: Fibonacci golf with one state variable
by aufflick (Deacon) on Oct 05, 2008 at 11:54 UTC

    Hey that's neat! Of course the memory usage is far from constant, but great idea. Good use of say to save a few.

    Only nitpicks are that you do have explicit initialisation and the first output is zero which is not quite right. Oddly, I get no output unless I tweak it to print to STDERR which is some strange buffering difference - no idea why.

    ++ for thinking laterally :)

      Well, I'd argue that *not* outputting zero isn't quite right. Usually, the Fibonacci sequence is defined as F(0) = 0; F(1) = 1; F(n) = F(n-1) + F(n-2), n > 1. See for instance Sloane: The On-Line Encyclopedia of Integer Sequences and Graham, Knuth and Patashnik in Concrete Mathematics. Eric Weisstein defines the sequence as starting with F(1) = F(2) = 1 and then states it's conventional to define F(0) = 0.
        Can't fault your references!
Re^2: Fibonacci golf with one state variable
by ikegami (Pope) on Oct 05, 2008 at 12:18 UTC

    Heh! I had come up with exactly that! It's not shorter, though. And boy does it get slow fast.

    Save a char by dropping the "l" in "-lE".
    Save a char by dropping the space after "-E".

Re^2: Fibonacci golf with one state variable
by ambrus (Abbot) on Oct 15, 2009 at 17:39 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://715421]
help
Chatterbox?
[erix]: it has TOP, IIRC
[Corion]: erix: Ah. I use where 1 = 0 for queries where I only am interested in the structure ;)
[erix]: 1=0 is as short as TOP :)
[erix]: "code of someone that died" -- kinda nice if your code stops working too
[erix]: hard to implement, hmm
[Corion]: erix: Well, they also seem to have changed the server, or some software, or whatever, and seem to be in the process of changing the DB schema from having the "username" as primary key to something else.
[Corion]: Far too many things being done at once, or maybe only now has it become apparent that nobody knows that piece of software anymore

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-01-23 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (192 votes). Check out past polls.