Pages

Wednesday, June 8, 2011

Number of paths in square grid (Project Euler problem 15)

Description of the problem (from here ):
Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner.
How many routes are there through a 20×20 grid?


A: We can observe that:
  •  every path has exactly 2*n moves, every move being either right or down (backtracking isn't allowed)
  • in every 2*n path there are n moves down and n moves right. 
So, the number of all the distinct possibilities is the number of ways we can arrange n right moves from 2*n positions:

1 comment:

  1. what will be the solution if you have to avoid one or two points in the square grid?

    ReplyDelete