Question for solution 16.3 for java

#1

int waysTop
= x == 0 ? 0 : computeNumberOfWaysToXY(x - 1, y, numberOfWays);
int waysLeft
= x == 0 ? 0 : computeNumberOfWaysToXY(x, y - 1, numberOfWays);

I can’t make sense out of the bold part. Doesn’t seem needed at all.

0 Likes

#2

Hi @ray,

We do need that as we are processing entries of (x, 0) and (0, y) where x and y are not 0. The special case in the code only handles the case (0, 0).

0 Likes

#3

Isn’t the special case handling code doing if (x==0 || y==0)? That should handle all (x,0) and (0,y) cases right?

0 Likes

#4

The special case only handles (x == 0 && y == 0) (by returning 1), and we can add another special case by handling (x == 0 || y == 0) but we did not do that.

0 Likes

#5

I’m reading (x == 0 || y == 0) from the book :slight_smile: .

0 Likes

#6

It was a bug before, and we fixed it :stuck_out_tongue:

0 Likes