1
0
This commit is contained in:
Hubert Van De Walle 2021-12-11 16:44:11 +01:00
parent 118b56e5f3
commit 73235b3e44
19 changed files with 57 additions and 54 deletions

View File

@ -1,18 +1,7 @@
plugins { plugins {
id("kotlin-convention") id("aoc")
kotlin("kapt")
} }
dependencies { application {
implementation(project(":utils")) mainClass.set("be.vandewalleh.aoc.days.MainKt")
kapt(Libs.Micronaut.processor)
implementation(Libs.Slf4J.api)
runtimeOnly(Libs.Slf4J.simple)
implementation(Libs.eclipseCollections)
testImplementation(Libs.Jmh.core)
kaptTest(Libs.Jmh.processor)
} }

View File

@ -36,16 +36,16 @@ class Day11 : BaseDay() {
map.keys.forEach { map[it] = map[it]!! + 1 } map.keys.forEach { map[it] = map[it]!! + 1 }
val flashed = hashSetOf<Point>() val flashed = hashSetOf<Point>()
while (true) { while (true) {
val new = map.entries.asSequence() val count = map.entries.asSequence()
.filter { it.value > 9 } .filter { it.value > 9 }
.filter { it.key !in flashed } .filter { it.key !in flashed }
.onEach { flashed += it.key } .onEach { flashed += it.key }
.flatMap { it.key.adjacents() } .flatMap { it.key.adjacents() }
.filter { it in map } .filter { it in map }
.toList() .onEach { map[it] = map[it]!! + 1 }
.count()
if (new.isEmpty()) break if (count == 0) break
new.forEach { map[it] = map[it]!! + 1 }
} }
map.entries.filter { it.value > 9 } map.entries.filter { it.value > 9 }

View File

@ -32,7 +32,7 @@ class Condition : ExecutionCondition {
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(Condition::class) @ExtendWith(Condition::class)
abstract class BaseDayTest(day: Int) { abstract class BaseDayTest() {
abstract val example: String abstract val example: String
@ -46,7 +46,11 @@ abstract class BaseDayTest(day: Int) {
BeanContext.run() BeanContext.run()
} }
val instance by lazy { ctx.value.getBean(ctx.value.findDayDefinition(day)) } private val day by lazy(LazyThreadSafetyMode.NONE) {
this::class.java.simpleName.replace("Day", "").replace("Test", "").toInt()
}
val instance by lazy { ctx.value.getBean(ctx.value.findDayDefinition(day)!!) }
private val exampleCtx = lazy { private val exampleCtx = lazy {
BeanContext.build() BeanContext.build()
@ -54,7 +58,7 @@ abstract class BaseDayTest(day: Int) {
.start() .start()
} }
val exampleInstance by lazy { exampleCtx.value.getBean(exampleCtx.value.findDayDefinition(day)) } val exampleInstance by lazy { exampleCtx.value.getBean(exampleCtx.value.findDayDefinition(day)!!) }
@AfterAll @AfterAll
fun `after all`() { fun `after all`() {

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day01Test : BaseDayTest(1) { class Day01Test : BaseDayTest() {
override val example = """ override val example = """
199 199
200 200

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day02Test : BaseDayTest(2) { class Day02Test : BaseDayTest() {
override val example = """ override val example = """
forward 5 forward 5
down 5 down 5

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day03Test : BaseDayTest(3) { class Day03Test : BaseDayTest() {
override val example = """ override val example = """
00100 00100
11110 11110

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day04Test : BaseDayTest(4) { class Day04Test : BaseDayTest() {
override val example = """ override val example = """
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day05Test : BaseDayTest(5) { class Day05Test : BaseDayTest() {
override val example = """ override val example = """
0,9 -> 5,9 0,9 -> 5,9
8,0 -> 0,8 8,0 -> 0,8

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day06Test : BaseDayTest(6) { class Day06Test : BaseDayTest() {
override val example = """ override val example = """
3,4,3,1,2 3,4,3,1,2
""".trimIndent() """.trimIndent()

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day07Test : BaseDayTest(7) { class Day07Test : BaseDayTest() {
override val example = """ override val example = """
16,1,2,0,4,2,7,1,2,14 16,1,2,0,4,2,7,1,2,14
""".trimIndent() """.trimIndent()

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day08Test : BaseDayTest(8) { class Day08Test : BaseDayTest() {
override val example = """ override val example = """
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day09Test : BaseDayTest(9) { class Day09Test : BaseDayTest() {
override val example = """ override val example = """
2199943210 2199943210
3987894921 3987894921

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day10Test : BaseDayTest(10) { class Day10Test : BaseDayTest() {
override val example = """ override val example = """
[({(<(())[]>[[{[]{<()<>> [({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>( [(()[<>])]({[<{<<[]>>(

View File

@ -1,6 +1,6 @@
package be.vandewalleh.aoc.days package be.vandewalleh.aoc.days
class Day11Test : BaseDayTest(11) { class Day11Test : BaseDayTest() {
override val example = """ override val example = """
5483143223 5483143223
2745854711 2745854711

View File

@ -2,10 +2,6 @@ plugins {
`kotlin-dsl` `kotlin-dsl`
} }
kotlinDslPluginOptions {
experimentalWarning.set(false)
}
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
maven { setUrl("https://kotlin.bintray.com/kotlinx") } maven { setUrl("https://kotlin.bintray.com/kotlinx") }

View File

@ -0,0 +1,21 @@
plugins {
id("kotlin-convention")
kotlin("kapt")
id("application")
}
dependencies {
implementation(project(":utils"))
kapt(Libs.Micronaut.processor)
implementation(Libs.Slf4J.api)
runtimeOnly(Libs.Slf4J.simple)
implementation(Libs.eclipseCollections)
testImplementation(Libs.Jmh.core)
testImplementation(Libs.Slf4J.simple)
kaptTest(Libs.Jmh.processor)
kaptTest(Libs.Slf4J.simple)
}

View File

@ -5,7 +5,6 @@ plugins {
repositories { repositories {
mavenCentral() mavenCentral()
jcenter()
maven { url = uri("https://dl.bintray.com/arrow-kt/arrow-kt/") } maven { url = uri("https://dl.bintray.com/arrow-kt/arrow-kt/") }
maven { url = uri("https://kotlin.bintray.com/kotlinx") } maven { url = uri("https://kotlin.bintray.com/kotlinx") }
} }

View File

@ -3,6 +3,7 @@ package be.vandewalleh.aoc.utils
import be.vandewalleh.aoc.utils.factory.findDayDefinition import be.vandewalleh.aoc.utils.factory.findDayDefinition
import io.micronaut.context.BeanContext import io.micronaut.context.BeanContext
import java.time.LocalDate import java.time.LocalDate
import kotlin.system.measureTimeMillis
fun runDay(day: Int = LocalDate.now().dayOfMonth) { fun runDay(day: Int = LocalDate.now().dayOfMonth) {
val ctx = BeanContext.run() val ctx = BeanContext.run()
@ -14,23 +15,18 @@ fun runDay(day: Int = LocalDate.now().dayOfMonth) {
} }
val instance = ctx.getBean(definition) val instance = ctx.getBean(definition)
val part1Handle = ctx.findExecutionHandle<Any, Any>(instance, "part1")
if (part1Handle.isEmpty) {
println("part1() not found")
return
}
println("*** Day $day ***") println("*** Day $day ***")
println()
println("part 1:")
println(part1Handle.get().invoke())
println() val p1: Any
val part2Handle = ctx.findExecutionHandle<Any, Any>(instance, "part2") val ms1 = measureTimeMillis {
if (part2Handle.isEmpty) { p1 = instance.part1()
println("part2() not found")
return
} }
println("part 2:") println("part 1 ($ms1 ms): $p1")
println(part2Handle.get().invoke())
val p2: Any
val ms2 = measureTimeMillis {
p2 = instance.part2()
}
println("part 2 ($ms2 ms): $p2")
} }

View File

@ -2,7 +2,6 @@
package be.vandewalleh.aoc.utils.input package be.vandewalleh.aoc.utils.input
import io.micronaut.context.annotation.Executable
import io.micronaut.context.annotation.Prototype import io.micronaut.context.annotation.Prototype
import io.micronaut.core.annotation.Introspected import io.micronaut.core.annotation.Introspected
import jakarta.inject.Qualifier import jakarta.inject.Qualifier
@ -12,5 +11,4 @@ import jakarta.inject.Qualifier
@Introspected @Introspected
@Target(AnnotationTarget.CLASS) @Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME) @Retention(AnnotationRetention.RUNTIME)
@Executable
annotation class Day(val value: Int = -1) annotation class Day(val value: Int = -1)