diff --git a/src/MidTerm1/Ex2.sc b/src/MidTerm1/Ex2.sc index c4b8232..81784bc 100644 --- a/src/MidTerm1/Ex2.sc +++ b/src/MidTerm1/Ex2.sc @@ -25,10 +25,13 @@ def predicates[T](list: List[T])(preds: List[T => Boolean]): List[T] = { } def fixedPoint(f: Int => Int): Int => Int = { + @tailrec def func(x: Int): Int = { val y: Int = f(x) if (x == y) y - else f(y) + else func(y) } func } + +fixedPoint(x => x / 2 + 5)(40) \ No newline at end of file