Average loop length: Difference between revisions
Content deleted Content added
Add Factor |
→{{header|Scala}}: migrate to Scala 2.13 |
||
Line 2,184:
object AverageLoopLength extends App {
val factorial:
val results = for (n <- 1 to 20;▼
avg = tested(n, 1000000);▼
theory = expected(n)▼
) yield (n, avg, theory, (avg / theory - 1) * 100)▼
def expected(n: Int): Double = (for (i <- 1 to n) yield factorial(n) / Math.pow(n, i) / factorial(n - i)).sum
def
def trial(n: Int): Double = {
var count = 0
var x = 1
Line 2,200 ⟶ 2,206:
count
}
▲ val results = for (n <- 1 to 20;
▲ avg = tested(n, 1000000);
▲ theory = expected(n)
▲ ) yield (n, avg, theory, (avg / theory - 1) * 100)
Line 2,212 ⟶ 2,211:
println("------------------------------------")
results foreach { n => {
}
|