Kotlin in ICPC

Revision en2, by NeercNews, 2017-12-05 17:10:17


Let us introduce the new programming language in ICPC: Kotlin. It is modern and developing language created by our sponsor JetBrains. Kotlin is inspired by Java and as Java is named after the island. Currently, Kotlin programs are compiled into JVM bytecode, all Java written code can be used from Kotlin sources and Kotlin written code can be used from Java sources as well out of the box. Kotlin being developed now most of the standard libraries are Java library classes, making Kotlin a programing language that is already used in many projects being the main language of their development.

Comparing to Java language some Java disadvantages fixed and new features added. Some of them we will see in today's solution of ICPC World Finals 2016 problem C (101242C - Ceiling Function). Less boilerplate code and syntactic sugar added

  1. new operator omitted
  2. data classes implement hashCode, equals and toString methods depending on constructor parameters
  3. operator overloading
  4. with function, to implement a block of code, making captured value as this
  5. when operator providing better readability of conditional operator in some cases
  6. type inference (IDE supports hints on variable and function types, it's just you don't have to type it)
  7. functional programming style
import java.util.*

data class Tree(var left: Tree? = null, var right: Tree? = null) {
    var value = 0

operator fun Tree?.plus(x: Int): Tree? {
    if (this == null) return Tree().apply { value = x }
    if (x < value) {
        left += x
    } else {
        right += x
    return this

fun main(args: Array<String>) = with(Scanner(System.`in`)) {
    val n = nextInt()
    val k = nextInt()
    val a = Array(n) { IntArray(k) { nextInt() } }
    println(a.map { it.fold(null, Tree?::plus) }.toSet().size)

You can try Kotlin at: https://try.kotlinlang.org

Tags kotlin, jetbrains, icpc world finals


  Rev. Lang. By When Δ Comment
en2 English NeercNews 2017-12-05 17:10:17 79 Tiny change: '="height: 250px; marg' -> '="height: 150px; marg' (published)
en1 English NeercNews 2017-12-05 16:46:51 2050 Initial revision (saved to drafts)