// Puzzle.java -- This solution should be similar to finding // a path through a maze. // You need to keep track of how many 1's are in a "blob", and be careful // not to change the original array. import java.io.*; import java.util.*; public class Puzzle { private char [][] board; private int rows; private int columns; private static final char occupied = '1'; private static final char empty = '0'; public Puzzle() throws IOException { BufferedReader inFile = new BufferedReader(new FileReader("blob.txt")); String line = inFile.readLine(); StringTokenizer tok = new StringTokenizer(line, " "); rows = Integer.parseInt(tok.nextToken()); columns = Integer.parseInt(tok.nextToken()); board = new char[rows][columns]; for (int i = 0; i < rows; ++i) { line = inFile.readLine(); for (int j = 0; j < columns; ++j) { board[i][j] = line.charAt(j); } } } // This is only a skeleton of the implementation of solve(). // It will compile and run, but it will always return 0. public int solve(int i, int j) { // Handle the base case here: if (true) { System.out.println("solve(" + i + ", " + j + "): returning 0"); return 0; } // I've provided some diagnostic output statements: You'll need to // insert your recursive calls somewhere around here. System.out.println("solve(" + i + ", " + j + "): going up"); System.out.println("solve(" + i + ", " + j + "): going right"); System.out.println("solve(" + i + ", " + j + "): going down"); System.out.println("solve(" + i + ", " + j + "): going left"); // You need to set the return value appropriately. int retVal = 0; System.out.println("solve(" + i + ", " + j + "): returning " + retVal); return retVal; } }