1
0
Fork 0

day(01): add solution

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2021-12-04 13:26:57 +01:00
parent 76d8d3b5c6
commit 252617a81d
4 changed files with 2021 additions and 8 deletions

View file

@ -1,17 +1,18 @@
fun main() { fun main() {
fun part1(input: List<String>): Int { fun part1(input: List<Int>): Int {
return input.size return input.windowed(2).count { it[0] < it[1] }
} }
fun part2(input: List<String>): Int { fun part2(input: List<Int>): Int {
return input.size return part1(input.windowed(3).map { it.sum() }.toList())
} }
// test if implementation meets criteria from the description, like: val testInput = readInputAsInts("Day01_test")
val testInput = readInput("Day01_test") val input = readInputAsInts("Day01")
check(part1(testInput) == 1)
val input = readInput("Day01") check(part1(testInput) == 7)
println(part1(input)) println(part1(input))
check(part2(testInput) == 5)
println(part2(input)) println(part2(input))
} }

2000
src/Day01.txt Normal file

File diff suppressed because it is too large Load diff

10
src/Day01_test.txt Normal file
View file

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263

View file

@ -7,6 +7,8 @@ import java.security.MessageDigest
*/ */
fun readInput(name: String) = File("src", "$name.txt").readLines() fun readInput(name: String) = File("src", "$name.txt").readLines()
fun readInputAsInts(name: String) = readInput(name).map { it.toInt() }
/** /**
* Converts string to md5 hash. * Converts string to md5 hash.
*/ */