Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,7 @@
txt :=
"Given$a$text$file$of$many$lines,$where$fields$within$a$line$\n"
"are$delineated$by$a$single$'dollar'$character,$write$a$program\n"
"that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$\n"
"column$are$separated$by$at$least$one$space.\n"
"Further,$allow$for$each$word$in$a$column$to$be$either$left$\n"
"justified,$right$justified,$or$center$justified$within$its$column.\n":

View file

@ -0,0 +1,24 @@
AlignColumns := proc( txt, align :: { "left", "right", "centre" } := "centre" )
uses StringTools;
# Get a list of lists of fields
local A := map( Split, Split( txt ), "$" );
# Calculate the column width
local width := 1 + max( map( L -> max( map( length, L ) ), A ) );
# Add spacing according to the requested type of alignment
if align = "left" then
local J := map( line -> map( PadRight, line, width ), A )
elif align = "right" then
J := map( line -> map( PadLeft, line, width ), A )
else
J := map( line -> map( Center, line, width ), A )
end if;
# Join up the fields in each line.
J := map( cat@op, J );
# Re-assemble the lines into a single string.
Join( J, "\n" )
end proc:

View file

@ -0,0 +1,28 @@
> printf( "%s\n", AlignColumns( txt ) ):
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.
> printf( "%s\n", AlignColumns( txt, "center" ) ): # same as above
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.
> printf( "%s\n", AlignColumns( txt, "left" ) ):
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.
> printf( "%s\n", AlignColumns( txt, "right" ) ):
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.