diff --git a/2019/build.gradle.kts b/2019/build.gradle.kts new file mode 100644 index 0000000..38f099e --- /dev/null +++ b/2019/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("java-convention") +} + +dependencies { + implementation(project(":utils")) + + annotationProcessor(Libs.Micronaut.processor) + + implementation(Libs.eclipseCollections) + + testImplementation(Libs.Jmh.core) + testAnnotationProcessor(Libs.Jmh.processor) +} diff --git a/2019/src/main/java/be/vandewalleh/aoc/Day01.java b/2019/src/main/java/be/vandewalleh/aoc/Day01.java new file mode 100644 index 0000000..9a2fd81 --- /dev/null +++ b/2019/src/main/java/be/vandewalleh/aoc/Day01.java @@ -0,0 +1,49 @@ +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) +public class Day01 { + + public static void main(String[] args) { + var day = Days.createDay(Day01.class); + System.out.println(day.part1()); + System.out.println(day.part2()); + } + + private final int[] input; + + public Day01(@Lines Input input) { + this.input = input.getValue(); + } + + private int fuel(int mass) { + return (mass / 3) - 2; + } + + public int part1() { + var total = 0; + for (var mass : input) { + total += fuel(mass); + } + return total; + } + + public int part2() { + var total = 0; + for (var mass : input) { + int fuel = fuel(mass); + int subTotal = fuel; + while (true) { + fuel = fuel(fuel); + if (fuel <= 0) break; + subTotal += fuel; + } + total += subTotal; + } + return total; + } +} diff --git a/2019/src/main/resources/day01.txt b/2019/src/main/resources/day01.txt new file mode 100644 index 0000000..7ba83e9 --- /dev/null +++ b/2019/src/main/resources/day01.txt @@ -0,0 +1,100 @@ +132791 +78272 +114679 +60602 +59038 +69747 +61672 +147972 +92618 +70186 +125826 +61803 +78112 +124864 +58441 +113062 +105389 +125983 +90716 +75544 +148451 +73739 +127762 +146660 +128747 +148129 +138635 +80095 +60241 +145455 +98730 +59139 +146828 +113550 +91682 +107415 +129207 +147635 +104583 +102245 +73446 +148657 +96364 +52033 +69964 +63609 +98207 +73401 +65511 +115034 +126179 +96664 +85394 +128472 +79017 +93222 +55267 +102446 +133150 +148985 +95325 +57713 +77370 +60879 +111977 +99362 +91581 +55201 +137670 +127159 +128324 +77217 +86378 +112847 +108265 +80355 +75650 +106222 +67793 +113891 +74508 +139463 +69972 +122753 +135854 +127770 +101085 +98304 +61451 +146719 +61225 +60468 +83613 +137436 +126303 +78759 +70081 +110671 +113234 +111563 diff --git a/2020/build.gradle.kts b/2020/build.gradle.kts new file mode 100644 index 0000000..efdff28 --- /dev/null +++ b/2020/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + id("kotlin-convention") + kotlin("kapt") +} + +dependencies { + implementation(project(":utils")) + + kapt(Libs.Micronaut.processor) + + implementation(Libs.Slf4J.api) + runtimeOnly(Libs.Slf4J.simple) + + implementation(Libs.eclipseCollections) + + testImplementation(Libs.Jmh.core) + kaptTest(Libs.Jmh.processor) +} diff --git a/days/src/main/kotlin/Day01.kt b/2020/src/main/kotlin/Day01.kt similarity index 84% rename from days/src/main/kotlin/Day01.kt rename to 2020/src/main/kotlin/Day01.kt index 24acd5f..7477f67 100644 --- a/days/src/main/kotlin/Day01.kt +++ b/2020/src/main/kotlin/Day01.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay @Day(1) class Day01(@Lines input: Input) { @@ -31,7 +30,3 @@ class Day01(@Lines input: Input) { } -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day02.kt b/2020/src/main/kotlin/Day02.kt similarity index 76% rename from days/src/main/kotlin/Day02.kt rename to 2020/src/main/kotlin/Day02.kt index 72d9020..0694478 100644 --- a/days/src/main/kotlin/Day02.kt +++ b/2020/src/main/kotlin/Day02.kt @@ -3,12 +3,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 be.vandewalleh.aoc.utils.input.createDay - -data class PasswordEntry(val range: IntRange, val letter: Char, val password: String) @Day(2) class Day02(@Lines input: Input>) { + 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 { @@ -22,8 +21,3 @@ class Day02(@Lines input: Input>) { (pwd[range.first - 1] == letter) xor (pwd[range.last - 1] == letter) } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day03.kt b/2020/src/main/kotlin/Day03.kt similarity index 74% rename from days/src/main/kotlin/Day03.kt rename to 2020/src/main/kotlin/Day03.kt index 4b7f327..7433494 100644 --- a/days/src/main/kotlin/Day03.kt +++ b/2020/src/main/kotlin/Day03.kt @@ -3,14 +3,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 -import be.vandewalleh.aoc.utils.input.createDay - -data class Slope(val x: Int, val y: Int) @Day(3) class Day03(@Lines val input: Input>) { + private data class Slope(val x: Int, val y: Int) - fun part1(slope: Slope = Slope(x = 3, y = 1)): Int { + private fun findSlope(slope: Slope): Int { val grid = input.value var trees = 0 var x = 0 @@ -28,6 +26,8 @@ class Day03(@Lines val input: Input>) { return trees } + fun part1() = findSlope(Slope(x = 3, y = 1)) + fun part2(): Long = listOf( Slope(x = 1, y = 1), Slope(x = 3, y = 1), @@ -35,11 +35,6 @@ class Day03(@Lines val input: Input>) { Slope(x = 7, y = 1), Slope(x = 1, y = 2), ) - .map { part1(it).toLong() } + .map { findSlope(it).toLong() } .reduce { acc, trees -> acc * trees } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day04.kt b/2020/src/main/kotlin/Day04.kt similarity index 86% rename from days/src/main/kotlin/Day04.kt rename to 2020/src/main/kotlin/Day04.kt index 630762b..7d5e517 100644 --- a/days/src/main/kotlin/Day04.kt +++ b/2020/src/main/kotlin/Day04.kt @@ -3,10 +3,9 @@ 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 be.vandewalleh.aoc.utils.input.createDay -typealias Entry = Pair -typealias Entries = List +private typealias Entry = Pair +private typealias Entries = List @Day(4) class Day04(@Text val input: Input) { @@ -42,8 +41,3 @@ class Day04(@Text val input: Input) { fun part2() = entries.count { it.hasRequiredKeys() && it.all { it.isValid() } } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day05.kt b/2020/src/main/kotlin/Day05.kt similarity index 81% rename from days/src/main/kotlin/Day05.kt rename to 2020/src/main/kotlin/Day05.kt index 8a1d794..86be687 100644 --- a/days/src/main/kotlin/Day05.kt +++ b/2020/src/main/kotlin/Day05.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay @Day(5) class Day05(@Lines val input: Input>) { @@ -22,8 +21,3 @@ class Day05(@Lines val input: Input>) { .find { (a, b) -> b - a > 1 }!! .first() + 1 } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day06.kt b/2020/src/main/kotlin/Day06.kt similarity index 83% rename from days/src/main/kotlin/Day06.kt rename to 2020/src/main/kotlin/Day06.kt index 7f06962..b70e0bb 100644 --- a/days/src/main/kotlin/Day06.kt +++ b/2020/src/main/kotlin/Day06.kt @@ -3,7 +3,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.Text -import be.vandewalleh.aoc.utils.input.createDay import org.eclipse.collections.impl.factory.primitive.CharBags @Day(6) @@ -23,8 +22,3 @@ class Day06(@Text val input: Input) { } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day07.kt b/2020/src/main/kotlin/Day07.kt similarity index 90% rename from days/src/main/kotlin/Day07.kt rename to 2020/src/main/kotlin/Day07.kt index f951814..da5c78d 100644 --- a/days/src/main/kotlin/Day07.kt +++ b/2020/src/main/kotlin/Day07.kt @@ -3,17 +3,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 be.vandewalleh.aoc.utils.input.createDay import org.eclipse.collections.api.factory.Stacks import org.eclipse.collections.api.multimap.list.ImmutableListMultimap import org.eclipse.collections.api.stack.MutableStack import org.eclipse.collections.impl.factory.Multimaps -data class Bag(val count: Int, val color: String) - @Day(7) class Day07(@Lines val input: Input>) { + private data class Bag(val count: Int, val color: String) + private val map: ImmutableListMultimap init { @@ -50,8 +49,3 @@ class Day07(@Lines val input: Input>) { fun part2() = bagSequence("shiny gold").sumBy { it.count } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day08.kt b/2020/src/main/kotlin/Day08.kt similarity index 82% rename from days/src/main/kotlin/Day08.kt rename to 2020/src/main/kotlin/Day08.kt index 8bebd1f..fbc15a2 100644 --- a/days/src/main/kotlin/Day08.kt +++ b/2020/src/main/kotlin/Day08.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay import org.eclipse.collections.impl.factory.primitive.IntLists import org.eclipse.collections.impl.factory.primitive.IntSets @@ -15,7 +14,12 @@ class Day08(@Lines val input: Input>) { Instruction(Operation.valueOf(words[0].capitalize()), words[1].toInt()) }.toTypedArray() - fun part1() = run(instructions) + fun part1() = run(instructions).let { + when (it) { + is VmResult.Looped -> it.acc + is VmResult.Terminated -> it.acc + } + } private fun run(instructions: Array): VmResult { var acc = 0 @@ -41,7 +45,7 @@ class Day08(@Lines val input: Input>) { return VmResult.Looped(acc) } - fun part2(): VmResult { + fun part2(): Int { val possibleMutations = IntLists.mutable.empty() instructions.forEachIndexed { i, e -> if (e.operation == Operation.Jmp || e.operation == Operation.Nop) possibleMutations.add(i) @@ -54,7 +58,7 @@ class Day08(@Lines val input: Input>) { } val res = run(copy) - if (res is VmResult.Terminated) return res + if (res is VmResult.Terminated) return res.acc } error("No result found") @@ -62,17 +66,11 @@ class Day08(@Lines val input: Input>) { } -enum class Operation { Acc, Jmp, Nop } +private enum class Operation { Acc, Jmp, Nop } -data class Instruction(val operation: Operation, val argument: Int) +private data class Instruction(val operation: Operation, val argument: Int) -sealed class VmResult { +private sealed class VmResult { data class Looped(val acc: Int) : VmResult() data class Terminated(val acc: Int) : VmResult() } - -fun main() { - val day = createDay() - println(day.part1()) - println(day.part2()) -} diff --git a/days/src/main/kotlin/Day09.kt b/2020/src/main/kotlin/Day09.kt similarity index 91% rename from days/src/main/kotlin/Day09.kt rename to 2020/src/main/kotlin/Day09.kt index ab3b5db..0c8e95c 100644 --- a/days/src/main/kotlin/Day09.kt +++ b/2020/src/main/kotlin/Day09.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay @Day(9) class Day09(@Lines val input: Input) { @@ -49,8 +48,3 @@ class Day09(@Lines val input: Input) { } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day10.kt b/2020/src/main/kotlin/Day10.kt similarity index 89% rename from days/src/main/kotlin/Day10.kt rename to 2020/src/main/kotlin/Day10.kt index 0208091..d14dfff 100644 --- a/days/src/main/kotlin/Day10.kt +++ b/2020/src/main/kotlin/Day10.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay import org.eclipse.collections.api.list.primitive.MutableIntList import org.eclipse.collections.impl.factory.primitive.IntLists import org.eclipse.collections.impl.factory.primitive.IntLongMaps @@ -43,8 +42,3 @@ class Day10(@Lines val input: Input) { } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day11.kt b/2020/src/main/kotlin/Day11.kt similarity index 83% rename from days/src/main/kotlin/Day11.kt rename to 2020/src/main/kotlin/Day11.kt index 95f5b17..667dac8 100644 --- a/days/src/main/kotlin/Day11.kt +++ b/2020/src/main/kotlin/Day11.kt @@ -3,27 +3,26 @@ 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 be.vandewalleh.aoc.utils.input.createDay -typealias Seats = Array +private typealias Seats = Array -fun Seats.deepClone(): Seats = map { it.clone() }.toTypedArray() +private fun Seats.deepClone(): Seats = map { it.clone() }.toTypedArray() -operator fun Seats.get(x: Int, y: Int): Char = this[y][x] -operator fun Seats.set(x: Int, y: Int, value: Char) { +private operator fun Seats.get(x: Int, y: Int): Char = this[y][x] +private operator fun Seats.set(x: Int, y: Int, value: Char) { this[y][x] = value } -operator fun Seats.contains(xy: Pair): Boolean { +private operator fun Seats.contains(xy: Pair): Boolean { val (x, y) = xy return x in 0 until width && y in 0 until height } -val Seats.width get() = first().size -val Seats.height get() = size +private val Seats.width get() = first().size +private val Seats.height get() = size -fun Seats.asGridString() = joinToString("\n") { it.joinToString("") } -fun Seats.countOccupied() = sumBy { it.count { it == '#' } } +private fun Seats.asGridString() = joinToString("\n") { it.joinToString("") } +private fun Seats.countOccupied() = sumBy { it.count { it == '#' } } @Day(11) class Day11(@Lines val input: Input>) { @@ -116,8 +115,3 @@ class Day11(@Lines val input: Input>) { fun part2() = findLastRepeating(seats, ::progress2).countOccupied() } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day12.kt b/2020/src/main/kotlin/Day12.kt similarity index 93% rename from days/src/main/kotlin/Day12.kt rename to 2020/src/main/kotlin/Day12.kt index ec51f94..b6b3fec 100644 --- a/days/src/main/kotlin/Day12.kt +++ b/2020/src/main/kotlin/Day12.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay import kotlin.math.abs @Day(12) @@ -79,8 +78,3 @@ class Day12(@Lines val input: Input>) { return abs(x) + abs(y) } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day13.kt b/2020/src/main/kotlin/Day13.kt similarity index 87% rename from days/src/main/kotlin/Day13.kt rename to 2020/src/main/kotlin/Day13.kt index 87a7a48..0c149d2 100644 --- a/days/src/main/kotlin/Day13.kt +++ b/2020/src/main/kotlin/Day13.kt @@ -3,10 +3,9 @@ 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 be.vandewalleh.aoc.utils.input.createDay import kotlin.math.abs -data class Bus(val index: Int, val id: Long) +private data class Bus(val index: Int, val id: Long) @Day(13) class Day13(@Lines val input: Input>) { @@ -48,8 +47,3 @@ class Day13(@Lines val input: Input>) { return t } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day14.kt b/2020/src/main/kotlin/Day14.kt similarity index 95% rename from days/src/main/kotlin/Day14.kt rename to 2020/src/main/kotlin/Day14.kt index 104cbb2..46158ca 100644 --- a/days/src/main/kotlin/Day14.kt +++ b/2020/src/main/kotlin/Day14.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay import kotlin.math.pow import org.eclipse.collections.impl.factory.primitive.IntObjectMaps import org.eclipse.collections.impl.factory.primitive.LongIntMaps @@ -93,8 +92,3 @@ class Day14(@Lines val input: Input>) { } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day15.kt b/2020/src/main/kotlin/Day15.kt similarity index 85% rename from days/src/main/kotlin/Day15.kt rename to 2020/src/main/kotlin/Day15.kt index fd231b7..71312d3 100644 --- a/days/src/main/kotlin/Day15.kt +++ b/2020/src/main/kotlin/Day15.kt @@ -3,7 +3,6 @@ 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 be.vandewalleh.aoc.utils.input.createDay import kotlin.math.abs import org.eclipse.collections.impl.factory.primitive.IntObjectMaps @@ -43,11 +42,3 @@ class Day15(@Csv val input: Input) { fun part2() = run(until = 30000000) } - -fun main() { - // val input = Input(intArrayOf(3, 1, 2)) - with(createDay()) { - println(part1()) - println(part2()) - } -} diff --git a/days/src/main/kotlin/Day16.kt b/2020/src/main/kotlin/Day16.kt similarity index 97% rename from days/src/main/kotlin/Day16.kt rename to 2020/src/main/kotlin/Day16.kt index 268cede..afafd32 100644 --- a/days/src/main/kotlin/Day16.kt +++ b/2020/src/main/kotlin/Day16.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay import org.eclipse.collections.api.multimap.list.ListMultimap import org.eclipse.collections.api.multimap.list.MutableListMultimap import org.eclipse.collections.api.multimap.set.MutableSetMultimap @@ -148,8 +147,3 @@ class Day16(@Groups val input: Input>>) { return rangesByName } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day17.kt b/2020/src/main/kotlin/Day17.kt similarity index 91% rename from days/src/main/kotlin/Day17.kt rename to 2020/src/main/kotlin/Day17.kt index 62c83de..1938751 100644 --- a/days/src/main/kotlin/Day17.kt +++ b/2020/src/main/kotlin/Day17.kt @@ -3,12 +3,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 be.vandewalleh.aoc.utils.input.createDay -data class Point(val x: Int, val y: Int, val z: Int) -data class Point4(val x: Int, val y: Int, val z: Int, val blah: Int) +private data class Point(val x: Int, val y: Int, val z: Int) +private data class Point4(val x: Int, val y: Int, val z: Int, val blah: Int) -enum class State { Active, Inactive } +private enum class State { Active, Inactive } @Day(17) class Day17(@Lines val input: Input>) { @@ -87,8 +86,3 @@ class Day17(@Lines val input: Input>) { } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day18.kt b/2020/src/main/kotlin/Day18.kt similarity index 95% rename from days/src/main/kotlin/Day18.kt rename to 2020/src/main/kotlin/Day18.kt index db10b0b..cf7ed71 100644 --- a/days/src/main/kotlin/Day18.kt +++ b/2020/src/main/kotlin/Day18.kt @@ -3,14 +3,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 be.vandewalleh.aoc.utils.input.createDay import java.util.* import org.slf4j.Logger import org.slf4j.LoggerFactory -enum class Operator { Add, Multiply } +private enum class Operator { Add, Multiply } -operator fun Operator.invoke(a: Long, b: Long) = when (this) { +private operator fun Operator.invoke(a: Long, b: Long) = when (this) { Operator.Add -> a + b Operator.Multiply -> a * b } @@ -170,8 +169,3 @@ class Day18(@Lines val input: Input>) { .reduce { t, u -> t + u } .get() } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day19.kt b/2020/src/main/kotlin/Day19.kt similarity index 94% rename from days/src/main/kotlin/Day19.kt rename to 2020/src/main/kotlin/Day19.kt index 31a104c..457392f 100644 --- a/days/src/main/kotlin/Day19.kt +++ b/2020/src/main/kotlin/Day19.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay import java.util.* import kotlin.collections.ArrayList @@ -56,8 +55,3 @@ class Day19(@Groups val input: Input>>) { } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day20.kt b/2020/src/main/kotlin/Day20.kt similarity index 98% rename from days/src/main/kotlin/Day20.kt rename to 2020/src/main/kotlin/Day20.kt index 5421d0f..ad7d725 100644 --- a/days/src/main/kotlin/Day20.kt +++ b/2020/src/main/kotlin/Day20.kt @@ -6,7 +6,6 @@ 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 be.vandewalleh.aoc.utils.input.createDay import java.util.* import kotlin.collections.ArrayList import kotlin.math.sqrt @@ -204,8 +203,3 @@ class Day20(@Groups val input: Input>>) { } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day21.kt b/2020/src/main/kotlin/Day21.kt similarity index 94% rename from days/src/main/kotlin/Day21.kt rename to 2020/src/main/kotlin/Day21.kt index 07aad7e..529936a 100644 --- a/days/src/main/kotlin/Day21.kt +++ b/2020/src/main/kotlin/Day21.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay import org.eclipse.collections.api.factory.Bags import org.eclipse.collections.api.multimap.set.MutableSetMultimap import org.eclipse.collections.impl.factory.Multimaps @@ -57,8 +56,3 @@ class Day21(@Lines val input: Input>) { return map } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day22.kt b/2020/src/main/kotlin/Day22.kt similarity index 91% rename from days/src/main/kotlin/Day22.kt rename to 2020/src/main/kotlin/Day22.kt index 61d893f..de50f4d 100644 --- a/days/src/main/kotlin/Day22.kt +++ b/2020/src/main/kotlin/Day22.kt @@ -3,9 +3,8 @@ 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 be.vandewalleh.aoc.utils.input.createDay -data class PlayedGame(val a: List, val b: List) +private data class PlayedGame(val a: List, val b: List) @Day(22) class Day22(@Groups val input: Input>>) { @@ -76,9 +75,3 @@ class Day22(@Groups val input: Input>>) { return if (one.isEmpty()) 2 else 1 } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} - diff --git a/days/src/main/kotlin/Day23.kt b/2020/src/main/kotlin/Day23.kt similarity index 96% rename from days/src/main/kotlin/Day23.kt rename to 2020/src/main/kotlin/Day23.kt index 4f0ab9f..5d56fab 100644 --- a/days/src/main/kotlin/Day23.kt +++ b/2020/src/main/kotlin/Day23.kt @@ -3,7 +3,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.Text -import be.vandewalleh.aoc.utils.input.createDay @Day(23) class Day23(@Text val input: Input) { @@ -111,8 +110,3 @@ class Day23(@Text val input: Input) { return current.next } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day24.kt b/2020/src/main/kotlin/Day24.kt similarity index 94% rename from days/src/main/kotlin/Day24.kt rename to 2020/src/main/kotlin/Day24.kt index fa3d294..0c417ec 100644 --- a/days/src/main/kotlin/Day24.kt +++ b/2020/src/main/kotlin/Day24.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay import org.eclipse.collections.api.bag.Bag import org.eclipse.collections.api.bag.MutableBag import org.eclipse.collections.api.factory.Bags @@ -65,8 +64,3 @@ class Day24(@Lines val input: Input>) { return bag.selectBlacks().size() } } - -fun main() = with(createDay()) { - println(part1()) - println(part2()) -} diff --git a/days/src/main/kotlin/Day25.kt b/2020/src/main/kotlin/Day25.kt similarity index 92% rename from days/src/main/kotlin/Day25.kt rename to 2020/src/main/kotlin/Day25.kt index 854276f..37b7a53 100644 --- a/days/src/main/kotlin/Day25.kt +++ b/2020/src/main/kotlin/Day25.kt @@ -3,7 +3,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 be.vandewalleh.aoc.utils.input.createDay @Day(25) class Day25(@Lines val input: Input) { @@ -44,7 +43,3 @@ class Day25(@Lines val input: Input) { } } - -fun main() = with(createDay()) { - println(part1()) -} diff --git a/2020/src/main/kotlin/Main.kt b/2020/src/main/kotlin/Main.kt new file mode 100644 index 0000000..66f7661 --- /dev/null +++ b/2020/src/main/kotlin/Main.kt @@ -0,0 +1,7 @@ +package be.vandewalleh.aoc.days + +import be.vandewalleh.aoc.utils.factory.createDay + +fun main() = with(createDay()) { + println(part1()) +} diff --git a/days/src/main/kotlin/geometry/Grid.kt b/2020/src/main/kotlin/geometry/Grid.kt similarity index 100% rename from days/src/main/kotlin/geometry/Grid.kt rename to 2020/src/main/kotlin/geometry/Grid.kt diff --git a/days/src/main/kotlin/geometry/GridFactory.kt b/2020/src/main/kotlin/geometry/GridFactory.kt similarity index 100% rename from days/src/main/kotlin/geometry/GridFactory.kt rename to 2020/src/main/kotlin/geometry/GridFactory.kt diff --git a/days/src/main/kotlin/geometry/GridTranformations.kt b/2020/src/main/kotlin/geometry/GridTranformations.kt similarity index 100% rename from days/src/main/kotlin/geometry/GridTranformations.kt rename to 2020/src/main/kotlin/geometry/GridTranformations.kt diff --git a/days/src/main/resources/day01.txt b/2020/src/main/resources/day01.txt similarity index 100% rename from days/src/main/resources/day01.txt rename to 2020/src/main/resources/day01.txt diff --git a/days/src/main/resources/day02.txt b/2020/src/main/resources/day02.txt similarity index 100% rename from days/src/main/resources/day02.txt rename to 2020/src/main/resources/day02.txt diff --git a/days/src/main/resources/day03.txt b/2020/src/main/resources/day03.txt similarity index 100% rename from days/src/main/resources/day03.txt rename to 2020/src/main/resources/day03.txt diff --git a/days/src/main/resources/day04.txt b/2020/src/main/resources/day04.txt similarity index 100% rename from days/src/main/resources/day04.txt rename to 2020/src/main/resources/day04.txt diff --git a/days/src/main/resources/day05.txt b/2020/src/main/resources/day05.txt similarity index 100% rename from days/src/main/resources/day05.txt rename to 2020/src/main/resources/day05.txt diff --git a/days/src/main/resources/day06.txt b/2020/src/main/resources/day06.txt similarity index 100% rename from days/src/main/resources/day06.txt rename to 2020/src/main/resources/day06.txt diff --git a/days/src/main/resources/day07.txt b/2020/src/main/resources/day07.txt similarity index 100% rename from days/src/main/resources/day07.txt rename to 2020/src/main/resources/day07.txt diff --git a/days/src/main/resources/day08.txt b/2020/src/main/resources/day08.txt similarity index 100% rename from days/src/main/resources/day08.txt rename to 2020/src/main/resources/day08.txt diff --git a/days/src/main/resources/day09.txt b/2020/src/main/resources/day09.txt similarity index 100% rename from days/src/main/resources/day09.txt rename to 2020/src/main/resources/day09.txt diff --git a/days/src/main/resources/day10.txt b/2020/src/main/resources/day10.txt similarity index 100% rename from days/src/main/resources/day10.txt rename to 2020/src/main/resources/day10.txt diff --git a/days/src/main/resources/day11.txt b/2020/src/main/resources/day11.txt similarity index 100% rename from days/src/main/resources/day11.txt rename to 2020/src/main/resources/day11.txt diff --git a/days/src/main/resources/day12.txt b/2020/src/main/resources/day12.txt similarity index 100% rename from days/src/main/resources/day12.txt rename to 2020/src/main/resources/day12.txt diff --git a/days/src/main/resources/day13.txt b/2020/src/main/resources/day13.txt similarity index 100% rename from days/src/main/resources/day13.txt rename to 2020/src/main/resources/day13.txt diff --git a/days/src/main/resources/day14.txt b/2020/src/main/resources/day14.txt similarity index 100% rename from days/src/main/resources/day14.txt rename to 2020/src/main/resources/day14.txt diff --git a/days/src/main/resources/day15.txt b/2020/src/main/resources/day15.txt similarity index 100% rename from days/src/main/resources/day15.txt rename to 2020/src/main/resources/day15.txt diff --git a/days/src/main/resources/day16.txt b/2020/src/main/resources/day16.txt similarity index 100% rename from days/src/main/resources/day16.txt rename to 2020/src/main/resources/day16.txt diff --git a/days/src/main/resources/day17.txt b/2020/src/main/resources/day17.txt similarity index 100% rename from days/src/main/resources/day17.txt rename to 2020/src/main/resources/day17.txt diff --git a/days/src/main/resources/day18.txt b/2020/src/main/resources/day18.txt similarity index 100% rename from days/src/main/resources/day18.txt rename to 2020/src/main/resources/day18.txt diff --git a/days/src/main/resources/day19.txt b/2020/src/main/resources/day19.txt similarity index 100% rename from days/src/main/resources/day19.txt rename to 2020/src/main/resources/day19.txt diff --git a/days/src/main/resources/day20.txt b/2020/src/main/resources/day20.txt similarity index 100% rename from days/src/main/resources/day20.txt rename to 2020/src/main/resources/day20.txt diff --git a/days/src/main/resources/day21.txt b/2020/src/main/resources/day21.txt similarity index 100% rename from days/src/main/resources/day21.txt rename to 2020/src/main/resources/day21.txt diff --git a/days/src/main/resources/day22.txt b/2020/src/main/resources/day22.txt similarity index 100% rename from days/src/main/resources/day22.txt rename to 2020/src/main/resources/day22.txt diff --git a/days/src/main/resources/day23.txt b/2020/src/main/resources/day23.txt similarity index 100% rename from days/src/main/resources/day23.txt rename to 2020/src/main/resources/day23.txt diff --git a/days/src/main/resources/day24.txt b/2020/src/main/resources/day24.txt similarity index 100% rename from days/src/main/resources/day24.txt rename to 2020/src/main/resources/day24.txt diff --git a/days/src/main/resources/day25.txt b/2020/src/main/resources/day25.txt similarity index 100% rename from days/src/main/resources/day25.txt rename to 2020/src/main/resources/day25.txt diff --git a/2020/src/main/resources/simplelogger.properties b/2020/src/main/resources/simplelogger.properties new file mode 100644 index 0000000..b4dd2ef --- /dev/null +++ b/2020/src/main/resources/simplelogger.properties @@ -0,0 +1,6 @@ +org.slf4j.simpleLogger.logFile=System.out +org.slf4j.simpleLogger.showDateTime=true +org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z +org.slf4j.simpleLogger.defaultLogLevel=info +org.slf4j.simpleLogger.log.io.micronaut=info +org.slf4j.simpleLogger.log.io.micronaut.context.lifecycle=info diff --git a/days/src/test/kotlin/Day01Test.kt b/2020/src/test/kotlin/Day01Test.kt similarity index 100% rename from days/src/test/kotlin/Day01Test.kt rename to 2020/src/test/kotlin/Day01Test.kt diff --git a/days/src/test/kotlin/Day03Test.kt b/2020/src/test/kotlin/Day03Test.kt similarity index 100% rename from days/src/test/kotlin/Day03Test.kt rename to 2020/src/test/kotlin/Day03Test.kt diff --git a/days/src/test/kotlin/Day04Test.kt b/2020/src/test/kotlin/Day04Test.kt similarity index 98% rename from days/src/test/kotlin/Day04Test.kt rename to 2020/src/test/kotlin/Day04Test.kt index ac228f6..8d59f07 100644 --- a/days/src/test/kotlin/Day04Test.kt +++ b/2020/src/test/kotlin/Day04Test.kt @@ -1,7 +1,7 @@ package be.vandewalleh.aoc.days +import be.vandewalleh.aoc.utils.factory.createDay import be.vandewalleh.aoc.utils.input.Input -import be.vandewalleh.aoc.utils.input.createDay import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Nested diff --git a/days/src/test/kotlin/Day05Test.kt b/2020/src/test/kotlin/Day05Test.kt similarity index 87% rename from days/src/test/kotlin/Day05Test.kt rename to 2020/src/test/kotlin/Day05Test.kt index 299bf02..4d0431b 100644 --- a/days/src/test/kotlin/Day05Test.kt +++ b/2020/src/test/kotlin/Day05Test.kt @@ -1,6 +1,6 @@ package be.vandewalleh.aoc.days -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.Test diff --git a/days/src/test/kotlin/Day13Test.kt b/2020/src/test/kotlin/Day13Test.kt similarity index 100% rename from days/src/test/kotlin/Day13Test.kt rename to 2020/src/test/kotlin/Day13Test.kt diff --git a/days/src/test/kotlin/Day14Benchmark.kt b/2020/src/test/kotlin/Day14Benchmark.kt similarity index 100% rename from days/src/test/kotlin/Day14Benchmark.kt rename to 2020/src/test/kotlin/Day14Benchmark.kt diff --git a/days/src/test/kotlin/Day16Benchmark.kt b/2020/src/test/kotlin/Day16Benchmark.kt similarity index 94% rename from days/src/test/kotlin/Day16Benchmark.kt rename to 2020/src/test/kotlin/Day16Benchmark.kt index 41288d8..73ad023 100644 --- a/days/src/test/kotlin/Day16Benchmark.kt +++ b/2020/src/test/kotlin/Day16Benchmark.kt @@ -1,6 +1,6 @@ package be.vandewalleh.aoc.days -import be.vandewalleh.aoc.utils.input.createDay +import be.vandewalleh.aoc.utils.factory.createDay import java.util.concurrent.TimeUnit import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole diff --git a/days/src/test/kotlin/Day18Benchmark.kt b/2020/src/test/kotlin/Day18Benchmark.kt similarity index 95% rename from days/src/test/kotlin/Day18Benchmark.kt rename to 2020/src/test/kotlin/Day18Benchmark.kt index 8e75528..f819ba5 100644 --- a/days/src/test/kotlin/Day18Benchmark.kt +++ b/2020/src/test/kotlin/Day18Benchmark.kt @@ -1,6 +1,6 @@ package be.vandewalleh.aoc.days -import be.vandewalleh.aoc.utils.input.createDay +import be.vandewalleh.aoc.utils.factory.createDay import java.util.concurrent.TimeUnit import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole diff --git a/days/src/test/kotlin/Day18Test.kt b/2020/src/test/kotlin/Day18Test.kt similarity index 100% rename from days/src/test/kotlin/Day18Test.kt rename to 2020/src/test/kotlin/Day18Test.kt diff --git a/days/src/test/resources/junit-platform.properties b/2020/src/test/resources/junit-platform.properties similarity index 100% rename from days/src/test/resources/junit-platform.properties rename to 2020/src/test/resources/junit-platform.properties diff --git a/build.gradle.kts b/build.gradle.kts index 314388d..869560a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("advent-of-code") + id("advent-of-code-downloader") } adventOfCode { diff --git a/buildSrc/src/main/kotlin/AdventOfCodePlugin.kt b/buildSrc/src/main/kotlin/AdventOfCodeDownloaderPlugin.kt similarity index 97% rename from buildSrc/src/main/kotlin/AdventOfCodePlugin.kt rename to buildSrc/src/main/kotlin/AdventOfCodeDownloaderPlugin.kt index f1b1816..46c6065 100644 --- a/buildSrc/src/main/kotlin/AdventOfCodePlugin.kt +++ b/buildSrc/src/main/kotlin/AdventOfCodeDownloaderPlugin.kt @@ -1,3 +1,5 @@ +import java.io.File +import java.time.LocalDateTime import kong.unirest.Unirest import org.gradle.api.GradleException import org.gradle.api.Plugin @@ -5,15 +7,13 @@ import org.gradle.api.Project import org.gradle.api.tasks.SourceSetContainer import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType -import java.io.File -import java.time.LocalDateTime open class AdventOfCodeExtension { var session: String? = null var year: Int = 2020 } -class AdventOfCodePlugin : Plugin { +class AdventOfCodeDownloaderPlugin : Plugin { override fun apply(project: Project) { project.tasks.create("aoc") { group = "Advent of Code" diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/advent-of-code-downloader.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/advent-of-code-downloader.properties new file mode 100644 index 0000000..2b1aadc --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/advent-of-code-downloader.properties @@ -0,0 +1 @@ +implementation-class=AdventOfCodeDownloaderPlugin diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/advent-of-code.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/advent-of-code.properties deleted file mode 100644 index 17f9ebf..0000000 --- a/buildSrc/src/main/resources/META-INF/gradle-plugins/advent-of-code.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=AdventOfCodePlugin diff --git a/days/build.gradle.kts b/days/build.gradle.kts deleted file mode 100644 index 9ed4323..0000000 --- a/days/build.gradle.kts +++ /dev/null @@ -1,27 +0,0 @@ -plugins { - id("kotlin-convention") - kotlin("kapt") -} - -dependencies { - implementation(project(":utils")) - - implementation(Libs.Micronaut.core) - implementation(Libs.Micronaut.inject) - implementation(Libs.Micronaut.kotlin) - kapt(Libs.Micronaut.processor) - - implementation(Libs.Slf4J.api) - runtimeOnly(Libs.Slf4J.simple) - - implementation(Libs.eclipseCollections) { - because("Primitive collections mostly") - } - - implementation(Libs.Arrow.core) { - because("Just in case") - } - - testImplementation(Libs.Jmh.core) - kaptTest(Libs.Jmh.processor) -} diff --git a/settings.gradle.kts b/settings.gradle.kts index b025579..d09c437 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,4 @@ -rootProject.name = "aoc-2020" +rootProject.name = "Advent of Code" include("utils") -include("days") +include("2020") +include("2019") diff --git a/utils/build.gradle.kts b/utils/build.gradle.kts index 4144864..6661667 100644 --- a/utils/build.gradle.kts +++ b/utils/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { implementation(Libs.Micronaut.core) - implementation(Libs.Micronaut.inject) + api(Libs.Micronaut.inject) implementation(Libs.Micronaut.kotlin) kapt(Libs.Micronaut.processor) diff --git a/utils/src/main/kotlin/be/vandewalleh/aoc/utils/factory/DayFactory.kt b/utils/src/main/kotlin/be/vandewalleh/aoc/utils/factory/DayFactory.kt new file mode 100644 index 0000000..c24f677 --- /dev/null +++ b/utils/src/main/kotlin/be/vandewalleh/aoc/utils/factory/DayFactory.kt @@ -0,0 +1,27 @@ +@file:JvmName("Days") + +package be.vandewalleh.aoc.utils.factory + +import be.vandewalleh.aoc.utils.input.TempFileResourceLoader +import io.micronaut.context.BeanContext +import java.io.File + +fun createDay(beanType: Class): T = BeanContext.run().getBean(beanType) + +inline fun createDay() = createDay(T::class.java) + +// A custom resourceLoader that returns a string should be more appropriate but ¯\_(ツ)_/¯ +private fun BeanContext.registerExampleLoader(example: String) { + registerSingleton(TempFileResourceLoader(File.createTempFile("aoc-example", ".txt").apply { + writeText(example) + })) +} + +fun createDay(beanType: Class, example: String): T { + return BeanContext.build() + .apply { registerExampleLoader(example) } + .start() + .getBean(beanType) +} + +inline fun createDay(example: String): T = createDay(T::class.java, example) diff --git a/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/Annotations.kt b/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/Annotations.kt index 7d85617..4148d10 100644 --- a/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/Annotations.kt +++ b/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/Annotations.kt @@ -10,7 +10,7 @@ import javax.inject.Qualifier @Qualifier @Introspected @Target(AnnotationTarget.CLASS) -annotation class Day(val day: Int) +annotation class Day(val value: Int) @Qualifier @Prototype diff --git a/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/InputFactory.kt b/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/InputFactory.kt index 45cb616..d686d36 100644 --- a/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/InputFactory.kt +++ b/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/InputFactory.kt @@ -90,7 +90,7 @@ class InputFactory(private val resourceLoader: ResourceLoader) { if (dayAnnotation.isEmpty) error("@DayInput cannot only be used on classes annotated with ${Day::class.qualifiedName}") - return dayAnnotation.get().intValue("day").asInt + return dayAnnotation.get().intValue("value").asInt } companion object { diff --git a/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/MicronautExtensions.kt b/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/MicronautExtensions.kt index 2bbdaee..fb73e8d 100644 --- a/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/MicronautExtensions.kt +++ b/utils/src/main/kotlin/be/vandewalleh/aoc/utils/input/MicronautExtensions.kt @@ -1,36 +1,11 @@ package be.vandewalleh.aoc.utils.input -import io.micronaut.context.BeanContext -import io.micronaut.context.getBean -import io.micronaut.core.annotation.AnnotationMetadataDelegate import io.micronaut.core.annotation.AnnotationMetadataProvider import io.micronaut.core.annotation.AnnotationValue -import io.micronaut.core.beans.BeanIntrospection -import java.io.File import java.util.* -internal inline fun getIntrospection(): BeanIntrospection = - BeanIntrospection.getIntrospection(T::class.java) - -internal inline fun AnnotationMetadataDelegate.getAnnotation(): AnnotationValue? = - getAnnotation(T::class.java) - internal inline fun AnnotationMetadataProvider.findAnnotation(): Optional> = findAnnotation(T::class.java) internal inline fun AnnotationMetadataProvider.hasAnnotation(): Boolean = findAnnotation(T::class.java).isPresent - -inline fun createDay() = BeanContext.run().getBean() - -// A custom resourceLoader that returns a string should be more appropriate but ¯\_(ツ)_/¯ -fun BeanContext.registerExampleLoader(example: String) { - registerSingleton(TempFileResourceLoader(File.createTempFile("aoc-example", ".txt").apply { - writeText(example) - })) -} - -inline fun createDay(example: String): T = BeanContext.build() - .apply { registerExampleLoader(example) } - .start() - .getBean() diff --git a/utils/src/test/kotlin/input/DayTest.kt b/utils/src/test/kotlin/input/DayTest.kt index 19cff5a..64a36e3 100644 --- a/utils/src/test/kotlin/input/DayTest.kt +++ b/utils/src/test/kotlin/input/DayTest.kt @@ -1,12 +1,13 @@ 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 org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test import javax.inject.Singleton import kotlin.io.path.ExperimentalPathApi import kotlin.io.path.writeText +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test class DayTest {