Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Fibo Golf challenge on 3 monkeys

by chargrill (Parson)
on Jul 13, 2007 at 19:40 UTC ( #626522=note: print w/ replies, xml ) Need Help??


in reply to Re: Fibo Golf challenge on 3 monkeys
in thread Fibo Golf challenge on 3 monkeys

A tiny improvement, substituting $/ for "\n":

perl -e '$b-=$a=1;for(A..T){$c=$a;print$a+=$b,$/;$b=$c}'

--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)


Comment on Re^2: Fibo Golf challenge on 3 monkeys
Select or Download Code
Re^3: Fibo Golf challenge on 3 monkeys
by jdalbec (Deacon) on Jul 13, 2007 at 23:02 UTC
    I can shave off a couple characters by leveraging the fact that the length of the sequence is even. Also, the OP's sequence starts with F1=1, so if I start there too I don't have to initialize both variables.
    perl -e '$a=1;for(A..J){print$a+=$b,$/,$b+=$a,$/}'
    Update: Now that the loop is down to 1 statement I can switch to a postfix for. I can also fold the initialization into the loop.
    perl -e 'print$a+=$b||1,$/,$b+=$a,$/for A..J'
    ... and if you feel strongly about starting with F0=0,
    perl -e 'print$a+=$b,$/,$b+=$a||1,$/for A..J'
      perl -le'print$a+=$b,$/,$b+=$a||1for A..J'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://626522]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2015-07-07 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls