PHP, 130 bytes
for($p=30,$s=1,$r=_;$i<51;$r[$p]=chr(90-abs(25-$i++)),$p+=$s*(9-$d))if(!$n||!$c=++$c%$n)($d=8-$d)?$n++:$s=-$s;echo wordwrap($r,8);
literally draws the spiral. Run with -r
breakdown
for($p=30,$s=1,$r=_; // initialize position to 3*9+3, $s(ign) to +1, $r(esult) to string
// implicit $c(ount)=$d(irection)=$i(ndex)=le($n)gth=0
$i<51; // loop $i from 0 to 50
$r[$p]=chr(90-abs(25-$i++)),// 2. set current position in string to correct character
$p+=$s*(9-$d)) // 3. move cursor
if(!$n||!$c=++$c%$n) // 1. if 1st iteration ($n==0) or ++$c has rotated around $n
($d=8-$d) // negate $direction (0=horizontal, 8=vertical)
?$n++ // if vertical: increase length
:$s=-$s // else invert sign
;
// output: wrap to lines of 8 characters
echo wordwrap($r,8); // having left spaces avoids need to provide 3rd and 4th parameter
Easy to extend: For more alphabet,
append %50
after $i++
,
replace 51
with the wanted number,
modify 8-$d
, 9-$d
, $p=30
and the wordwrap
width to the new dimensions.
Can the lines have trailing spaces? – Dennis – 2016-08-13T18:23:22.650
@Dennis Yes, I will edit the question to clarify that. – DanTheMan – 2016-08-13T18:26:56.930
1
in case you wonder about the ascii codes of the spiral: http://puu.sh/qAitG/dd89c615cf.png
– downrep_nation – 2016-08-13T22:03:22.9773This output seems far too “complex” (in the Kolmogorov sense, i.e. devoid of pattern). Golf-y languages can hope to compress it, or in the case of MATL, hope to have a spiral built-in — but IMO it’s a bad sign if the best approach to a [tag:kolmogorov-complexity] challenge is ever “just print the output as a string literal” (see Python). – Lynn – 2016-08-13T22:15:17.870
2@Lynn Feel free to downvote if you think it's a bad question. That's what it's there for. I'll keep that in mind for next time though. – DanTheMan – 2016-08-13T22:28:44.670
So I did; I was just explaining my vote. ^^ – Lynn – 2016-08-13T22:29:43.453
Strongly related. – Lynn – 2016-08-13T22:33:00.953