Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: fibo's 66 chars

by pepik_knize (Scribe)
on May 26, 2009 at 05:28 UTC ( #766127=note: print w/replies, xml ) Need Help??

in reply to fibo's 66 chars

I agree, very nice. If you're golfing this, I have a few reductions for you:

You can save yourself a couple of characters by using pop instead of shift.

Also, if you use -l, you can get rid of the quotes and newline:

Then, you can cut down the while$#b<$a by using for(2..$a):

Of all the causes that conspire to blind
Man's erring judgment, and misguide the mind,
What the weak head with strongest bias rules,
Is pride, the never-failing vice of fools.
-- Pope.

Replies are listed 'Best First'.
Re^2: fibo's 66 chars
by Roy Johnson (Monsignor) on May 27, 2009 at 21:17 UTC
    Since you only use the parameter once, it's cheaper to just reference it as $ARGV[0] pop it inline rather than assign it to anything.
    @b=(0,1);push@b,$b[-2]+$b[-1]for 2..pop;print$b[-2]
    You can save fourteen more strokes (and, irrelevantly, memory) by not using an array and using convoluted scalar assignment with a variable that is pre-initialized:
    $b=1;$?=($b+=$?)-$?for 2..pop;print$?

    Caution: Contents may have been coded under pressure.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://766127]
and the daffodils sway...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2017-11-18 03:01 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (277 votes). Check out past polls.