Update things
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
@Day(1)
|
||||
class Day01(@Lines input: Input<IntArray>) {
|
||||
private val items = input.value
|
||||
|
||||
class Day01(@Lines val items: IntArray) {
|
||||
fun part1(): Int? {
|
||||
items.forEach { a ->
|
||||
items.forEach { b ->
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
@Day(2)
|
||||
class Day02(@Lines input: Input<List<String>>) {
|
||||
class Day02(@Lines input: List<String>) {
|
||||
private data class PasswordEntry(val range: IntRange, val letter: Char, val password: String)
|
||||
|
||||
private val regex = "^(\\d+)-(\\d+) ([a-z]): (.*)$".toRegex()
|
||||
|
||||
private val passwords = input.value.map {
|
||||
private val passwords = input.map {
|
||||
val (_, min, max, letter, password) = regex.find(it)!!.groupValues
|
||||
PasswordEntry(min.toInt()..max.toInt(), letter[0], password)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
@Day(3)
|
||||
class Day03(@Lines val input: Input<List<String>>) {
|
||||
class Day03(@Lines val input: List<String>) {
|
||||
private data class Slope(val x: Int, val y: Int)
|
||||
|
||||
private fun findSlope(slope: Slope): Int {
|
||||
val grid = input.value
|
||||
val grid = input
|
||||
var trees = 0
|
||||
var x = 0
|
||||
var y = 0
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Text
|
||||
|
||||
private typealias Entry = Pair<String, String>
|
||||
private typealias Entries = List<Entry>
|
||||
|
||||
@Day(4)
|
||||
class Day04(@Text val input: Input<String>) {
|
||||
class Day04(@Text val input: String) {
|
||||
|
||||
val entries = input.value.split("\n\n").map {
|
||||
val entries = input.split("\n\n").map {
|
||||
it.split(" ", "\n").map { it.split(":").let { (k, v) -> k to v } }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
@Day(5)
|
||||
class Day05(@Lines val input: Input<List<String>>) {
|
||||
class Day05(@Lines val input: List<String>) {
|
||||
|
||||
private val ids = input.value.map {
|
||||
private val ids = input.map {
|
||||
it.replace("F", "0")
|
||||
.replace("B", "1")
|
||||
.replace("L", "0")
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Text
|
||||
import org.eclipse.collections.impl.factory.primitive.CharBags
|
||||
|
||||
@Day(6)
|
||||
class Day06(@Text val input: Input<String>) {
|
||||
class Day06(@Text val input: String) {
|
||||
|
||||
private val groups = input.value.split("\n\n")
|
||||
private val groups = input.split("\n\n")
|
||||
|
||||
fun part1() = groups.sumBy { it.replace("\n", "").toCharArray().toSet().size }
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import org.eclipse.collections.api.factory.Stacks
|
||||
import org.eclipse.collections.api.multimap.list.ImmutableListMultimap
|
||||
@@ -9,7 +8,7 @@ import org.eclipse.collections.api.stack.MutableStack
|
||||
import org.eclipse.collections.impl.factory.Multimaps
|
||||
|
||||
@Day(7)
|
||||
class Day07(@Lines val input: Input<List<String>>) {
|
||||
class Day07(@Lines val input: List<String>) {
|
||||
|
||||
private data class Bag(val count: Int, val color: String)
|
||||
|
||||
@@ -21,7 +20,7 @@ class Day07(@Lines val input: Input<List<String>>) {
|
||||
val colorRegex = "^(\\w+ \\w+)".toRegex()
|
||||
val requirementRegex = "(\\d+) (\\w+ \\w+) bag".toRegex()
|
||||
|
||||
for (line in input.value) {
|
||||
for (line in input) {
|
||||
val outerColor = colorRegex.find(line)!!.groupValues[1]
|
||||
for (match in requirementRegex.findAll(line)) {
|
||||
val (_, count, color) = match.groupValues
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import org.eclipse.collections.impl.factory.primitive.IntLists
|
||||
import org.eclipse.collections.impl.factory.primitive.IntSets
|
||||
|
||||
@Day(8)
|
||||
class Day08(@Lines val input: Input<List<String>>) {
|
||||
class Day08(@Lines val input: List<String>) {
|
||||
|
||||
private val instructions = input.value.map {
|
||||
private val instructions = input.map {
|
||||
val words = it.split(" ")
|
||||
Instruction(Operation.valueOf(words[0].capitalize()), words[1].toInt())
|
||||
}.toTypedArray()
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
@Day(9)
|
||||
class Day09(@Lines val input: Input<LongArray>) {
|
||||
class Day09(@Lines val input: LongArray) {
|
||||
|
||||
private var part1Result = 0L
|
||||
|
||||
fun part1(): Long? {
|
||||
val longs = input.value
|
||||
|
||||
for (windowStart in 0 until longs.size - 26) {
|
||||
val last = longs[windowStart + 25]
|
||||
for (windowStart in 0 until input.size - 26) {
|
||||
val last = input[windowStart + 25]
|
||||
if (!isValid(windowStart, last)) {
|
||||
part1Result = last
|
||||
return last
|
||||
@@ -26,8 +23,8 @@ class Day09(@Lines val input: Input<LongArray>) {
|
||||
private fun isValid(windowStart: Int, last: Long): Boolean {
|
||||
for (i in windowStart until windowStart + 25) {
|
||||
for (j in windowStart + 1 until windowStart + 25) {
|
||||
val f = input.value[i]
|
||||
val s = input.value[j]
|
||||
val f = input[i]
|
||||
val s = input[j]
|
||||
if (f + s == last && f != s) return true
|
||||
}
|
||||
}
|
||||
@@ -37,10 +34,10 @@ class Day09(@Lines val input: Input<LongArray>) {
|
||||
fun part2(): Long {
|
||||
var size = 2
|
||||
while (true) {
|
||||
for (startIndex in input.value.indices) {
|
||||
val lastIndex = input.value.size - 1 - size
|
||||
for (startIndex in input.indices) {
|
||||
val lastIndex = input.size - 1 - size
|
||||
if (startIndex + size > lastIndex) break
|
||||
val slice = input.value.sliceArray(startIndex..startIndex + size)
|
||||
val slice = input.sliceArray(startIndex..startIndex + size)
|
||||
if (slice.sum() == part1Result) return slice.minOrNull()!! + slice.maxOrNull()!!
|
||||
}
|
||||
size++
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import org.eclipse.collections.api.list.primitive.MutableIntList
|
||||
import org.eclipse.collections.impl.factory.primitive.IntLists
|
||||
import org.eclipse.collections.impl.factory.primitive.IntLongMaps
|
||||
|
||||
@Day(10)
|
||||
class Day10(@Lines val input: Input<IntArray>) {
|
||||
class Day10(@Lines val input: IntArray) {
|
||||
|
||||
fun part1(): Int {
|
||||
val sorted = IntLists.mutable.of(0, *input.value).apply {
|
||||
val sorted = IntLists.mutable.of(0, *input).apply {
|
||||
sortThis()
|
||||
add(last + 3)
|
||||
}.toArray().toList()
|
||||
@@ -28,7 +27,7 @@ class Day10(@Lines val input: Input<IntArray>) {
|
||||
}
|
||||
|
||||
fun part2(): Long {
|
||||
val sorted: MutableIntList = IntLists.mutable.of(*input.value).apply { sortThis() }
|
||||
val sorted: MutableIntList = IntLists.mutable.of(*input).apply { sortThis() }
|
||||
|
||||
val map = IntLongMaps.mutable.empty().apply {
|
||||
put(0, 1L)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
private typealias Seats = Array<CharArray>
|
||||
@@ -25,9 +24,9 @@ private fun Seats.asGridString() = joinToString("\n") { it.joinToString("") }
|
||||
private fun Seats.countOccupied() = sumBy { it.count { it == '#' } }
|
||||
|
||||
@Day(11)
|
||||
class Day11(@Lines val input: Input<List<String>>) {
|
||||
class Day11(@Lines val input: List<String>) {
|
||||
|
||||
private val seats: Seats = input.value.map { it.toCharArray() }.toTypedArray()
|
||||
private val seats: Seats = input.map { it.toCharArray() }.toTypedArray()
|
||||
|
||||
private val directions = listOf(
|
||||
-1 to -1,
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import kotlin.math.abs
|
||||
|
||||
@Day(12)
|
||||
class Day12(@Lines val input: Input<List<String>>) {
|
||||
class Day12(@Lines val input: List<String>) {
|
||||
|
||||
fun part1(): Int {
|
||||
var x = 0
|
||||
@@ -15,7 +14,7 @@ class Day12(@Lines val input: Input<List<String>>) {
|
||||
|
||||
val dirs = listOf("N", "E", "S", "W")
|
||||
|
||||
input.value.forEach {
|
||||
input.forEach {
|
||||
val dir = it.take(1)
|
||||
val steps = it.drop(1).toInt()
|
||||
|
||||
@@ -49,7 +48,7 @@ class Day12(@Lines val input: Input<List<String>>) {
|
||||
var waypointX = 10
|
||||
var waypointY = -1
|
||||
|
||||
input.value.forEach {
|
||||
input.forEach {
|
||||
val dir = it.take(1)
|
||||
val steps = it.drop(1).toInt()
|
||||
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import kotlin.math.abs
|
||||
|
||||
private data class Bus(val index: Int, val id: Long)
|
||||
|
||||
@Day(13)
|
||||
class Day13(@Lines val input: Input<List<String>>) {
|
||||
class Day13(@Lines val input: List<String>) {
|
||||
|
||||
fun part1(): Int {
|
||||
val id = input.value[0].toInt()
|
||||
val id = input[0].toInt()
|
||||
|
||||
val (busId, min) = input.value[1]
|
||||
val (busId, min) = input[1]
|
||||
.splitToSequence(",")
|
||||
.filterNot { it == "x" }
|
||||
.map { it.toInt() }
|
||||
@@ -28,7 +27,7 @@ class Day13(@Lines val input: Input<List<String>>) {
|
||||
private fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b
|
||||
|
||||
fun part2(): Long {
|
||||
val buses = input.value[1]
|
||||
val buses = input[1]
|
||||
.splitToSequence(",")
|
||||
.mapIndexedNotNull { index, bus ->
|
||||
if (bus == "x") null
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import kotlin.math.pow
|
||||
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps
|
||||
import org.eclipse.collections.impl.factory.primitive.LongIntMaps
|
||||
|
||||
@Day(14)
|
||||
class Day14(@Lines val input: Input<List<String>>) {
|
||||
class Day14(@Lines val input: List<String>) {
|
||||
|
||||
private val memRe = "mem\\[(\\d+)] = (.*)$".toRegex()
|
||||
|
||||
@@ -19,7 +18,7 @@ class Day14(@Lines val input: Input<List<String>>) {
|
||||
|
||||
var currentMask: String = ""
|
||||
|
||||
for (line in input.value) {
|
||||
for (line in input) {
|
||||
if (line.startsWith("mask")) {
|
||||
currentMask = line.removePrefix("mask = ")
|
||||
} else {
|
||||
@@ -45,7 +44,7 @@ class Day14(@Lines val input: Input<List<String>>) {
|
||||
|
||||
var currentMask = ""
|
||||
|
||||
for (line in input.value) {
|
||||
for (line in input) {
|
||||
if (line[1] == 'a') {
|
||||
currentMask = line.substring(7)
|
||||
} else {
|
||||
|
||||
@@ -2,15 +2,14 @@ package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Csv
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import kotlin.math.abs
|
||||
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps
|
||||
|
||||
@Day(15)
|
||||
class Day15(@Csv val input: Input<IntArray>) {
|
||||
class Day15(@Csv val input: IntArray) {
|
||||
|
||||
private fun run(until: Int): Int {
|
||||
val start = input.value
|
||||
val start = input
|
||||
|
||||
val map = IntObjectMaps.mutable.empty<IntArray>()
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Groups
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import org.eclipse.collections.api.multimap.list.ListMultimap
|
||||
import org.eclipse.collections.api.multimap.list.MutableListMultimap
|
||||
import org.eclipse.collections.api.multimap.set.MutableSetMultimap
|
||||
@@ -10,11 +9,11 @@ import org.eclipse.collections.impl.factory.Multimaps
|
||||
import org.eclipse.collections.impl.multimap.list.FastListMultimap
|
||||
|
||||
@Day(16)
|
||||
class Day16(@Groups val input: Input<List<List<String>>>) {
|
||||
class Day16(@Groups val input: List<List<String>>) {
|
||||
|
||||
private val rangesGroup = input.value[0]
|
||||
private val myTicket = input.value[1][1]
|
||||
private val nearbyTicketsGroup = input.value[2].drop(1)
|
||||
private val rangesGroup = input[0]
|
||||
private val myTicket = input[1][1]
|
||||
private val nearbyTicketsGroup = input[2].drop(1)
|
||||
|
||||
private val rangeRe = "(\\d+)-(\\d+)".toRegex()
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
private data class Point(val x: Int, val y: Int, val z: Int)
|
||||
@@ -10,7 +9,7 @@ private data class Point4(val x: Int, val y: Int, val z: Int, val blah: Int)
|
||||
private enum class State { Active, Inactive }
|
||||
|
||||
@Day(17)
|
||||
class Day17(@Lines val input: Input<List<String>>) {
|
||||
class Day17(@Lines val input: List<String>) {
|
||||
|
||||
fun part1(): Int {
|
||||
val grid = parseGrid { x, y -> Point(x, y, 0) }
|
||||
@@ -26,7 +25,7 @@ class Day17(@Lines val input: Input<List<String>>) {
|
||||
|
||||
private fun <T> parseGrid(pointFactory: (x: Int, y: Int) -> T): MutableMap<T, State> {
|
||||
val grid = mutableMapOf<T, State>()
|
||||
input.value.forEachIndexed { index, row ->
|
||||
input.forEachIndexed { index, row ->
|
||||
row.forEachIndexed { col, char ->
|
||||
val state = if (char == '#') State.Active else State.Inactive
|
||||
grid[pointFactory(index, col)] = state
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import java.util.*
|
||||
import org.slf4j.Logger
|
||||
@@ -19,10 +18,10 @@ private inline fun Logger.debug(msg: () -> Any) {
|
||||
}
|
||||
|
||||
@Day(18)
|
||||
class Day18(@Lines val input: Input<List<String>>) {
|
||||
class Day18(@Lines val input: List<String>) {
|
||||
|
||||
private val logger = LoggerFactory.getLogger("Day18")
|
||||
private val lines = input.value.map { it.replace(" ", "") }
|
||||
private val lines = input.map { it.replace(" ", "") }
|
||||
|
||||
private fun parseGroups(line: String): Map<Int, List<IntRange>> {
|
||||
var depth = 0
|
||||
|
||||
@@ -2,14 +2,12 @@ package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Groups
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@Day(19)
|
||||
class Day19(@Groups val input: Input<List<List<String>>>) {
|
||||
private val rules = input.value[0]
|
||||
private val messages = input.value[1]
|
||||
class Day19(@Groups val input: List<List<String>>) {
|
||||
private val rules = input[0]
|
||||
private val messages = input[1]
|
||||
|
||||
sealed class Rule {
|
||||
data class CharRule(val value: Char) : Rule()
|
||||
|
||||
@@ -5,16 +5,13 @@ import be.vandewalleh.aoc.days.geometry.gridOf
|
||||
import be.vandewalleh.aoc.days.geometry.transformations
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Groups
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.math.sqrt
|
||||
|
||||
private typealias Tile = Grid<Char>
|
||||
|
||||
@Day(20)
|
||||
class Day20(@Groups val input: Input<List<List<String>>>) {
|
||||
private val tiles: Map<Int, Tile> = input.value
|
||||
class Day20(@Groups val input: List<List<String>>) {
|
||||
private val tiles: Map<Int, Tile> = input
|
||||
.map { it[0].let { it.substring(5 until it.indexOf(':')).toInt() } to it.drop(1) }
|
||||
.associate { (id, tile) -> id to gridOf(tile) }
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import org.eclipse.collections.api.factory.Bags
|
||||
import org.eclipse.collections.api.multimap.set.MutableSetMultimap
|
||||
import org.eclipse.collections.impl.factory.Multimaps
|
||||
|
||||
@Day(21)
|
||||
class Day21(@Lines val input: Input<List<String>>) {
|
||||
private val foods = input.value.map { line ->
|
||||
class Day21(@Lines val input: List<String>) {
|
||||
private val foods = input.map { line ->
|
||||
val parOpen = line.indexOf('(')
|
||||
val ingredients = line.substring(0 until parOpen - 1).split(" ")
|
||||
val allergens = line.substring(parOpen + 1 until line.length - 1).removePrefix("contains ").split(", ")
|
||||
|
||||
@@ -2,14 +2,13 @@ package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Groups
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
|
||||
private data class PlayedGame(val a: List<Int>, val b: List<Int>)
|
||||
|
||||
@Day(22)
|
||||
class Day22(@Groups val input: Input<List<List<String>>>) {
|
||||
private val one = input.value[0].drop(1).map { it.toInt() }
|
||||
private val two = input.value[1].drop(1).map { it.toInt() }
|
||||
class Day22(@Groups val input: List<List<String>>) {
|
||||
private val one = input[0].drop(1).map { it.toInt() }
|
||||
private val two = input[1].drop(1).map { it.toInt() }
|
||||
|
||||
fun part1(): Long {
|
||||
val oneDeque = ArrayDeque(one)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Text
|
||||
|
||||
@Day(23)
|
||||
class Day23(@Text val input: Input<String>) {
|
||||
private val cups = input.value.toCharArray().map { it.toString().toInt() }
|
||||
class Day23(@Text val input: String) {
|
||||
private val cups = input.toCharArray().map { it.toString().toInt() }
|
||||
|
||||
private fun <T> ringSequence(head: Ring.Node<T>) = generateSequence(head) { it.next }
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import org.eclipse.collections.api.bag.Bag
|
||||
import org.eclipse.collections.api.bag.MutableBag
|
||||
import org.eclipse.collections.api.factory.Bags
|
||||
|
||||
@Day(24)
|
||||
class Day24(@Lines val input: Input<List<String>>) {
|
||||
class Day24(@Lines val input: List<String>) {
|
||||
|
||||
private data class HexPoint(val x: Int, val y: Int, val z: Int) {
|
||||
fun translate(other: HexPoint) = HexPoint(this.x + other.x, this.y + other.y, this.z + other.z)
|
||||
@@ -31,7 +30,7 @@ class Day24(@Lines val input: Input<List<String>>) {
|
||||
.map { Direction.valueOf(it.toUpperCase()) }
|
||||
.toList()
|
||||
|
||||
private val tiles = input.value.map { parseTile(it) }.map {
|
||||
private val tiles = input.map { parseTile(it) }.map {
|
||||
it.map { it.coordinates }.reduce { acc, ints -> acc.translate(ints) }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
|
||||
@Day(25)
|
||||
class Day25(@Lines val input: Input<IntArray>) {
|
||||
private val doorPublicKey = input.value[0]
|
||||
private val cardPublicKey = input.value[1]
|
||||
class Day25(@Lines val input: IntArray) {
|
||||
private val doorPublicKey = input[0]
|
||||
private val cardPublicKey = input[1]
|
||||
|
||||
private fun encryptionKey(loopSize: Int, publicKey: Int) = transformSubjectNumber(loopSize, publicKey)
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@ package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.factory.createDay
|
||||
|
||||
fun main() = with(createDay<Day25>()) {
|
||||
fun main() = with(createDay<Day15>()) {
|
||||
println(part1())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package be.vandewalleh.aoc.days.geometry
|
||||
|
||||
import java.util.*
|
||||
|
||||
private fun <T> ArrayList<T>.reversed(): ArrayList<T> {
|
||||
val out = ArrayList<T>(this.size)
|
||||
asReversed().forEach { out.add(it) }
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import io.micronaut.context.BeanContext
|
||||
import io.micronaut.context.getBean
|
||||
import be.vandewalleh.aoc.utils.factory.createDay
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class Day01Test {
|
||||
|
||||
private val day = BeanContext.run().getBean<Day01>()
|
||||
private val day = createDay<Day01>()
|
||||
|
||||
@Test
|
||||
fun `part1 result`() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.createDay
|
||||
import be.vandewalleh.aoc.utils.factory.createDay
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.Nested
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@@ -22,7 +22,7 @@ class Day03Test {
|
||||
"#.##...#...",
|
||||
"#...##....#",
|
||||
".#..#...#.#",
|
||||
).let { Input(it) }
|
||||
)
|
||||
|
||||
private val day03 = Day03(example)
|
||||
|
||||
@@ -43,11 +43,13 @@ class Day03Test {
|
||||
private val day03 = createDay<Day03>()
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
fun `part1 result`() {
|
||||
assertThat(day03.part1()).isEqualTo(294)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
fun `part2 result`() {
|
||||
assertThat(day03.part2()).isEqualTo(5774564250)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.factory.createDay
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Nested
|
||||
@@ -26,7 +25,6 @@ class Day04Test {
|
||||
hcl:#cfa07d eyr:2025 pid:166559648
|
||||
iyr:2011 ecl:brn hgt:59in
|
||||
""".trimIndent()
|
||||
.let { Input(it) }
|
||||
|
||||
private val day04 = Day04(example)
|
||||
|
||||
@@ -63,7 +61,7 @@ class Day04Test {
|
||||
hgt:59cm ecl:zzz
|
||||
eyr:2038 hcl:74454a iyr:2023
|
||||
pid:3556412378 byr:2007
|
||||
""".trimIndent().let { Input(it) }
|
||||
""".trimIndent()
|
||||
|
||||
assertThat(Day04(input).part2()).isEqualTo(0)
|
||||
}
|
||||
@@ -83,7 +81,7 @@ class Day04Test {
|
||||
eyr:2022
|
||||
|
||||
iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
|
||||
""".trimIndent().let { Input(it) }
|
||||
""".trimIndent()
|
||||
|
||||
assertThat(Day04(input).part2()).isEqualTo(4)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.CsvSource
|
||||
@@ -20,7 +19,7 @@ class Day13Test {
|
||||
)
|
||||
@ParameterizedTest
|
||||
fun examples(buses: String, answer: Long) {
|
||||
val input = Input(listOf("", buses))
|
||||
val input = listOf("", buses)
|
||||
assertThat(Day13(input).part2()).isEqualTo(answer)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.CsvSource
|
||||
@@ -17,7 +16,7 @@ class Day18Test {
|
||||
])
|
||||
@ParameterizedTest
|
||||
fun examplesPart2(input: String, output: Long) {
|
||||
val day18 = Day18(Input(listOf(input)))
|
||||
val day18 = Day18(listOf(input))
|
||||
assertThat(day18.part2()).isEqualTo(output)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user