fixed fixedPoint func in midterm

This commit is contained in:
Louis Heredero 2025-04-04 10:35:11 +02:00
parent 84315955f8
commit 3f648b7fc9
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7

@ -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)