ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

How to write Kotlin solutions

Kotlin programs are compiled on the server by the Kotlin command line compiler 1.1.4. The compiler is invoked with the following parameters:

kotlinc Main.kt -jvm-target 1.8

Solutions are executed by the Java 8 interpreter:

java -client -Xmx544m -Xss64m -DONLINE_JUDGE
    -classpath .;kotlin-runtime.jar;kotlin-reflect.jar MainKt

You can find the compiler here.

Examples of solving a problem

A sample solution for 1000. A + B problem in Kotlin:

fun main(args: Array<String>) {
   val (x, y) = readLine()!!.split(' ').map(String::toInt)
   println(x + y)
}

Or even shorter:

fun main(args: Array<String>) =
   print(readLine()!!.split(' ').map(String::toInt).sum())

A sample solution for 1001. Reverse Root in Kotlin:

fun main(args: Array<String>) {
   val nums = mutableListOf<Double>()
   while (true) {
      nums +=
         (readLine() ?: break)
            .split(' ')
            .filter { !it.isEmpty() }
            .map { it.toDouble() }
   }
   nums.reversed()
       .forEach { println(Math.sqrt(it)) }
}

Or once again in a single operator:

fun main(args: Array<String>) =
   generateSequence { readLine() }
      .takeWhile { true }
      .map { a -> a.split(' ').filter(String::isNotEmpty).toMutableList() }
      .fold(mutableListOf<String>(), { a, b -> (a + b).toMutableList() })
      .map(String::toDouble)
      .map { x -> Math.sqrt(x) }
      .reversed()
      .forEach(::println)