Permalink
Please sign in to comment.
| @@ -1,9 +1,6 @@ | ||
| -def f(row: Seq[Long], c: Int): Long = { | ||
| - var s = 0L | ||
| - val next = row.map { n => s += n; s } | ||
| - if(c == 0) next.last else f(next, c - 1) | ||
| -} | ||
| +def f(row: Seq[Long], c: Int): Long = | ||
| + if (c == 0) row.last else f(row.scan(0L)(_ + _), c - 1) | ||
| -def r(n: Int) = f(List.fill(n + 1)(1L), n - 1) | ||
| +def r(n: Int) = f(Seq.fill(n + 1)(1L), n) | ||
| assert(r(20) == 137846528820L) // 1 ms |
0 comments on commit
ff3e612