in reply to (Golf) Decorating the Christmas Tree

I've been trimming people's posts down by a couple bytes here and there, and I'd like to explain what I did. I'll use danboo's code:
print' 'x(--$h).($_==1?'*':join'',map{rand>$f?'=' :qw(* 0 @ +)[rand 4]}1..$_*2-1)."\n"for 1..$h
Ok. ' ' can be replaced by $" which defaults to a space (1 char). The parens around --$h are unnecessary (2 chars). $_==1?X:Y can be rewritten as $_-1?Y:X (1 char). "\n" can be replaced by $/ (2 chars). That results in a s(h)aving of 6 chars, bringing it from 94 to 88.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: README: The Sand Wedge (Re: (Golf) Decorating the Christmas Tree)
by dragonchild (Archbishop) on Dec 04, 2001 at 01:41 UTC
    You don't need the join. Just use the fact that print takes a list.
    print$"x$h--,"*\n",map{$"x$h--,(map{rand>$f?'=':qw(* 0 @ +)[rand 4]}0. +.2*$_),$/}1..$h
    85 chars (without assignment). :-)

    At some point, I'd like someone to explain to me how that nested map doesn't get confused. *laughs*

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: README: The Sand Wedge (Re: (Golf) Decorating the Christmas Tree)
by Rhose (Priest) on Dec 04, 2001 at 00:31 UTC
    *Smiles*

    You hit all the ones I would never find, but you have kept the only one I found obvious --

    Since the number are not being used in any calculations, 1..$_*2-1 can be rewritten as 2..$_*2 (2 chars)