diff --git a/src/main/scala/main.scala b/src/main/scala/main.scala index c6288f2..70ef690 100644 --- a/src/main/scala/main.scala +++ b/src/main/scala/main.scala @@ -59,3 +59,27 @@ def binKoeffRek(m:Int,n:Int):Int = { else return m * binKoeffRek(m - 1, n - 1) / n } + +//Aufgabe 5 + +def triagnles(n:Int):Int = { + + // mistake is in sum it always returns 1 + + def sum(i: Int, n: Int): Int = { + if (i <= n) then{ + // println("Test1") + return (n-i)+sum(i+2,n) + } + else { + 1 + } + } + // println("Test2") + if (n == 1) { + return 1 + } else { + //return n + return triagnles(n - 1) + ((n * (n + 1)) / 2) + sum(1,n) + } +}