Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Align-columns/Q/align-columns.q
Normal file
14
Task/Align-columns/Q/align-columns.q
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
text:(
|
||||
"Given$a$text$file$of$many$lines,$where$fields$within$a$line$";
|
||||
"are$delineated$by$a$single$'dollar'$character,$write$a$program";
|
||||
"that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$";
|
||||
"column$are$separated$by$at$least$one$space.";
|
||||
"Further,$allow$for$each$word$in$a$column$to$be$either$left$";
|
||||
"justified,$right$justified,$or$center$justified$within$its$column." )
|
||||
|
||||
ta:{[aln;txt] / tabulate aligned
|
||||
sl:(count'')s:"$"vs/:txt; / strings and their lengths
|
||||
cw:{rl#\:max x@/:\:til max rl:count each x}sl; / cell widths
|
||||
ps:$[aln=`R;-1-cw;1+cw]$''s; / padded strings
|
||||
ps:$[aln=`C;(neg(cw-sl)div 2)rotate''ps;ps]; / center
|
||||
1,[;"\n\n"]"\n"sv raze each ps; } / print
|
||||
Loading…
Add table
Add a link
Reference in a new issue