Problem Statement
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
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
Definition
- Class:
- Quilting
- Method:
- lastPatch
- Parameters:
- int, int, String[]
- Returns:
- String
- Method signature:
- String lastPatch(int length, int width, String[] colorList)
- (be sure your method is public)
Constraints
- width will be between 1 and 100 inclusive
- length will be between 1 and 100 inclusive
- length - width will be 0 or 1
- colorList will have between 1 and 10 elements inclusive
- each element of colorList will have between 1 and 15 characters inclusive
- each element of colorList will contain only uppercase letters 'A'-'Z'
- each element of colorList will be distinct
Examples
3
2
{"RED","BLUE","TAN"}
Returns: "TAN"
TAN BLUE RED RED BLUE TAN The layout above shows the finished quilt. It was created by starting at the position of the rightmost RED. (The color RED was chosen by rule 3). The BLUE above it was added next (RED was disqualified by rule 1, BLUE preferred over TAN by rule 3). Then TAN was chosen by rule 1, and then RED was chosen by rule 3. BLUE was chosen by rule 3 after RED was eliminated by rule 1. Finally the last patch was TAN by rule 1.
4
3
{"E","D","C","B","A"}
Returns: "E"
E B E C D A B E B A D C The layout above shows the finished quilt. It was created by starting at the position of E near the middle.(The color E was chosen by rule 3). The D above it was added next (E was disqualified by rule 1, the others were tied under rule 2, and D was preferred over the others by rule 3). The process continued until the final E in the upper left corner was chosen because B, C, and D were eliminated by rule 1, E and A were tied under rule 2 and E was preferred to A by rule 3.
5
4
{"RED","BLUE","YELLOW","GREEN","ORANGE","PURPLE","BROWN"}
Returns: "ORANGE"
100
100
{"A","B","C","D","E"}
Returns: "E"
3
3
{"A","B","C","D"}
Returns: "C"
C B C D A A B C D This quilt was constructed by starting at the position of the middle A and then adding the B patch above it. The final patch was the C in the upper right corner.
1
1
{"RED","BLUE","YELLOW"}
Returns: "RED"
10
10
{"X","Y","Z"}
Returns: "Z"
Z Y Z Y X Y X Z X Y X X Z Y Z Y X Y X Z Z Y Z X Z Y Z Y Z Y X Z X Y X Y X Z X X Y Z Y Z Z Y Z Y Y Y Z X X X X X X Z X Z Y Y Y Z Y Z Y Y Z Y X X Z X Y X Z X X X Y Z Y X Z X Y Z Y Y Z X Y Z Y Z X Z X Z
100
99
{"ORGANDY","ORGANZA","A","B","C","D","O","X","Y","Z"}
Returns: "Z"
40
40
{"A","B"}
Returns: "B"
39
39
{"X","D"}
Returns: "X"
17
17
{"G","H"}
Returns: "G"
2
1
{"A","B","C","D","E","F"}
Returns: "B"
9
9
{"A","B","C","D","E","F"}
Returns: "D"
9
8
{"A","B","C","D","E","F"}
Returns: "B"
8
8
{"A","B","C","D","E","F"}
Returns: "B"
8
7
{"A","B","C","D","E","F"}
Returns: "C"
44
44
{"A","B","C","D","E","F"}
Returns: "D"
57
56
{"A","B","C","D","E","F"}
Returns: "E"
89
88
{"A","B","C","D","E","F"}
Returns: "C"
89
89
{"A"}
Returns: "A"
45
44
{"ORGANDY","ORGANZA","A","B","C","D","O","X","Y","Z"}
Returns: "Z"
32
32
{"ORGANDY","ORGANZA","A","B","C","D","O","X","Y","Z"}
Returns: "B"
97
96
{ "A", "B", "C", "D", "E", "F", "G", "H", "I" }
Returns: "F"
5
5
{ "A", "B", "C", "D", "E", "F", "G" }
Returns: "C"
99
99
{ "A", "B", "C", "D", "E", "F", "G", "W", "Z" }
Returns: "Z"
3
3
{ "A", "B", "C", "D" }
Returns: "C"
3
3
{ "A", "B", "C" }
Returns: "C"