12345678910111213141516171819 |
- #!/usr/bin/ruby
- # Author: Daniel "Trizen" Șuteu
- # License: GPLv3
- # Website: https://github.com/trizen
- # Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
- # How many such routes are there through a 20×20 grid?
- # https://projecteuler.net/problem=15
- # Runtime: 0.131s
- func lattice_paths(n) {
- binomial(2*n, n);
- }
- say lattice_paths(20);
|