A quilt is made by sewing square patches of different colors together in
a pattern. We are using a pattern that says to start with one patch, and then add patches starting with the patch above it and continuing by spiraling outward counterclockwise until we
have the desired size. The picture below shows the order of the patches (a then b then c etc.)
in crafting a quilt whose length(i.e. height) is 4 and whose width is 3.
lkj
cbi
dah
efg
Define the neighbors of a newly added patch to be
all the previous patches that touch the new patch (including those that
just touch diagonally at a corner). The rules for choosing the color of
the newly added patch are -
1) choose a color that minimizes the number of neighbors of the same color
-
2) choose a color that has been used least often by previous patches
-
3) choose the earliest(lowest index) color in the colorList
Rule 2 is applied only to decide among colors that are tied after rule 1 has been applied. Rule 3
is applied only to decide among colors that are tied after the first two rules have been applied.
Create a class Quilting that contains a method lastPatch that returns the color
of the last patch added to the quilt. Its inputs are an int length and an int
width (the two dimensions of the finished quilt), and
a String[] colorList giving the
available colors. length minus width will be 0 or 1,
so it will always be possible to produce a quilt of the given size.
|