mirror of
https://github.com/OMGeeky/AdventOfCodeKotlin.git
synced 2026-01-08 20:42:51 +01:00
Initial commit
This commit is contained in:
17
src/Day01.kt
Normal file
17
src/Day01.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
fun main() {
|
||||
fun part1(input: List<String>): Int {
|
||||
return input.size
|
||||
}
|
||||
|
||||
fun part2(input: List<String>): Int {
|
||||
return input.size
|
||||
}
|
||||
|
||||
// test if implementation meets criteria from the description, like:
|
||||
val testInput = readInput("Day01_test")
|
||||
check(part1(testInput) == 1)
|
||||
|
||||
val input = readInput("Day01")
|
||||
part1(input).println()
|
||||
part2(input).println()
|
||||
}
|
||||
21
src/Utils.kt
Normal file
21
src/Utils.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
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()
|
||||
|
||||
/**
|
||||
* 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)
|
||||
Reference in New Issue
Block a user