Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
7
Task/Align-columns/Maple/align-columns-1.maple
Normal file
7
Task/Align-columns/Maple/align-columns-1.maple
Normal 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":
|
||||
24
Task/Align-columns/Maple/align-columns-2.maple
Normal file
24
Task/Align-columns/Maple/align-columns-2.maple
Normal 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:
|
||||
28
Task/Align-columns/Maple/align-columns-3.maple
Normal file
28
Task/Align-columns/Maple/align-columns-3.maple
Normal 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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue