1

I just have trouble understanding the question. I am not asking for the solution. Could you please help me break down what the problem wants?

  • In this problem, an array represents the squares on an unusual board game.

  • An positive index represents an instruction to move forward (e.g. a 2 means

  • "move forward 2 squares"). A negative index means move backwards.

  • Squares that have a 0 are "end locations". Once there, no more movement is possible.

  • Given a board and a starting position (index), the goal of the function

  • is to compute the path till arriving on an end location.

  • You can assume:
    a. An instruction will never move you off the board
    b. The path will not have any cycles (we'll address this issue in the next part of the problem).

  • Return an ArrayList of indices visited in inputA in the order in which they were visited, starting with startLoc in position zero of the ArrayList.
  • Examples:
    computeBoardPathV1([2,-1,0], 1) --> <1,0,2>
    computeBoardPathV1([3,3,-2,0,-2], 1) --> <1,4,2,0,3>
    computeBoardPathV1([6,4,2,0,-1,-3,-5], 0) --> <0,6,1,5,2,4,3>
    computeBoardPathV1([6,4,2,0,-1,-3,-5], 4) --> <4,3>
    computeBoardPathV1([0], 0) --> <0>
/**
 * @param input the game board
 * @param startingLoc the index where the path should start
 * @return The indexes traveled from startingLoc to the 0 "end location"
 */
public static ArrayList<Integer> computeBoardPathV1(int[] input, int startLoc) {
    return null;
}
2
  • 1
    We can give our opinion on what is being asked for, but keep in mind that it'll be nothing more than an educated guess. If you need clarity regarding an assignment, it's always best to contact your teacher and ask them what they want you to do. Commented Oct 12, 2018 at 17:00
  • The answers you got appear correct, though there seem to be a couple of mistakes in the instructions. Those mistakes may be adding to the confusion. 1) The instructions mistakenly use the term "index" to mean both "the location in the array" and "the contents at a location in the array". That makes the earlier parts more confusing. 2) The startLoc was not obvious at first; it appears to be the second argument to the function, but that is not specified anywhere in what you provided to us, so if it was not provided to you either, that indeed could throw you off. Commented Oct 12, 2018 at 17:31

2 Answers 2

1

The computeBoardPathV1 function is supposed to return a list of the steps taken from the given starting point to get to a stopping point in the array.

Let's look at the given examples: * Examples: computeBoardPathV1([2,-1,0], 1) --> <1,0,2>

The given array is [2,-1,0]. The second parameter is the starting point, 1.

Here's what should happen:

  • Save the current position (1) to the result list.
  • Array element 1 has value -1. (Don't forget arrays start at index 0)
  • Add -1 to the current position to get 0
  • Save the current position (0) to the result list.
  • Array element 0 has value 2
  • Add 2 to the current position(0) to get 2
  • Save the current position(2) to the result list
  • Array element 2 is 0, so we're done.

The result list now contains: [1, 0, 2]

Another example: computeBoardPathV1([6,4,2,0,-1,-3,-5], 4) --> <4,3>

  • The starting index is 4
  • Save the current position(4) to the result list
  • Array element 4 is -1
  • Add -1 to the current position to get 3
  • Save the current position(3) to the result list
  • Array element 3 is 0, so we're done.

The result list in this case is [4,3]

Sign up to request clarification or add additional context in comments.

Comments

0

What they are asking you is to print how you travel the array; i.e. which positions of the array you access, following the instructions declared in each element of the array...

For example, computeBoardPathV1([2,-1,0], 1) --> is telling you that you must start from the instruction declared in the array element 1... then reading the value of such element, execute the instruction which is move to the left of the array by one element, then read again, and the instruction says move 2 spaces to the right...

So the solution is: <1,0,2>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.