day(01): add solution
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
76d8d3b5c6
commit
252617a81d
4 changed files with 2021 additions and 8 deletions
17
src/Day01.kt
17
src/Day01.kt
|
@ -1,17 +1,18 @@
|
|||
fun main() {
|
||||
fun part1(input: List<String>): Int {
|
||||
return input.size
|
||||
fun part1(input: List<Int>): Int {
|
||||
return input.windowed(2).count { it[0] < it[1] }
|
||||
}
|
||||
|
||||
fun part2(input: List<String>): Int {
|
||||
return input.size
|
||||
fun part2(input: List<Int>): Int {
|
||||
return part1(input.windowed(3).map { it.sum() }.toList())
|
||||
}
|
||||
|
||||
// test if implementation meets criteria from the description, like:
|
||||
val testInput = readInput("Day01_test")
|
||||
check(part1(testInput) == 1)
|
||||
val testInput = readInputAsInts("Day01_test")
|
||||
val input = readInputAsInts("Day01")
|
||||
|
||||
val input = readInput("Day01")
|
||||
check(part1(testInput) == 7)
|
||||
println(part1(input))
|
||||
|
||||
check(part2(testInput) == 5)
|
||||
println(part2(input))
|
||||
}
|
||||
|
|
2000
src/Day01.txt
Normal file
2000
src/Day01.txt
Normal file
File diff suppressed because it is too large
Load diff
10
src/Day01_test.txt
Normal file
10
src/Day01_test.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
199
|
||||
200
|
||||
208
|
||||
210
|
||||
200
|
||||
207
|
||||
240
|
||||
269
|
||||
260
|
||||
263
|
|
@ -7,6 +7,8 @@ import java.security.MessageDigest
|
|||
*/
|
||||
fun readInput(name: String) = File("src", "$name.txt").readLines()
|
||||
|
||||
fun readInputAsInts(name: String) = readInput(name).map { it.toInt() }
|
||||
|
||||
/**
|
||||
* Converts string to md5 hash.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue