#Perl, 83 +1 = 84 bytes
Perl, 83 +1 = 84 bytes
Run with the -n
flag.
$\="*
*";print$c="*"x($_+1);for$b(1..$_){@a=($")x$_;@a[$b-1,-$b]=(a,a);print@a}say$c
The literal newline saves 1 byte over \n
or $/
.
Readable:
$\="*\n*";
print$c="*"x($_+1);
for$b(1..$_){
@a=($")x$_;
@a[$b-1,-$b]=(a,a);
print@a
}
say$c
The code prints the top line and saves it in $c
, then prints a bunch of spaces with the appropriate slots replaced with a
s, then prints the top line again.
The assignment to the $\
variable tells the interpreter to print the contents (an asterisk, a newline, and another asterisk) after every print
, but this does NOT occur after a say
.