object HelloWorld { def addN(n: Int): Int => Int = (x: Int) => { x + n } def iteruj(n: Int, f: Int => Int): Int => Int = n match { case 0 => (x: Int) => x case _ => (x: Int) => iteruj(n - 1, f)(f(x)) } def logaritmickyIteruj(n: Int, f: Int => Int): Int => Int = n match { case 0 => (x: Int) => x case _ => if (n % 2 == 0) (x: Int) => iteruj(n / 2, f)(iteruj(n / 2, f)(x)) else (x: Int) => iteruj(n - 1, f)(f(x)) } type realnaFunkcia = Double => Double def kompozicia(f: realnaFunkcia, g: realnaFunkcia): realnaFunkcia = { (x: Double) => f(g(x)) } def iteracia(n: Int, f: realnaFunkcia): realnaFunkcia = n match { case 0 => (x: Double) => x case _ => kompozicia(f, iteracia(n - 1, f)) } def main(args: Array[String]): Unit = { println(iteruj(10,addN(5))(4)) println(iteruj(10,addN(10))(4)) } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more