1
0
Fork 0
2021/src/Utils.kt
Matej Focko d7cde13a2e day(06): add solution
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-06 10:35:12 +01:00

21 lines
677 B
Kotlin

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")
/**
* Reads lines from the given input txt file.
*/
fun readInput(day: Int, name: String) = openFile(day, name).readLines()
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() }
/**
* Converts string to md5 hash.
*/
fun String.md5(): String = BigInteger(1, MessageDigest.getInstance("MD5").digest(toByteArray())).toString(16)