Files
Advent-of-Code-2019/src/main/kotlin/com/basdado/adventofcode/Utils.kt
2019-12-12 01:04:34 +01:00

37 lines
837 B
Kotlin

package com.basdado.adventofcode
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.FileSystems
import java.util.stream.Stream
fun lines(resourceFile: String): Stream<String> {
val uri = Utils::class.java.getResource(resourceFile).toURI()
// val env = mapOf(Pair("create", "true"))
// FileSystems.newFileSystem(uri, env)
return Files.lines(Paths.get(uri))
}
fun line(resourceFile: String): String {
return lines(resourceFile).findFirst().get()
}
fun pow10(n: Int): Int {
return when (n) {
0 -> 1
1 -> 10
2 -> 100
3 -> 1000
4 -> 10000
5 -> 100000
6 -> 1000000
7 -> 10000000
8 -> 100000000
9 -> 1000000000
else -> throw IllegalArgumentException("Int overflowing with pow10($n)")
}
}
class Utils