Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cache = []
- def binomial(n, k) {
- if (n == k || k == 0) {
- return 1G
- }
- if (! cache[n]) {
- cache[n] = []
- }
- if (! cache[n][k]) {
- cache[n][k] = binomial(n-1,k) + binomial(n-1,k-1)
- }
- return cache[n][k]
- }
- println "Lattice paths counts:"
- println "For 2x2 grid there are ${binomial(4,2)} paths"
- println "For 3x3 grid there are ${binomial(6,3)} paths"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement