AoC - "I was told there would be no math"
My solution to Advent of Code 2015 Day 2
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 adventOfCode.y2015.d02
import adventOfCode.lib.Solver
class Solution : Solver {
override fun part1(input: String): Int {
return boxes(input).sumOf { sides ->
2 * sides[0] * sides[1] + 2 * sides[1] * sides[2] + 2 * sides[0] * sides[2] + sides[0] * sides[1]
}
}
override fun part2(input: String): Int {
return boxes(input).sumOf { sides ->
sides[0] * 2 + sides[1] * 2 + sides[0] * sides[1] * sides[2]
}
}
private fun boxes(input: String) = sequence {
input.split('\n').forEach { line ->
val sides = line.split('x')
yield(sides.map { it.trim().toInt() }.sorted())
}
}
}
This post is licensed under CC BY 4.0 by the author.