Prepare for other years
This commit is contained in:
parent
522618d106
commit
4a90257257
14
2019/build.gradle.kts
Normal file
14
2019/build.gradle.kts
Normal file
@ -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)
|
||||||
|
}
|
||||||
49
2019/src/main/java/be/vandewalleh/aoc/Day01.java
Normal file
49
2019/src/main/java/be/vandewalleh/aoc/Day01.java
Normal file
@ -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<int[]> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
100
2019/src/main/resources/day01.txt
Normal file
100
2019/src/main/resources/day01.txt
Normal file
@ -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
|
||||||
18
2020/build.gradle.kts
Normal file
18
2020/build.gradle.kts
Normal file
@ -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)
|
||||||
|
}
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
|
|
||||||
@Day(1)
|
@Day(1)
|
||||||
class Day01(@Lines input: Input<IntArray>) {
|
class Day01(@Lines input: Input<IntArray>) {
|
||||||
@ -31,7 +30,3 @@ class Day01(@Lines input: Input<IntArray>) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day01>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,12 +3,11 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
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)
|
@Day(2)
|
||||||
class Day02(@Lines input: Input<List<String>>) {
|
class Day02(@Lines input: 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 regex = "^(\\d+)-(\\d+) ([a-z]): (.*)$".toRegex()
|
||||||
|
|
||||||
private val passwords = input.value.map {
|
private val passwords = input.value.map {
|
||||||
@ -22,8 +21,3 @@ class Day02(@Lines input: Input<List<String>>) {
|
|||||||
(pwd[range.first - 1] == letter) xor (pwd[range.last - 1] == letter)
|
(pwd[range.first - 1] == letter) xor (pwd[range.last - 1] == letter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day02>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,14 +3,12 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
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)
|
@Day(3)
|
||||||
class Day03(@Lines val input: Input<List<String>>) {
|
class Day03(@Lines val input: Input<List<String>>) {
|
||||||
|
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
|
val grid = input.value
|
||||||
var trees = 0
|
var trees = 0
|
||||||
var x = 0
|
var x = 0
|
||||||
@ -28,6 +26,8 @@ class Day03(@Lines val input: Input<List<String>>) {
|
|||||||
return trees
|
return trees
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun part1() = findSlope(Slope(x = 3, y = 1))
|
||||||
|
|
||||||
fun part2(): Long = listOf(
|
fun part2(): Long = listOf(
|
||||||
Slope(x = 1, y = 1),
|
Slope(x = 1, y = 1),
|
||||||
Slope(x = 3, y = 1),
|
Slope(x = 3, y = 1),
|
||||||
@ -35,11 +35,6 @@ class Day03(@Lines val input: Input<List<String>>) {
|
|||||||
Slope(x = 7, y = 1),
|
Slope(x = 7, y = 1),
|
||||||
Slope(x = 1, y = 2),
|
Slope(x = 1, y = 2),
|
||||||
)
|
)
|
||||||
.map { part1(it).toLong() }
|
.map { findSlope(it).toLong() }
|
||||||
.reduce { acc, trees -> acc * trees }
|
.reduce { acc, trees -> acc * trees }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day03>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,10 +3,9 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Text
|
import be.vandewalleh.aoc.utils.input.Text
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
|
|
||||||
typealias Entry = Pair<String, String>
|
private typealias Entry = Pair<String, String>
|
||||||
typealias Entries = List<Entry>
|
private typealias Entries = List<Entry>
|
||||||
|
|
||||||
@Day(4)
|
@Day(4)
|
||||||
class Day04(@Text val input: Input<String>) {
|
class Day04(@Text val input: Input<String>) {
|
||||||
@ -42,8 +41,3 @@ class Day04(@Text val input: Input<String>) {
|
|||||||
|
|
||||||
fun part2() = entries.count { it.hasRequiredKeys() && it.all { it.isValid() } }
|
fun part2() = entries.count { it.hasRequiredKeys() && it.all { it.isValid() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day04>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
|
|
||||||
@Day(5)
|
@Day(5)
|
||||||
class Day05(@Lines val input: Input<List<String>>) {
|
class Day05(@Lines val input: Input<List<String>>) {
|
||||||
@ -22,8 +21,3 @@ class Day05(@Lines val input: Input<List<String>>) {
|
|||||||
.find { (a, b) -> b - a > 1 }!!
|
.find { (a, b) -> b - a > 1 }!!
|
||||||
.first() + 1
|
.first() + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day05>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Text
|
import be.vandewalleh.aoc.utils.input.Text
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import org.eclipse.collections.impl.factory.primitive.CharBags
|
import org.eclipse.collections.impl.factory.primitive.CharBags
|
||||||
|
|
||||||
@Day(6)
|
@Day(6)
|
||||||
@ -23,8 +22,3 @@ class Day06(@Text val input: Input<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day06>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,17 +3,16 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
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.factory.Stacks
|
||||||
import org.eclipse.collections.api.multimap.list.ImmutableListMultimap
|
import org.eclipse.collections.api.multimap.list.ImmutableListMultimap
|
||||||
import org.eclipse.collections.api.stack.MutableStack
|
import org.eclipse.collections.api.stack.MutableStack
|
||||||
import org.eclipse.collections.impl.factory.Multimaps
|
import org.eclipse.collections.impl.factory.Multimaps
|
||||||
|
|
||||||
data class Bag(val count: Int, val color: String)
|
|
||||||
|
|
||||||
@Day(7)
|
@Day(7)
|
||||||
class Day07(@Lines val input: Input<List<String>>) {
|
class Day07(@Lines val input: Input<List<String>>) {
|
||||||
|
|
||||||
|
private data class Bag(val count: Int, val color: String)
|
||||||
|
|
||||||
private val map: ImmutableListMultimap<String, Bag>
|
private val map: ImmutableListMultimap<String, Bag>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -50,8 +49,3 @@ class Day07(@Lines val input: Input<List<String>>) {
|
|||||||
fun part2() = bagSequence("shiny gold").sumBy { it.count }
|
fun part2() = bagSequence("shiny gold").sumBy { it.count }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day07>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
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.IntLists
|
||||||
import org.eclipse.collections.impl.factory.primitive.IntSets
|
import org.eclipse.collections.impl.factory.primitive.IntSets
|
||||||
|
|
||||||
@ -15,7 +14,12 @@ class Day08(@Lines val input: Input<List<String>>) {
|
|||||||
Instruction(Operation.valueOf(words[0].capitalize()), words[1].toInt())
|
Instruction(Operation.valueOf(words[0].capitalize()), words[1].toInt())
|
||||||
}.toTypedArray()
|
}.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<Instruction>): VmResult {
|
private fun run(instructions: Array<Instruction>): VmResult {
|
||||||
var acc = 0
|
var acc = 0
|
||||||
@ -41,7 +45,7 @@ class Day08(@Lines val input: Input<List<String>>) {
|
|||||||
return VmResult.Looped(acc)
|
return VmResult.Looped(acc)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun part2(): VmResult {
|
fun part2(): Int {
|
||||||
val possibleMutations = IntLists.mutable.empty()
|
val possibleMutations = IntLists.mutable.empty()
|
||||||
instructions.forEachIndexed { i, e ->
|
instructions.forEachIndexed { i, e ->
|
||||||
if (e.operation == Operation.Jmp || e.operation == Operation.Nop) possibleMutations.add(i)
|
if (e.operation == Operation.Jmp || e.operation == Operation.Nop) possibleMutations.add(i)
|
||||||
@ -54,7 +58,7 @@ class Day08(@Lines val input: Input<List<String>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val res = run(copy)
|
val res = run(copy)
|
||||||
if (res is VmResult.Terminated) return res
|
if (res is VmResult.Terminated) return res.acc
|
||||||
}
|
}
|
||||||
|
|
||||||
error("No result found")
|
error("No result found")
|
||||||
@ -62,17 +66,11 @@ class Day08(@Lines val input: Input<List<String>>) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 Looped(val acc: Int) : VmResult()
|
||||||
data class Terminated(val acc: Int) : VmResult()
|
data class Terminated(val acc: Int) : VmResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val day = createDay<Day08>()
|
|
||||||
println(day.part1())
|
|
||||||
println(day.part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
|
|
||||||
@Day(9)
|
@Day(9)
|
||||||
class Day09(@Lines val input: Input<LongArray>) {
|
class Day09(@Lines val input: Input<LongArray>) {
|
||||||
@ -49,8 +48,3 @@ class Day09(@Lines val input: Input<LongArray>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day09>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
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.api.list.primitive.MutableIntList
|
||||||
import org.eclipse.collections.impl.factory.primitive.IntLists
|
import org.eclipse.collections.impl.factory.primitive.IntLists
|
||||||
import org.eclipse.collections.impl.factory.primitive.IntLongMaps
|
import org.eclipse.collections.impl.factory.primitive.IntLongMaps
|
||||||
@ -43,8 +42,3 @@ class Day10(@Lines val input: Input<IntArray>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day10>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,27 +3,26 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
|
|
||||||
typealias Seats = Array<CharArray>
|
private typealias Seats = Array<CharArray>
|
||||||
|
|
||||||
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]
|
private 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.set(x: Int, y: Int, value: Char) {
|
||||||
this[y][x] = value
|
this[y][x] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun Seats.contains(xy: Pair<Int, Int>): Boolean {
|
private operator fun Seats.contains(xy: Pair<Int, Int>): Boolean {
|
||||||
val (x, y) = xy
|
val (x, y) = xy
|
||||||
return x in 0 until width && y in 0 until height
|
return x in 0 until width && y in 0 until height
|
||||||
}
|
}
|
||||||
|
|
||||||
val Seats.width get() = first().size
|
private val Seats.width get() = first().size
|
||||||
val Seats.height get() = size
|
private val Seats.height get() = size
|
||||||
|
|
||||||
fun Seats.asGridString() = joinToString("\n") { it.joinToString("") }
|
private fun Seats.asGridString() = joinToString("\n") { it.joinToString("") }
|
||||||
fun Seats.countOccupied() = sumBy { it.count { it == '#' } }
|
private fun Seats.countOccupied() = sumBy { it.count { it == '#' } }
|
||||||
|
|
||||||
@Day(11)
|
@Day(11)
|
||||||
class Day11(@Lines val input: Input<List<String>>) {
|
class Day11(@Lines val input: Input<List<String>>) {
|
||||||
@ -116,8 +115,3 @@ class Day11(@Lines val input: Input<List<String>>) {
|
|||||||
fun part2() = findLastRepeating(seats, ::progress2).countOccupied()
|
fun part2() = findLastRepeating(seats, ::progress2).countOccupied()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day11>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
@Day(12)
|
@Day(12)
|
||||||
@ -79,8 +78,3 @@ class Day12(@Lines val input: Input<List<String>>) {
|
|||||||
return abs(x) + abs(y)
|
return abs(x) + abs(y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day12>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,10 +3,9 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import kotlin.math.abs
|
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)
|
@Day(13)
|
||||||
class Day13(@Lines val input: Input<List<String>>) {
|
class Day13(@Lines val input: Input<List<String>>) {
|
||||||
@ -48,8 +47,3 @@ class Day13(@Lines val input: Input<List<String>>) {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day13>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps
|
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps
|
||||||
import org.eclipse.collections.impl.factory.primitive.LongIntMaps
|
import org.eclipse.collections.impl.factory.primitive.LongIntMaps
|
||||||
@ -93,8 +92,3 @@ class Day14(@Lines val input: Input<List<String>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day14>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Csv
|
import be.vandewalleh.aoc.utils.input.Csv
|
||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps
|
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps
|
||||||
|
|
||||||
@ -43,11 +42,3 @@ class Day15(@Csv val input: Input<IntArray>) {
|
|||||||
|
|
||||||
fun part2() = run(until = 30000000)
|
fun part2() = run(until = 30000000)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
|
||||||
// val input = Input(intArrayOf(3, 1, 2))
|
|
||||||
with(createDay<Day15>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Groups
|
import be.vandewalleh.aoc.utils.input.Groups
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
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.ListMultimap
|
||||||
import org.eclipse.collections.api.multimap.list.MutableListMultimap
|
import org.eclipse.collections.api.multimap.list.MutableListMultimap
|
||||||
import org.eclipse.collections.api.multimap.set.MutableSetMultimap
|
import org.eclipse.collections.api.multimap.set.MutableSetMultimap
|
||||||
@ -148,8 +147,3 @@ class Day16(@Groups val input: Input<List<List<String>>>) {
|
|||||||
return rangesByName
|
return rangesByName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day16>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,12 +3,11 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
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)
|
private 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 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)
|
@Day(17)
|
||||||
class Day17(@Lines val input: Input<List<String>>) {
|
class Day17(@Lines val input: Input<List<String>>) {
|
||||||
@ -87,8 +86,3 @@ class Day17(@Lines val input: Input<List<String>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day17>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,14 +3,13 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
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.Add -> a + b
|
||||||
Operator.Multiply -> a * b
|
Operator.Multiply -> a * b
|
||||||
}
|
}
|
||||||
@ -170,8 +169,3 @@ class Day18(@Lines val input: Input<List<String>>) {
|
|||||||
.reduce { t, u -> t + u }
|
.reduce { t, u -> t + u }
|
||||||
.get()
|
.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day18>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Groups
|
import be.vandewalleh.aoc.utils.input.Groups
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
@ -56,8 +55,3 @@ class Day19(@Groups val input: Input<List<List<String>>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day19>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -6,7 +6,6 @@ import be.vandewalleh.aoc.days.geometry.transformations
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Groups
|
import be.vandewalleh.aoc.utils.input.Groups
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
@ -204,8 +203,3 @@ class Day20(@Groups val input: Input<List<List<String>>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day20>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
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.factory.Bags
|
||||||
import org.eclipse.collections.api.multimap.set.MutableSetMultimap
|
import org.eclipse.collections.api.multimap.set.MutableSetMultimap
|
||||||
import org.eclipse.collections.impl.factory.Multimaps
|
import org.eclipse.collections.impl.factory.Multimaps
|
||||||
@ -57,8 +56,3 @@ class Day21(@Lines val input: Input<List<String>>) {
|
|||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day21>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,9 +3,8 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Groups
|
import be.vandewalleh.aoc.utils.input.Groups
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
|
|
||||||
data class PlayedGame(val a: List<Int>, val b: List<Int>)
|
private data class PlayedGame(val a: List<Int>, val b: List<Int>)
|
||||||
|
|
||||||
@Day(22)
|
@Day(22)
|
||||||
class Day22(@Groups val input: Input<List<List<String>>>) {
|
class Day22(@Groups val input: Input<List<List<String>>>) {
|
||||||
@ -76,9 +75,3 @@ class Day22(@Groups val input: Input<List<List<String>>>) {
|
|||||||
return if (one.isEmpty()) 2 else 1
|
return if (one.isEmpty()) 2 else 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day22>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Text
|
import be.vandewalleh.aoc.utils.input.Text
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
|
|
||||||
@Day(23)
|
@Day(23)
|
||||||
class Day23(@Text val input: Input<String>) {
|
class Day23(@Text val input: Input<String>) {
|
||||||
@ -111,8 +110,3 @@ class Day23(@Text val input: Input<String>) {
|
|||||||
return current.next
|
return current.next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day23>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
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.Bag
|
||||||
import org.eclipse.collections.api.bag.MutableBag
|
import org.eclipse.collections.api.bag.MutableBag
|
||||||
import org.eclipse.collections.api.factory.Bags
|
import org.eclipse.collections.api.factory.Bags
|
||||||
@ -65,8 +64,3 @@ class Day24(@Lines val input: Input<List<String>>) {
|
|||||||
return bag.selectBlacks().size()
|
return bag.selectBlacks().size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day24>()) {
|
|
||||||
println(part1())
|
|
||||||
println(part2())
|
|
||||||
}
|
|
||||||
@ -3,7 +3,6 @@ package be.vandewalleh.aoc.days
|
|||||||
import be.vandewalleh.aoc.utils.input.Day
|
import be.vandewalleh.aoc.utils.input.Day
|
||||||
import be.vandewalleh.aoc.utils.input.Input
|
import be.vandewalleh.aoc.utils.input.Input
|
||||||
import be.vandewalleh.aoc.utils.input.Lines
|
import be.vandewalleh.aoc.utils.input.Lines
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
|
|
||||||
@Day(25)
|
@Day(25)
|
||||||
class Day25(@Lines val input: Input<IntArray>) {
|
class Day25(@Lines val input: Input<IntArray>) {
|
||||||
@ -44,7 +43,3 @@ class Day25(@Lines val input: Input<IntArray>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() = with(createDay<Day25>()) {
|
|
||||||
println(part1())
|
|
||||||
}
|
|
||||||
7
2020/src/main/kotlin/Main.kt
Normal file
7
2020/src/main/kotlin/Main.kt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package be.vandewalleh.aoc.days
|
||||||
|
|
||||||
|
import be.vandewalleh.aoc.utils.factory.createDay
|
||||||
|
|
||||||
|
fun main() = with(createDay<Day25>()) {
|
||||||
|
println(part1())
|
||||||
|
}
|
||||||
6
2020/src/main/resources/simplelogger.properties
Normal file
6
2020/src/main/resources/simplelogger.properties
Normal file
@ -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
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package be.vandewalleh.aoc.days
|
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.Input
|
||||||
import be.vandewalleh.aoc.utils.input.createDay
|
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Nested
|
import org.junit.jupiter.api.Nested
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package be.vandewalleh.aoc.days
|
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.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package be.vandewalleh.aoc.days
|
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 java.util.concurrent.TimeUnit
|
||||||
import org.openjdk.jmh.annotations.*
|
import org.openjdk.jmh.annotations.*
|
||||||
import org.openjdk.jmh.infra.Blackhole
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package be.vandewalleh.aoc.days
|
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 java.util.concurrent.TimeUnit
|
||||||
import org.openjdk.jmh.annotations.*
|
import org.openjdk.jmh.annotations.*
|
||||||
import org.openjdk.jmh.infra.Blackhole
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("advent-of-code")
|
id("advent-of-code-downloader")
|
||||||
}
|
}
|
||||||
|
|
||||||
adventOfCode {
|
adventOfCode {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import java.io.File
|
||||||
|
import java.time.LocalDateTime
|
||||||
import kong.unirest.Unirest
|
import kong.unirest.Unirest
|
||||||
import org.gradle.api.GradleException
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
@ -5,15 +7,13 @@ import org.gradle.api.Project
|
|||||||
import org.gradle.api.tasks.SourceSetContainer
|
import org.gradle.api.tasks.SourceSetContainer
|
||||||
import org.gradle.kotlin.dsl.create
|
import org.gradle.kotlin.dsl.create
|
||||||
import org.gradle.kotlin.dsl.getByType
|
import org.gradle.kotlin.dsl.getByType
|
||||||
import java.io.File
|
|
||||||
import java.time.LocalDateTime
|
|
||||||
|
|
||||||
open class AdventOfCodeExtension {
|
open class AdventOfCodeExtension {
|
||||||
var session: String? = null
|
var session: String? = null
|
||||||
var year: Int = 2020
|
var year: Int = 2020
|
||||||
}
|
}
|
||||||
|
|
||||||
class AdventOfCodePlugin : Plugin<Project> {
|
class AdventOfCodeDownloaderPlugin : Plugin<Project> {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
project.tasks.create("aoc") {
|
project.tasks.create("aoc") {
|
||||||
group = "Advent of Code"
|
group = "Advent of Code"
|
||||||
@ -0,0 +1 @@
|
|||||||
|
implementation-class=AdventOfCodeDownloaderPlugin
|
||||||
@ -1 +0,0 @@
|
|||||||
implementation-class=AdventOfCodePlugin
|
|
||||||
@ -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)
|
|
||||||
}
|
|
||||||
@ -1,3 +1,4 @@
|
|||||||
rootProject.name = "aoc-2020"
|
rootProject.name = "Advent of Code"
|
||||||
include("utils")
|
include("utils")
|
||||||
include("days")
|
include("2020")
|
||||||
|
include("2019")
|
||||||
|
|||||||
@ -5,7 +5,7 @@ plugins {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Libs.Micronaut.core)
|
implementation(Libs.Micronaut.core)
|
||||||
implementation(Libs.Micronaut.inject)
|
api(Libs.Micronaut.inject)
|
||||||
implementation(Libs.Micronaut.kotlin)
|
implementation(Libs.Micronaut.kotlin)
|
||||||
kapt(Libs.Micronaut.processor)
|
kapt(Libs.Micronaut.processor)
|
||||||
|
|
||||||
|
|||||||
@ -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 <T> createDay(beanType: Class<T>): T = BeanContext.run().getBean(beanType)
|
||||||
|
|
||||||
|
inline fun <reified T> 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 <T> createDay(beanType: Class<T>, example: String): T {
|
||||||
|
return BeanContext.build()
|
||||||
|
.apply { registerExampleLoader(example) }
|
||||||
|
.start()
|
||||||
|
.getBean(beanType)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T> createDay(example: String): T = createDay(T::class.java, example)
|
||||||
@ -10,7 +10,7 @@ import javax.inject.Qualifier
|
|||||||
@Qualifier
|
@Qualifier
|
||||||
@Introspected
|
@Introspected
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
annotation class Day(val day: Int)
|
annotation class Day(val value: Int)
|
||||||
|
|
||||||
@Qualifier
|
@Qualifier
|
||||||
@Prototype
|
@Prototype
|
||||||
|
|||||||
@ -90,7 +90,7 @@ class InputFactory(private val resourceLoader: ResourceLoader) {
|
|||||||
if (dayAnnotation.isEmpty)
|
if (dayAnnotation.isEmpty)
|
||||||
error("@DayInput cannot only be used on classes annotated with ${Day::class.qualifiedName}")
|
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 {
|
companion object {
|
||||||
|
|||||||
@ -1,36 +1,11 @@
|
|||||||
package be.vandewalleh.aoc.utils.input
|
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.AnnotationMetadataProvider
|
||||||
import io.micronaut.core.annotation.AnnotationValue
|
import io.micronaut.core.annotation.AnnotationValue
|
||||||
import io.micronaut.core.beans.BeanIntrospection
|
|
||||||
import java.io.File
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
internal inline fun <reified T> getIntrospection(): BeanIntrospection<T> =
|
|
||||||
BeanIntrospection.getIntrospection(T::class.java)
|
|
||||||
|
|
||||||
internal inline fun <reified T : Annotation> AnnotationMetadataDelegate.getAnnotation(): AnnotationValue<T>? =
|
|
||||||
getAnnotation(T::class.java)
|
|
||||||
|
|
||||||
internal inline fun <reified T : Annotation> AnnotationMetadataProvider.findAnnotation(): Optional<AnnotationValue<T>> =
|
internal inline fun <reified T : Annotation> AnnotationMetadataProvider.findAnnotation(): Optional<AnnotationValue<T>> =
|
||||||
findAnnotation(T::class.java)
|
findAnnotation(T::class.java)
|
||||||
|
|
||||||
internal inline fun <reified T : Annotation> AnnotationMetadataProvider.hasAnnotation(): Boolean =
|
internal inline fun <reified T : Annotation> AnnotationMetadataProvider.hasAnnotation(): Boolean =
|
||||||
findAnnotation(T::class.java).isPresent
|
findAnnotation(T::class.java).isPresent
|
||||||
|
|
||||||
inline fun <reified T> createDay() = BeanContext.run().getBean<T>()
|
|
||||||
|
|
||||||
// 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 <reified T> createDay(example: String): T = BeanContext.build()
|
|
||||||
.apply { registerExampleLoader(example) }
|
|
||||||
.start()
|
|
||||||
.getBean()
|
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
package be.vandewalleh.aoc.utils.input
|
package be.vandewalleh.aoc.utils.input
|
||||||
|
|
||||||
|
import be.vandewalleh.aoc.utils.factory.createDay
|
||||||
import com.google.common.jimfs.Jimfs
|
import com.google.common.jimfs.Jimfs
|
||||||
import io.micronaut.context.annotation.Replaces
|
import io.micronaut.context.annotation.Replaces
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.io.path.ExperimentalPathApi
|
import kotlin.io.path.ExperimentalPathApi
|
||||||
import kotlin.io.path.writeText
|
import kotlin.io.path.writeText
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class DayTest {
|
class DayTest {
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user