Problem 59526. Count paths between corners of a grid that remain on or below the diagonal
Consider motion from the lower left corner of a square grid to the upper right corner. The motion is constrained in two ways: (1) the only legal moves are (0,1), (1,0), and (1,1)—i.e., right, up, and up-and-right between points of the lattice—and (2) the motion must remain on or below the line connecting the starting and finishing corners. For a 2x2 grid, the number of paths is 6, as shown below.
Write a function to count the legal paths for an nxn grid. Return the count as a string. Check the last test for banned functions.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers3
Suggested Problems
-
423 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
541 Solvers
-
Flip the main diagonal of a matrix
830 Solvers
-
USC Fall 2012 ACM : Code Word Minimum Flipped Bits
19 Solvers
-
431 Solvers
More from this Author291
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!