20 lines
553 B
Kotlin
20 lines
553 B
Kotlin
|
import kotlin.random.Random
|
||
|
|
||
|
fun main(args: Array<String>) {
|
||
|
val totalAttempts: Int = 15_000_000
|
||
|
var successfulAttempts: Int = 0
|
||
|
|
||
|
for (i in 0..totalAttempts) {
|
||
|
var a: Int = Random.nextInt(256)
|
||
|
var b: Int = Random.nextInt(256)
|
||
|
var c: Int = Random.nextInt(256)
|
||
|
|
||
|
if (a + b + c > 300) {
|
||
|
successfulAttempts++
|
||
|
}
|
||
|
}
|
||
|
|
||
|
println("Iterations: $totalAttempts")
|
||
|
println("Valid sums: $successfulAttempts")
|
||
|
println("Probability: ${successfulAttempts.toFloat() / totalAttempts.toFloat()}")
|
||
|
}
|