This is my first post; I'm a first you CS major. I'm trying to find a way to write a "verbose" add-on method for an assignment. The assignment is to play the game JumpIt, where the player either moves one or two spaces to the right through a board/array of integers to reach the final square, shooting for the smallest sum. The problem is solved recursively; here's the simple method (in Java):
private static int findRoute(int start, int[] board) { if ((boardSize - start) == 0 ) { // the last element has been reached return board[start]; } else { return board[start] + Math.min(findRoute(start + 1, board), findRoute(start + 2, board)); } // end else } // end findRoute
What I want to do is print out a string of just those steps that lead to the best solution. So far, my attempts to build such a string have all had many hundreds of entries, in wild order, resulting in nothing of interest. I'm stumped.
Does anyone know how I could do this? It's not part of the assignment; I just want to know. Thanks in advance!