Oh no, more code golf!
By joe
- 1 minutes read - 207 wordsA new code golfing site. Gaaaak! If I have time to work on such diversions, I’ll post mine under the ID numbercruncher. [update] Played with the starburst code. Have something that works (though they failed to specify their input method, or their output requirement, e.g. newlines, etc.) This is at 135 characters:
<code>
$l=@a=split//,shift;$i=-1;while($i++< $l){map$x[$_]=" ",0..$l;$i==int$l/2?@x=@a:map$x[$_]=$a[$i],$i,$l/2,$l-$i-1;print join"",@x,"\n";}
</code>
</code>
which for the input “asdfd” gives
a a a
sss
asdfd
fff
d d d
among other things. Works well for the other input. In the debugger. Their code testing environment, not so much. So I have to reverse engineer this. Apart from that, I see areas where I can save quite a few characters, 30-50, if I could avoid some initialization, and some of the formatting bits. [update 2] started exploiting some of the more powerful features of Perl, though I kept generating more temporary variables.
<code>
($l=@a=split//,<>)--;$\=pop@a;$m=$l>>1;map{@x=(" ")x$l;$_==$m?@x=@a:(@x[$_,$m,$l-$_-1]=($a[$_])x3);print@x;}0..$l;
</code>
115 characters. If I could eliminate some of the temp variables (carefully), could probably get it below 100 characters. Its still … almost … readable by humans. There are 3 vector assignments, a vector printing, and a serialized outer loop. The map{} is the core, the $l=.. gets the input and divides it up into an array.