aaaaa
This commit is contained in:
9
WS23_24/Anwendungsentwicklung/src/P10/Curry.scala
Normal file
9
WS23_24/Anwendungsentwicklung/src/P10/Curry.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
package P10
|
||||
|
||||
object Curry {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val curriedSum: Double => Double => Double => Double => Double = a => b => c => d => a+b+c+d
|
||||
val curSum2 = curriedSum(1)(2)
|
||||
print(curSum2(3)(4))
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ object FrenchDude {
|
||||
startPascal(5)
|
||||
println(" ")
|
||||
startPascal2(5)
|
||||
println(" ")
|
||||
fib(5)
|
||||
}
|
||||
|
||||
def startPascal(n:Int):Unit={
|
||||
@@ -47,4 +49,27 @@ object FrenchDude {
|
||||
pascal2(newArr,n)
|
||||
println()
|
||||
}
|
||||
|
||||
def fib(n: Int): Unit = {
|
||||
def fibIn(x: Int, previous: Array[Int], current: Array[Int]): Unit = {
|
||||
def topOffset(off: Int): Int = {
|
||||
val newX = x + off
|
||||
if (newX >= 0 && newX < previous.length)
|
||||
previous(newX)
|
||||
else
|
||||
0
|
||||
}
|
||||
current(x) = topOffset(-1) + topOffset(0)
|
||||
print(current(x))
|
||||
print(" ")
|
||||
if (x < current.length - 1)
|
||||
fibIn(x + 1, previous, current)
|
||||
else if (current.length < n) {
|
||||
println()
|
||||
fibIn(0, current, new Array[Int](current.length+1))
|
||||
}
|
||||
}
|
||||
println(1)
|
||||
fibIn(0, Array(1), new Array[Int](2))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user