Skip to content

Commit ad89501

Browse files
committed
Day03 - Part 1
1 parent 6768ff7 commit ad89501

File tree

4 files changed

+239
-0
lines changed

4 files changed

+239
-0
lines changed

src/main/kotlin/Day03.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Day03 : Day {
2+
override fun partOne(filename: String, verbose: Boolean): Any {
3+
val banks = filename.asPath().parseMatrix()
4+
val maxJoltage = banks.map { bank ->
5+
bank.foldIndexed(0L) { index, acc, current ->
6+
if (index < bank.lastIndex) {
7+
bank.drop(index + 1).fold(acc) { acc, next ->
8+
maxOf(acc, "$current$next".toLong())
9+
}
10+
} else {
11+
acc
12+
}
13+
}
14+
}
15+
if (verbose) {
16+
maxJoltage.forEach {
17+
println(it)
18+
}
19+
}
20+
return maxJoltage.sum()
21+
}
22+
23+
override fun partTwo(filename: String, verbose: Boolean): Any {
24+
TODO("Not yet implemented")
25+
}
26+
27+
companion object : Day.Main("Day03.txt") {
28+
@JvmStatic
29+
fun main(args: Array<String>) = main()
30+
}
31+
}

0 commit comments

Comments
 (0)