Permalink
Browse files

Problem 15 updated

  • Loading branch information...
1 parent 580368c commit ff3e612a25420bd25cbb43025c455a8ce9e41625 @pavelfatin committed Dec 8, 2013
Showing with 3 additions and 6 deletions.
  1. +3 −6 p15.scala
View
@@ -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

Please sign in to comment.