This examination consists of a single problem, addressed to the class as a whole:
Design, implement, test, and document a C program that determines and
outputs the elements of one or more two-dimensional arrays of Boolean
values, given the dimensions of each array and the number of occurrences of
true in each row and each column of each array.
For example, given the information that a Boolean array has six rows,
respectively containing (from top to bottom) 2, 4, 1, 3, 0, and 2
occurrences of true, and four columns, respectively containing (from
left to right) 2, 5, 1, and 4 such occurrences, the program should
construct the array
+-------+-------+-------+-------+ | false | true | false | true | +-------+-------+-------+-------+ | true | true | true | true | +-------+-------+-------+-------+ | false | true | false | false | +-------+-------+-------+-------+ | true | true | false | true | +-------+-------+-------+-------+ | false | false | false | false | +-------+-------+-------+-------+ | false | true | false | true | +-------+-------+-------+-------+
In this case, the given information uniquely determines the contents of the
array. It is also possible for several arrangements of elements to be
consistent with the given information. For instance, there are six
different three-by-three arrays which each row and column contains exactly
two occurrences of true:
+-------+-------+-------+ +-------+-------+-------+ | false | true | true | | false | true | true | +-------+-------+-------+ +-------+-------+-------+ | true | false | true | | true | true | false | +-------+-------+-------+ +-------+-------+-------+ | true | true | false | | true | false | true | +-------+-------+-------+ +-------+-------+-------+ +-------+-------+-------+ +-------+-------+-------+ | true | false | true | | true | true | false | +-------+-------+-------+ +-------+-------+-------+ | false | true | true | | false | true | true | +-------+-------+-------+ +-------+-------+-------+ | true | true | false | | true | false | true | +-------+-------+-------+ +-------+-------+-------+ +-------+-------+-------+ +-------+-------+-------+ | true | false | true | | true | true | false | +-------+-------+-------+ +-------+-------+-------+ | true | true | false | | true | false | true | +-------+-------+-------+ +-------+-------+-------+ | false | true | true | | false | true | true | +-------+-------+-------+ +-------+-------+-------+
In such a case, it is sufficient for the program to find and output any one of the possible configurations.
It is also possible that no arrangement of Boolean values is consistent
with the given information. For instance, there is no two-by-two Boolean
array in which one row contains two occurrences of true and the
other row none, while one column contains two occurrences of true
and the other column none. In such a case, your program should briefly
report that no such array exists (but should not signal an error).
Your program should have a command-line interface. On the command line,
the user is expected to supply the names of one or more existing,
read-accessible text files, each containing the dimensions of an array and
the number of true values in each of its rows and columns.
You may design and specify the format of the input files, with the goal of making it easy and straightforward for a human preparer to create an input file that the program can process efficiently. It is more important for the design to be simple than for it to be flexible or exceptionally readable.
Similarly, you may design and specify the format of the output, with the goal of making the output easy for other programs to parse and process, but also at least marginally human-readable.
For instance, a command-line invocation of your program might look like this:
array-filler sample.dat ambiguous.dat impossible.dat
and its output might look like this:
# sample.dat FTFT TTTT FTFF TTFT FFFF FTFT # ambiguous.dat FTT TFT TTF # impossible.dat # *** No solution ***
It is acceptable for your program to deliver quick results only in cases that are small or exceptionally simple. Thus you may choose to implement an algorithm that requires exponential time in the worst case, even though polynomial-time algorithms for this problem are known.
You may use any books, notes, technological devices, Web sites, outside assistants and consultants, published source code and code libraries, or other resources, provided that you fully acknowledge any assistance you receive and pay nothing extra for it (i.e., nothing beyond College tuition and fees, charges for wireless service for which you have already contracted, and the like).
Submit your solution by preparing a tarball containing the finished source code and documentation for your program and e-mailing it to me (stone@cs.grinnell.edu mailto:stone@cs.grinnell.edu) before noon today. If the entire class can agree on a solution, it is all right for just one person to submit it, but I'll accept as many factional or individual solutions as you wish to submit.