generated from Jadarma/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathY2015D02.kt
24 lines (19 loc) · 820 Bytes
/
Y2015D02.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package aockt.y2015
import io.github.jadarma.aockt.core.Solution
object Y2015D02 : Solution {
/** Parses the [input] and returns a sequence of the three dimensions of each gift, sorted by length. */
private fun dimensions(input: String) =
input
.lineSequence()
.map { it.split('x').map(String::toInt).sorted() }
.onEach { require(it.size == 3) { "Invalid input. Expected exactly three integer dimensions." } }
.map { Triple(it[0], it[1], it[2]) }
override fun partOne(input: String) =
dimensions(input)
.map { (l, w, h) -> 2 * (l * w + w * h + h * l) + l * w }
.sum()
override fun partTwo(input: String) =
dimensions(input)
.map { (l, w, h) -> 2 * (l + w) + l * w * h }
.sum()
}