{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# tile2 - printTile(n-2"2" printTile(n-1"1"...

This preview shows page 1. Sign up to view the full content.

// Arup Guha // 11/3/06 // Written in COP 3503 - solves "tile" problem. // Prints out each way to tile a length of n with 1, 2, 3, 4 and 5 unit tiles. / public class tile2 { p public static void main(String[] args) { p // One test case. / printTile(10,""); } public static void printTile(int n, String curtiles) { p // This is invalid. if (n < 0) return; r // Print out the tiles we've already laid out. if (n == 0) { i System.out.println(curtiles); return; } // For starting case, so a comma doesn't precede the first tile. if (curtiles.equals("")) { printTile(n-5, "5"); printTile(n-4, "4"); printTile(n-3, "3");
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printTile(n-2, "2"); printTile(n-1, "1"); } // We can place a tile of length 2, and from that, do all tilings of // length n-2. // OR // We can place a tile of length 1, and from that, do all tilings of // length n-1. else { e char lasttile = curtiles.charAt(curtiles.length()-1); c switch (lasttile) { s case '5': printTile(n-5, curtiles+", 5"); c case '4': printTile(n-4, curtiles+", 4"); case '3': printTile(n-3, curtiles+", 3"); case '2': printTile(n-2, curtiles+", 2"); case '1': printTile(n-1, curtiles+", 1"); c } } } }...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern