Queues. That's interesting. Here's the important part of my nested for loop solution:
// find all unique ending values and populate an array that contains the
// frequency of occurrence of each unique ending
private int[] calculateEndingFrequency( int numberOfSteps )
{
// the number of unique endings is 1 more than the number of steps
int[] stepFrequency = new int[numberOfSteps + 1];
// initialize the frequency array for the zero-step case
stepFrequency[0] = 1;
// for numberOfSteps = 0, return the current result
if ( numberOfSteps == 0 )
{
return stepFrequency;
}
// continue initialization of the array for the single step result
// this is the first term of the second row of the pyramid
stepFrequency[1] = 1;
// calculate each array by finishing the single step result (row 2 of
// the pyramid) to the specified number of steps (row numberOfSteps + 1
// of the pyramid)
for ( int i = 2 ; i <= numberOfSteps ; i++ )
{
// each pass through the for loop expands the current array. the
// expansion begins by setting the next zero element to 1
stepFrequency[i] = 1;
// a temporary array contains a copy of the current array and is
// used to calculate the next iteration of the stepFrequency array
int[] tempArray = Arrays.copyOf( stepFrequency, stepFrequency.length );
// calculate the current array's values between the first and last
// non-zero elements by adding the elements in the temp array
// (see the diagram above to understand how adding elements of
// previous array builds the next array)
for ( int j = 1 ; j < i ; j++ )
{
// set the jth element of the current array equal to the sum
// of elements in the preceding row to the left and to the
// right of the current element
stepFrequency[j] = tempArray[j - 1] + tempArray[j];
}
}
return stepFrequency;
} // end method calculateEndingFrequency()