advent-of-code/src/Utils.kt
Chris Hodges 13a3503196 Tested one puzzle.
Change-Id: I60720151667814f13881e16868d570282e509c77
2023-11-17 11:53:16 +01:00

41 lines
900 B
Kotlin

import java.io.File
import java.math.BigInteger
import java.security.MessageDigest
/**
* Reads lines from the given input txt file.
*/
fun readInput(name: String) = File("src", "$name.txt")
.readLines()
fun listOfIntegerLists(input: List<String>): ArrayList<List<Int>> {
val output = ArrayList<List<Int>>()
var currList = ArrayList<Int>()
for(i in input)
{
if(i.isEmpty()){
output.add(currList)
currList = ArrayList<Int>()
} else {
currList.add(i.toInt())
}
}
if(currList.isNotEmpty())
{
output.add(currList)
}
return output
}
/**
* Converts string to md5 hash.
*/
fun String.md5() = BigInteger(1, MessageDigest.getInstance("MD5").digest(toByteArray()))
.toString(16)
.padStart(32, '0')
/**
* The cleaner shorthand for printing output.
*/
fun Any?.println() = println(this)