This commit is contained in:
2024-02-11 17:49:29 +01:00
parent 489ca42d32
commit 20099ae740
85 changed files with 3383 additions and 2024 deletions

View 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))
}
}

View File

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