Individual Project 3
Text Layout Functions
Due Monday, February 17, 3:30pm
- papers submitted after 3:30pm Feb 17 and before 3:30pm Feb 19
suffer a penalty of one-grade per day -
- papers not accepted after 3:30pm Feb 19 -
Note: Start today!
This is more than twice as
hard as your last project.
Anticipate a definition or collection of defintions
comprising one or two dozen lines.
What to Hand In (see also: example project solution)
Four projects are described below. Different team members do different projects. Team members listed first or fifth on their team's roster must do Project 3A; those listed second or sixth, Project 3B; third, Project 3C; fourth, Project 3D.
Project 3A - packaging lines
Define a function called
linePackets
that splits a sequence of strings (words) supplied
in the second argument into a
sequence of sequences of strings (line packets) that fit within
a length limit supplied in the first argument, but would not
fit if they contained any additional strings.
The delivered sequence of packets must satisfy the following properties:
Examples
linePackets 12 ["The", "purpose", "of", "computing"]
= [["The", "purpose"], ["of computing"]]
linePackets 6 ["is", "insight,", "not", "numbers."]
= [["is"], ["insight,"], ["not"], ["numbers."]]
linePackets 14 (repeat "blah") = repeat["blah", "blah", "blah"]
Show that the function you define has the following property:
Examples:
justify 12 ["The", "purpose"] = "The purpose"
justify 12 ["of", "computing"] = "of computing"
justify 6 ["is"] = "is "
justify 6 ["insight,"] = "insight,"
justify 52 ["The", "purpose", "of", "computing",
"is", "insight,", "not", "numbers."] =
"The purpose of computing is insight, not numbers."
Show that the function you define has the following property:
Project 3C - arranging words in columns
Define a function called columns that, given a number indicating
how many columns are desired and a sequence of strings (words),
delivers a sequence of sequences (columns) of words
such that the first column contains
the initial segment of the given sequence of words, the second
column contains the next segment, and so on.
All columns must
have exactly the same length;
if the number of
words is not a multiple of the number of columns, then
pad the bottom of some of the columns with an empty string.
Note: Each column must consist entirely of words from the argument, except that the last element of the column may be a pad; the number of padded columns must be less than the number of columns.
Examples
columns 3 ["Bool", "Char", "Int", "Float",
"Double", "Integer", "String"] =
[["Bool", "Char", "Int"],
["Float", "Double", ""],
["Integer", "String", ""]]
columns 3 ["Bool", "Char", "Int", "Float", "Double", "Integer"] =
[["Bool", "Char"],
["Int", "Float"],
["Double", "Integer"]]
columns 3 ["Bool", "Char", "Int", "Float", "Double"] =
[["Bool", "Char"],
["Int", "Float"],
["Double", ""]]
Show that the function you define has the following property:
Project 3D - making a table
Define a function called table that, given a number
(the first argument) indicating
how many spaces to put between columns and a sequence
of sequences of strings (columns of words), all columns having
exactly the same length,
delivers a sequence of strings (rows) such that each row
is formed by concatenating one word from each column
in such a way that the words from the first column occur at the
beginnings of the rows, the words from the second column follow
the words from the first column in their respective rows,
then the words from the third column and so on.
The rows must be arranged so that the columns "line up" and so that the minimum gap between each adjacent pair of columns is the number supplied as the first argument. That is, if the second word in the first row begins at the k-th character in the string representing that row, then the second word in all the other rows must begin at the k-th character of the row. Furthermore, number of spaces between the end of the first and second words on the row must be exactly equal to the second argument in the invocation of the table function. Other words in the rows must line up in an analogous way and follow the same constraint on the number of spaces between words in one column and words in the next column. All of the rows must contain exactly the same number of characters. Use spaces to separate the words of a row and to pad out the rows to make them all the same length.
Examples
table 3 [["Char", "String", "Bool"],
["Int", "Integer", "Rational"],
["Float", "Complex Float", "Double"]] =
["Char Int Float ",
"String Integer Complex Float",
"Bool Rational Double "]
table 1 [["Char", "String", "Bool"],
["Int", "Integer", "Rational"],
["Float", "Complex Float", "Double"]] =
["Char Int Float ",
"String Integer Complex Float",
"Bool Rational Double "]
table 0 [["Char", "String", "Bool"],
["Int", "Integer", "Rational"],
["Float", "Complex Float", "Double"]] =
["Char Int Float ",
"StringInteger Complex Float",
"Bool RationalDouble "]
Show that the function you define has the following property:Ground Rules