fixed fixedPoint func in midterm
This commit is contained in:
parent
84315955f8
commit
3f648b7fc9
@ -25,10 +25,13 @@ def predicates[T](list: List[T])(preds: List[T => Boolean]): List[T] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def fixedPoint(f: Int => Int): Int => Int = {
|
def fixedPoint(f: Int => Int): Int => Int = {
|
||||||
|
@tailrec
|
||||||
def func(x: Int): Int = {
|
def func(x: Int): Int = {
|
||||||
val y: Int = f(x)
|
val y: Int = f(x)
|
||||||
if (x == y) y
|
if (x == y) y
|
||||||
else f(y)
|
else func(y)
|
||||||
}
|
}
|
||||||
func
|
func
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fixedPoint(x => x / 2 + 5)(40)
|
Loading…
x
Reference in New Issue
Block a user