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
- new operator omitted
- data classes implement hashCode, equals and toString methods depending on constructor parameters
- operator overloading
- with function, to implement a block of code, making captured value as this
- when operator providing better readability of conditional operator in some cases
- type inference (IDE supports hints on variable and function types, it's just you don't have to type it)
- 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