Perl, 93 chars
@x=($t=$x=_ x 3**($a=abs($n=<>)),map$x.=$"x($x=~s/(.)../$1/g).$x,1..$a);say for$n<0?sort@x:@x
I thought I'd try to see how well Peter Taylor's GolfScript solutionPeter Taylor's GolfScript solution would port to Perl. Notable features include the use of sort
instead of reverse
to save three chars, using the fact that a space sorts before _
.