Skip to content

Instantly share code, notes, and snippets.

@twobiers
Created August 14, 2020 14:24
Show Gist options
  • Save twobiers/f7dd7a5910866011701c753b4ca45e13 to your computer and use it in GitHub Desktop.
Save twobiers/f7dd7a5910866011701c753b4ca45e13 to your computer and use it in GitHub Desktop.
Kotlin Snippets
/*
* Small Snippet to read input from stdin as a sequence to process input in a functional way.
*/
fun main() {
val lines = generateSequence(::readLine) {
readLine()
}
val avg = lines.takeWhile { it.trim() != "." }.map { it.toInt() }.average()
println(avg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment