Created
August 14, 2020 14:24
-
-
Save twobiers/f7dd7a5910866011701c753b4ca45e13 to your computer and use it in GitHub Desktop.
Kotlin Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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