diff options
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)) + } } |