1
0
This commit is contained in:
2021-12-03 12:34:02 +01:00
parent b9a8e7585b
commit 811a6a0af0
11 changed files with 66 additions and 187 deletions
+5 -4
View File
@@ -1,12 +1,13 @@
package be.vandewalleh.aoc.days
import be.vandewalleh.aoc.utils.BaseDay
import be.vandewalleh.aoc.utils.input.Day
import be.vandewalleh.aoc.utils.input.Lines
@Day
class Day01(@Lines val items: IntArray) {
class Day01 : BaseDay() {
private val items by lazy { input.lines.ints }
fun part1(): Int {
override fun part1(): Int {
var count = 0
for (i in 0 until items.size - 1) {
if (items[i] < items[i + 1]) count++
@@ -14,7 +15,7 @@ class Day01(@Lines val items: IntArray) {
return count
}
fun part2(): Int {
override fun part2(): Int {
var count = 0
for (i in 0 until items.size - 3) {
val a = items.drop(i).take(3).sum()
+17 -17
View File
@@ -1,39 +1,39 @@
package be.vandewalleh.aoc.days
import be.vandewalleh.aoc.utils.BaseDay
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() } }
class Day02 : BaseDay() {
private val lines by lazy { input.lines.value.map { it.split(' ').let { it[0] to it[1].toInt() } } }
fun part1(): Any {
override fun part1(): Int {
var horizontalPosition = 0
var depth = 0
lines.forEach { (direction, value) ->
when (direction) {
"forward" -> horizontalPosition += value
"down" -> depth += value
"up" -> depth -= value
}
when (direction) {
"forward" -> horizontalPosition += value
"down" -> depth += value
"up" -> depth -= value
}
}
return horizontalPosition * depth
}
fun part2(): Any {
override 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
when (direction) {
"forward" -> {
horizontalPosition += value
depth += aim * value
}
"down" -> aim += value
"up" -> aim -= value
}
}
return horizontalPosition * depth
}