Basic-benchmark-experiment/Kotlin/code_cycle.kt

18 lines
499 B
Kotlin
Raw Permalink Normal View History

2024-03-11 12:43:52 +02:00
fun main(args: Array<String>) {
val totalAttempts: Int = 256*256*256
var successfulAttempts: Int = 0
for (a in 0..255) {
for (b in 0..255) {
for (c in 0..255) {
if (a + b + c > 300) {
successfulAttempts++
}
}
}
}
println("Iterations: $totalAttempts")
println("Valid sums: $successfulAttempts")
println("Probability: ${successfulAttempts.toFloat() / totalAttempts.toFloat()}")
}