tile2 - printTile(n-2, "2"); printTile(n-1,...

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

View Full Document Right Arrow Icon
// 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");
Background image of page 1
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

This document was uploaded on 11/09/2009.

Ask a homework question - tutors are online