1
0

Day02 2021

This commit is contained in:
2021-12-02 09:08:06 +01:00
parent 15b11a191d
commit b9a8e7585b
3 changed files with 1058 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package be.vandewalleh.aoc.days
import be.vandewalleh.aoc.utils.input.Day
import be.vandewalleh.aoc.utils.input.Text
@Day
class Day02(@Text input: String) {
private val lines = input.lines().map { it.split(' ').let { it[0] to it[1].toInt() } }
fun part1(): Any {
var horizontalPosition = 0
var depth = 0
lines.forEach { (direction, value) ->
when (direction) {
"forward" -> horizontalPosition += value
"down" -> depth += value
"up" -> depth -= value
}
}
return horizontalPosition * depth
}
fun part2(): Any {
var horizontalPosition = 0
var depth = 0
var aim = 0
lines.forEach { (direction, value) ->
when (direction) {
"forward" -> {
horizontalPosition += value
depth += aim * value
}
"down" -> aim += value
"up" -> aim -= value
}
}
return horizontalPosition * depth
}
}
File diff suppressed because it is too large Load Diff