Skip to content

Commit ffca52c

Browse files
committed
Create 015.js (solved using math not code)
1 parent a0dfb55 commit ffca52c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

015.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
This one can be solved without code, using combinatorics.
3+
4+
Starting from the top left corner of a n x n board, to get to the bottom right corner, we need to take n steps right and n steps down.
5+
6+
We can construct an element of the set of all possible lattice paths via the following multi-step procedure,
7+
such that the number of ways in which a choice can be made is not affected by how a prior choice was made,
8+
and each possible lattice path arises in exactly one way by this process:
9+
10+
1. Choose positions in the path (n + n steps long) where we're going to be going right: 2n choose n
11+
2. Choose positions in the path (n more steps left) where we're going to be going down: n choose n
12+
13+
By the Rule of Product, the cardinality of the set of all possible lattice paths is equal to (2n choose n) * (n choose n) = (2n choose n)
14+
15+
Thus, for a 20 x 20 board (n = 20), 2*20 choose 20 = 40 choose 20 = 40!/((20!)(40-20)!) = 40!/(20!20!) = 137846528820 = our answer
16+
*/

0 commit comments

Comments
 (0)