Skip to content

Commit 321e534

Browse files
committed
Solution 2015-02 (I Was Told There Would Be No Math)
1 parent 171d9d7 commit 321e534

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package de.ronny_h.aoc.year15.day02
2+
3+
import de.ronny_h.aoc.AdventOfCode
4+
5+
fun main() = IWasToldThereWouldBeNoMath().run(1586300, 3737498)
6+
7+
class IWasToldThereWouldBeNoMath : AdventOfCode<Int>(2015, 2) {
8+
data class Present(val length: Int, val width: Int, val height: Int) {
9+
fun surfaces() = listOf(2 * length * width, 2 * width * height, 2 * height * length)
10+
fun smallestPerimeter() = 2 * (width + length + height - listOf(width, height, length).max())
11+
fun volume() = length * width * height
12+
}
13+
14+
override fun part1(input: List<String>): Int =
15+
input.toPresents()
16+
.map(Present::surfaces)
17+
.sumOf { it.sum() + it.min() / 2 }
18+
19+
override fun part2(input: List<String>): Int =
20+
input.toPresents()
21+
.sumOf { it.smallestPerimeter() + it.volume() }
22+
23+
private fun List<String>.toPresents() = map { it.split("x") }
24+
.map { (l, w, h) -> Present(l.toInt(), w.toInt(), h.toInt()) }
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package de.ronny_h.aoc.year15.day02
2+
3+
import io.kotest.core.spec.style.StringSpec
4+
import io.kotest.matchers.shouldBe
5+
6+
class IWasToldThereWouldBeNoMathTest : StringSpec({
7+
8+
"part 1: A present with dimensions 2x3x4 requires 58 square feet of wrapping paper" {
9+
val input = listOf("2x3x4")
10+
IWasToldThereWouldBeNoMath().part1(input) shouldBe 58
11+
}
12+
"part 1: A present with dimensions 1x1x10 requires 43 square feet of wrapping paper" {
13+
val input = listOf("1x1x10")
14+
IWasToldThereWouldBeNoMath().part1(input) shouldBe 43
15+
}
16+
17+
"part 2: A present with dimensions 2x3x4 requires 34 feet of ribbon" {
18+
val intput = listOf("2x3x4")
19+
IWasToldThereWouldBeNoMath().part2(intput) shouldBe 34
20+
}
21+
"part 2: A present with dimensions 1x1x10 requires 14 feet of ribbon" {
22+
val intput = listOf("1x1x10")
23+
IWasToldThereWouldBeNoMath().part2(intput) shouldBe 14
24+
}
25+
})

0 commit comments

Comments
 (0)