Inject challenges input
This commit is contained in:
@@ -1,22 +1,30 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.Resources
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import io.micronaut.context.BeanContext
|
||||
import io.micronaut.context.getBean
|
||||
|
||||
object Day01 {
|
||||
@Day(1)
|
||||
class Day01(@Lines input: Input<IntArray>) {
|
||||
private val items = input.value
|
||||
|
||||
fun part1(list: List<Int>): Int? {
|
||||
list.forEach { a ->
|
||||
list.forEach { b ->
|
||||
fun part1(): Int? {
|
||||
items.forEach { a ->
|
||||
items.forEach { b ->
|
||||
if (a + b == 2020) return a * b
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun part2(list: List<Int>): Int? {
|
||||
list.forEach { a ->
|
||||
list.forEach { b ->
|
||||
list.forEach { c ->
|
||||
fun part2(): Int? {
|
||||
items.forEach { a ->
|
||||
items.forEach { b ->
|
||||
items.forEach { c ->
|
||||
if (a + b + c == 2020) return a * b * c
|
||||
}
|
||||
}
|
||||
@@ -27,7 +35,7 @@ object Day01 {
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val input = Resources.ints("day01.txt").toList()
|
||||
println(Day01.part1(input))
|
||||
println(Day01.part2(input))
|
||||
val day = BeanContext.run().getBean<Day01>()
|
||||
println(day.part1())
|
||||
println(day.part2())
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.Resources
|
||||
import io.micronaut.context.BeanContext
|
||||
import io.micronaut.context.getBean
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class Day01Test {
|
||||
|
||||
private val input = Resources.ints("day01.txt").toList()
|
||||
private val day = BeanContext.run().getBean<Day01>()
|
||||
|
||||
@Test
|
||||
fun `part1 result`() {
|
||||
assertThat(Day01.part1(input)).isEqualTo(32064)
|
||||
assertThat(day.part1()).isEqualTo(32064)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `part2 result`() {
|
||||
assertThat(Day01.part2(input)).isEqualTo(193598720)
|
||||
assertThat(day.part2()).isEqualTo(193598720)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user