a
This commit is contained in:
@@ -1,5 +1,22 @@
|
||||
package P10
|
||||
|
||||
object FrenshDude {
|
||||
import scala.annotation.tailrec
|
||||
|
||||
object FrenchDude {
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
}
|
||||
def pascalTriangle(c: Int, r: Int): Int = {
|
||||
@tailrec
|
||||
def loop(c0: Int, r0: Int, pred: Array[Int], cur: Array[Int]): Int = {
|
||||
cur(c0) = (if (c0 > 0) pred(c0 - 1) else 0) + (if (c0 < r0) pred(c0) else 0)
|
||||
|
||||
if ((c0 == c) && (r0 == r)) cur(c0)
|
||||
else if (c0 < r0) loop(c0 + 1, r0, pred, cur)
|
||||
else loop(0, r0 + 1, cur, new Array(_length = r0 + 2))
|
||||
}
|
||||
|
||||
if ((c == 0) && (r == 0)) 1
|
||||
else loop(0, 1, Array(1), Array(0, 0))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package P10
|
||||
|
||||
|
||||
object test{
|
||||
object additionCurry{
|
||||
def main(args: Array[String]): Unit = {
|
||||
type DoubleFkt = (Double, Double) => Double
|
||||
def func(a: Double, b: Double):
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
package P10
|
||||
|
||||
object calculate {
|
||||
def main(args: Array[String]): Unit = {
|
||||
type DoubleFkt = (Double, Double) => Double
|
||||
def calc(a:Double,b:Double,func:DoubleFkt):Double={
|
||||
func(a,b)
|
||||
}
|
||||
|
||||
val add =
|
||||
(x: Double, y: Double) => x+y
|
||||
|
||||
val subtract=
|
||||
(x: Double, y: Double) => x-y
|
||||
|
||||
println(calc(1,1,add))
|
||||
println(calc(1,1,subtract))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user