1
0
Fork 0
2021/src/Utils.kt

22 lines
677 B
Kotlin
Raw Normal View History

2021-12-04 00:15:03 +01:00
import java.io.File
import java.math.BigInteger
import java.security.MessageDigest
private fun openFile(day: Int, name: String) = File("src/day%02d".format(day), "$name.txt")
2021-12-04 00:15:03 +01:00
/**
* Reads lines from the given input txt file.
*/
fun readInput(day: Int, name: String) = openFile(day, name).readLines()
2021-12-04 00:15:03 +01:00
fun readInputAsInts(day: Int, name: String) = readInput(day, name).map { it.toInt() }
fun readInputAsCommaSeparatedInts(day: Int, name: String) = openFile(day, name)
.readText()
.split(",")
.map { it.toInt() }
2021-12-04 00:15:03 +01:00
/**
* Converts string to md5 hash.
*/
fun String.md5(): String = BigInteger(1, MessageDigest.getInstance("MD5").digest(toByteArray())).toString(16)