fixed fixedPoint func in midterm
This commit is contained in:
		| @@ -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) | ||||
		Reference in New Issue
	
	Block a user