Update things
This commit is contained in:
parent
ccfcf5a259
commit
322f8eb45a
@ -2,7 +2,6 @@ package be.vandewalleh.aoc;
|
||||
|
||||
import be.vandewalleh.aoc.utils.factory.Days;
|
||||
import be.vandewalleh.aoc.utils.input.Day;
|
||||
import be.vandewalleh.aoc.utils.input.Input;
|
||||
import be.vandewalleh.aoc.utils.input.Lines;
|
||||
|
||||
@Day(1)
|
||||
@ -16,8 +15,8 @@ public class Day01 {
|
||||
|
||||
private final int[] input;
|
||||
|
||||
public Day01(@Lines Input<int[]> input) {
|
||||
this.input = input.getValue();
|
||||
public Day01(@Lines int[] input) {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
private int fuel(int mass) {
|
||||
|
||||
@ -4,7 +4,6 @@ import be.vandewalleh.aoc.intcode.IntCodeInterpreter;
|
||||
import be.vandewalleh.aoc.utils.factory.Days;
|
||||
import be.vandewalleh.aoc.utils.input.Csv;
|
||||
import be.vandewalleh.aoc.utils.input.Day;
|
||||
import be.vandewalleh.aoc.utils.input.Input;
|
||||
|
||||
@Day(2)
|
||||
public class Day02 {
|
||||
@ -17,8 +16,8 @@ public class Day02 {
|
||||
|
||||
private final int[] input;
|
||||
|
||||
public Day02(@Csv Input<int[]> input) {
|
||||
this.input = input.getValue();
|
||||
public Day02(@Csv int[] input) {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
private long runInterpreterWith(int noun, int verb) {
|
||||
|
||||
@ -4,7 +4,6 @@ import be.vandewalleh.aoc.geometry.Direction2D;
|
||||
import be.vandewalleh.aoc.geometry.Point2D;
|
||||
import be.vandewalleh.aoc.utils.factory.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.ArrayList;
|
||||
@ -23,9 +22,9 @@ public class Day03 {
|
||||
private final String[] wireA;
|
||||
private final String[] wireB;
|
||||
|
||||
public Day03(@Lines Input<List<String>> input) {
|
||||
this.wireA = input.getValue().get(0).split(",");
|
||||
this.wireB = input.getValue().get(1).split(",");
|
||||
public Day03(@Lines List<String> input) {
|
||||
this.wireA = input.get(0).split(",");
|
||||
this.wireB = input.get(1).split(",");
|
||||
}
|
||||
|
||||
private List<Point2D> path(String[] wire) {
|
||||
|
||||
@ -2,7 +2,6 @@ package be.vandewalleh.aoc;
|
||||
|
||||
import be.vandewalleh.aoc.utils.factory.Days;
|
||||
import be.vandewalleh.aoc.utils.input.Day;
|
||||
import be.vandewalleh.aoc.utils.input.Input;
|
||||
import be.vandewalleh.aoc.utils.input.Text;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -21,8 +20,8 @@ public class Day04 {
|
||||
private final int min;
|
||||
private final int max;
|
||||
|
||||
public Day04(@Text Input<String> input) {
|
||||
var spl = input.getValue().split("-", 2);
|
||||
public Day04(@Text String input) {
|
||||
var spl = input.split("-", 2);
|
||||
min = Integer.parseInt(spl[0]);
|
||||
max = Integer.parseInt(spl[1]);
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@ import be.vandewalleh.aoc.intcode.IntCodeInterpreter;
|
||||
import be.vandewalleh.aoc.utils.factory.Days;
|
||||
import be.vandewalleh.aoc.utils.input.Csv;
|
||||
import be.vandewalleh.aoc.utils.input.Day;
|
||||
import be.vandewalleh.aoc.utils.input.Input;
|
||||
|
||||
@Day(5)
|
||||
public class Day05 {
|
||||
@ -17,8 +16,8 @@ public class Day05 {
|
||||
|
||||
private final int[] input;
|
||||
|
||||
public Day05(@Csv Input<int[]> input) {
|
||||
this.input = input.getValue();
|
||||
public Day05(@Csv int[] input) {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
private Long part1() {
|
||||
|
||||
@ -2,7 +2,6 @@ package be.vandewalleh.aoc;
|
||||
|
||||
import be.vandewalleh.aoc.utils.factory.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.*;
|
||||
@ -18,8 +17,8 @@ public class Day06 {
|
||||
|
||||
private final List<String> input;
|
||||
|
||||
public Day06(@Lines Input<List<String>> input) {
|
||||
this.input = input.getValue();
|
||||
public Day06(@Lines List<String> input) {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
private final Map<String, String> reverseOrbits = new HashMap<>();
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package be.vandewalleh.aoc.intcode;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public enum OpCode {
|
||||
Add(1, 3),
|
||||
Multiply(2, 3),
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +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 {
|
||||
var count = 0
|
||||
|
||||
@ -2,6 +2,8 @@ package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.factory.createDay
|
||||
|
||||
fun main() = with(createDay<Day01>()) {
|
||||
fun main() {
|
||||
with(createDay<Day01>()) {
|
||||
println(part2())
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20")
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0")
|
||||
implementation("com.konghq:unirest-java:3.11.04")
|
||||
}
|
||||
|
||||
@ -17,10 +17,10 @@ object Libs {
|
||||
}
|
||||
|
||||
object Micronaut {
|
||||
private const val version = "2.2.0"
|
||||
private const val version = "3.2.0"
|
||||
const val inject = "io.micronaut:micronaut-inject:$version"
|
||||
const val core = "io.micronaut:micronaut-core:$version"
|
||||
const val kotlin = "io.micronaut.kotlin:micronaut-kotlin-extension-functions:$version"
|
||||
const val kotlin = "io.micronaut.kotlin:micronaut-kotlin-extension-functions:3.0.0"
|
||||
const val processor = "io.micronaut:micronaut-inject-java:$version"
|
||||
}
|
||||
|
||||
|
||||
@ -14,11 +14,10 @@ group = "be.vandewalleh"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_15
|
||||
targetCompatibility = JavaVersion.VERSION_15
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
options.compilerArgs.add("--enable-preview")
|
||||
}
|
||||
|
||||
@ -7,12 +7,12 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.4.20"))
|
||||
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.6.0"))
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
jvmTarget = "15"
|
||||
jvmTarget = "17"
|
||||
javaParameters = true
|
||||
freeCompilerArgs = listOf(
|
||||
"-Xinline-classes",
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-rc-1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
rootProject.name = "Advent of Code"
|
||||
include("utils")
|
||||
include("2019")
|
||||
include("2020")
|
||||
include("2021")
|
||||
|
||||
@ -4,26 +4,42 @@ package be.vandewalleh.aoc.utils.input
|
||||
|
||||
import io.micronaut.context.annotation.Prototype
|
||||
import io.micronaut.core.annotation.Introspected
|
||||
import javax.inject.Qualifier
|
||||
import jakarta.inject.Qualifier
|
||||
import java.lang.annotation.Inherited
|
||||
|
||||
@Prototype
|
||||
@Qualifier
|
||||
@Introspected
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Day(val value: Int)
|
||||
|
||||
@Qualifier
|
||||
@Prototype
|
||||
@Inherited
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class DayInput
|
||||
|
||||
@DayInput
|
||||
@Qualifier
|
||||
@Prototype
|
||||
@Inherited
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Csv
|
||||
|
||||
@DayInput
|
||||
@Qualifier
|
||||
@Prototype
|
||||
@Inherited
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Text
|
||||
|
||||
@DayInput
|
||||
@Qualifier
|
||||
@Prototype
|
||||
@Inherited
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Lines
|
||||
|
||||
@DayInput
|
||||
@Qualifier
|
||||
@Prototype
|
||||
@Inherited
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Groups
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
package be.vandewalleh.aoc.utils.input
|
||||
|
||||
/**
|
||||
* Wrapper class so that micronaut is not confused with an other injectable
|
||||
* container type when using an iterable / array
|
||||
*/
|
||||
data class Input<T>(val value: T)
|
||||
@ -6,75 +6,39 @@ import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.readLines
|
||||
import kotlin.io.path.readText
|
||||
|
||||
/**
|
||||
* Load challenge inputs and convert them to the appropriate format
|
||||
*
|
||||
* contains horrible hacks while waiting for generic support in bean injection
|
||||
* @see [micronaut-2775](https://github.com/micronaut-projects/micronaut-core/issues/2775)
|
||||
*/
|
||||
@Factory
|
||||
@ExperimentalPathApi
|
||||
class InputFactory(private val resourceLoader: ResourceLoader) {
|
||||
|
||||
@Csv
|
||||
fun csv(injectionPoint: InjectionPoint<*>): Input<*> =
|
||||
when (val param = injectionPoint.typeNameOfAnnotation<Csv>()) {
|
||||
INT_ARRAY -> injectionPoint
|
||||
.read()
|
||||
.split(",")
|
||||
.map { it.toInt() }
|
||||
.toIntArray()
|
||||
.wrap()
|
||||
LONG_ARRAY -> injectionPoint
|
||||
.read()
|
||||
.split(",")
|
||||
.map { it.toLong() }
|
||||
.toLongArray()
|
||||
.wrap()
|
||||
else -> error("Unsupported type $param")
|
||||
}
|
||||
fun csvInts(injectionPoint: InjectionPoint<*>): IntArray =
|
||||
injectionPoint.csv().map { it.toInt() }.toIntArray()
|
||||
|
||||
@Csv
|
||||
fun csvLongs(injectionPoint: InjectionPoint<*>): LongArray =
|
||||
injectionPoint.csv().map { it.toLong() }.toLongArray()
|
||||
|
||||
private fun InjectionPoint<*>.csv() = read().split(",")
|
||||
|
||||
@Lines
|
||||
fun lines(injectionPoint: InjectionPoint<*>): Input<*> =
|
||||
when (val param = injectionPoint.typeNameOfAnnotation<Lines>()) {
|
||||
INT_ARRAY -> injectionPoint
|
||||
.lines()
|
||||
.map { it.toInt() }
|
||||
.toList()
|
||||
.toIntArray()
|
||||
.wrap()
|
||||
LONG_ARRAY -> injectionPoint
|
||||
.lines()
|
||||
.map { it.toLong() }
|
||||
.toList()
|
||||
.toLongArray()
|
||||
.wrap()
|
||||
STRING_LIST -> injectionPoint
|
||||
.lines()
|
||||
.toList()
|
||||
.wrap()
|
||||
else -> error("Unsupported type $param")
|
||||
}
|
||||
fun linesInts(injectionPoint: InjectionPoint<*>): IntArray =
|
||||
injectionPoint.lines().map { it.toInt() }.toList().toIntArray()
|
||||
|
||||
@Lines
|
||||
fun linesLongs(injectionPoint: InjectionPoint<*>): LongArray =
|
||||
injectionPoint.lines().map { it.toLong() }.toList().toLongArray()
|
||||
|
||||
@Lines
|
||||
fun lines(injectionPoint: InjectionPoint<*>): List<String> =
|
||||
injectionPoint.lines().toList()
|
||||
|
||||
@Text
|
||||
fun text(injectionPoint: InjectionPoint<*>): Input<String> =
|
||||
injectionPoint.read().wrap()
|
||||
fun text(injectionPoint: InjectionPoint<*>): String =
|
||||
injectionPoint.read()
|
||||
|
||||
@Groups
|
||||
fun groups(injectionPoint: InjectionPoint<*>): Input<List<List<String>>> =
|
||||
injectionPoint.read().split("\n\n").map { it.lines() }.wrap()
|
||||
|
||||
|
||||
private fun <T> T.wrap() = Input(this)
|
||||
|
||||
private inline fun <reified T : Annotation> InjectionPoint<*>.typeNameOfAnnotation() = declaringBean
|
||||
.constructor
|
||||
.arguments
|
||||
.find { it.hasAnnotation<T>() }
|
||||
?.typeName
|
||||
?.removePrefix("be.vandewalleh.aoc.utils.input.Input<")
|
||||
?.removeSuffix(">")
|
||||
?: error("??")
|
||||
fun groups(injectionPoint: InjectionPoint<*>): List<List<String>> =
|
||||
injectionPoint.read().split("\n\n").map { it.lines() }
|
||||
|
||||
private fun InjectionPoint<*>.path() = resourceLoader.ofDay(getDay(this))
|
||||
private fun InjectionPoint<*>.read() = path().readText().trim()
|
||||
@ -93,10 +57,4 @@ class InputFactory(private val resourceLoader: ResourceLoader) {
|
||||
return dayAnnotation.get().intValue("value").asInt
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val INT_ARRAY = "int[]"
|
||||
private const val LONG_ARRAY = "long[]"
|
||||
private const val STRING_LIST = "java.util.List<java.lang.String>"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,3 @@ import java.util.*
|
||||
|
||||
internal inline fun <reified T : Annotation> AnnotationMetadataProvider.findAnnotation(): Optional<AnnotationValue<T>> =
|
||||
findAnnotation(T::class.java)
|
||||
|
||||
internal inline fun <reified T : Annotation> AnnotationMetadataProvider.hasAnnotation(): Boolean =
|
||||
findAnnotation(T::class.java).isPresent
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package be.vandewalleh.aoc.utils.input
|
||||
|
||||
import jakarta.inject.Singleton
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import javax.inject.Singleton
|
||||
|
||||
interface ResourceLoader {
|
||||
fun ofDay(day: Int): Path
|
||||
|
||||
@ -3,7 +3,7 @@ package be.vandewalleh.aoc.utils.input
|
||||
import be.vandewalleh.aoc.utils.factory.createDay
|
||||
import com.google.common.jimfs.Jimfs
|
||||
import io.micronaut.context.annotation.Replaces
|
||||
import javax.inject.Singleton
|
||||
import jakarta.inject.Singleton
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.writeText
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@ -43,39 +43,39 @@ class DayTest {
|
||||
}
|
||||
|
||||
@Day(1)
|
||||
class TextStringExample(@Text val input: Input<String>)
|
||||
class TextStringExample(@Text val input: String)
|
||||
|
||||
@Day(2)
|
||||
class CsvIntArrayExample(@Csv val input: Input<IntArray>)
|
||||
class CsvIntArrayExample(@Csv val input: IntArray)
|
||||
|
||||
@Day(3)
|
||||
class IntLinesExample(@Lines val input: Input<IntArray>)
|
||||
class IntLinesExample(@Lines val input: IntArray)
|
||||
|
||||
@Day(4)
|
||||
class StringLinesExample(@Lines val input: Input<List<String>>)
|
||||
class StringLinesExample(@Lines val input: List<String>)
|
||||
|
||||
@Test
|
||||
fun `check @Text String`() {
|
||||
val day = createDay<TextStringExample>()
|
||||
assertThat(day.input.value).isEqualTo("blablabla")
|
||||
assertThat(day.input).isEqualTo("blablabla")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `check @Csv IntArray`() {
|
||||
val day = createDay<CsvIntArrayExample>()
|
||||
assertThat(day.input.value).containsExactly(1, +2, 3, 4, -5)
|
||||
assertThat(day.input).containsExactly(1, +2, 3, 4, -5)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `check @Lines IntArray`() {
|
||||
val day = createDay<IntLinesExample>()
|
||||
assertThat(day.input.value).containsExactly(1779, 1737, 1537, 1167, 1804, 1873)
|
||||
assertThat(day.input).containsExactly(1779, 1737, 1537, 1167, 1804, 1873)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `check @Lines strings`() {
|
||||
val day = createDay<StringLinesExample>()
|
||||
assertThat(day.input.value).containsExactly("a", "bb", "ccc")
|
||||
assertThat(day.input).containsExactly("a", "bb", "ccc")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user