diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-04-03 22:18:48 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-10 18:03:22 +0100 |
commit | 476583c90a47cad62f992ab0b845ebf2897cb47d (patch) | |
tree | c3742b376e852cc34b3bcfe052fd7aa1acbc09f5 /Scala/sandbox/recursion.scala | |
parent | 545c03ac4981737594d7638b7a925d1881a74cdc (diff) | |
download | coursera-476583c90a47cad62f992ab0b845ebf2897cb47d.zip coursera-476583c90a47cad62f992ab0b845ebf2897cb47d.tar.gz |
Scala : cleanup, Scala : add sumCurry
Diffstat (limited to 'Scala/sandbox/recursion.scala')
-rw-r--r-- | Scala/sandbox/recursion.scala | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Scala/sandbox/recursion.scala b/Scala/sandbox/recursion.scala index e7c29a5..5488aea 100644 --- a/Scala/sandbox/recursion.scala +++ b/Scala/sandbox/recursion.scala @@ -8,15 +8,11 @@ object Recursion { def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b) - println(gcd(21, 56)) - // there is still the multiplication to be performed // -> the stack frame can't be reused def fact(n: Int): Int = if (n == 0) 1 else n * fact(n - 1) - println(fact(4)) - // tail recursive version of factorial def factr(n: Int): Int = { def factIter(acc: Int, n: Int): Int = @@ -24,6 +20,11 @@ object Recursion { factIter(1, n) } - def run = println(factr(4)) + def run = { + println("Recursion") + println(gcd(21, 56)) + println(fact(4)) + println(factr(4)) + } } |