015 Lattice paths.sf 448 B

12345678910111213141516171819
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # 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.
  6. # How many such routes are there through a 20×20 grid?
  7. # https://projecteuler.net/problem=15
  8. # Runtime: 0.131s
  9. func lattice_paths(n) {
  10. binomial(2*n, n);
  11. }
  12. say lattice_paths(20);