Initial commit
This commit is contained in:
10
Kotlin/Makefile
Normal file
10
Kotlin/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
compile:
|
||||
kotlinc code_cycle.kt -include-runtime -d code_cycle.jar
|
||||
kotlinc code_unoptimised.kt -include-runtime -d code_unoptimised.jar
|
||||
|
||||
compile-on-premise:
|
||||
/home/shared-space-1/kotlinc/bin/kotlinc code_cycle.kt -include-runtime -d code_cycle.jar
|
||||
/home/shared-space-1/kotlinc/bin/kotlinc code_unoptimised.kt -include-runtime -d code_unoptimised.jar
|
||||
|
||||
clean:
|
||||
rm *.jar
|
||||
18
Kotlin/code_cycle.kt
Normal file
18
Kotlin/code_cycle.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
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()}")
|
||||
}
|
||||
20
Kotlin/code_unoptimised.kt
Normal file
20
Kotlin/code_unoptimised.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
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()}")
|
||||
}
|
||||
Reference in New Issue
Block a user