Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
44
Task/Align-columns/8th/align-columns.8th
Normal file
44
Task/Align-columns/8th/align-columns.8th
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
quote | 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.|
|
||||
var, raw-text
|
||||
|
||||
[] var, data
|
||||
var width
|
||||
|
||||
: read-and-parse \ --
|
||||
raw-text @
|
||||
( "$" s:/ data @ swap a:push drop )
|
||||
s:eachline ;
|
||||
|
||||
: find-widest \ -- n
|
||||
data @ ( ( swap s:len nip n:max ) swap a:reduce ) 0 a:reduce ;
|
||||
|
||||
: print-data \ fmt --
|
||||
width @ swap s:strfmt >r
|
||||
data @
|
||||
(
|
||||
nip
|
||||
(
|
||||
nip
|
||||
r@ s:strfmt .
|
||||
) a:each drop
|
||||
|
||||
cr
|
||||
) a:each drop rdrop ;
|
||||
|
||||
|
||||
: app:main
|
||||
read-and-parse
|
||||
|
||||
\ find widest column, and add one for the space:
|
||||
find-widest n:1+ width !
|
||||
|
||||
\ print the data
|
||||
cr "right:" . cr "%%>%ds" print-data
|
||||
cr "left:" . cr "%%<%ds" print-data
|
||||
cr "center:" . cr "%%|%ds" print-data
|
||||
bye ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue