diff --git a/src/main/kotlin/day3/Day3.kt b/src/main/kotlin/day3/Day3.kt index f75f034..4f75faa 100644 --- a/src/main/kotlin/day3/Day3.kt +++ b/src/main/kotlin/day3/Day3.kt @@ -12,7 +12,7 @@ object Day3 { } .sumOf { it.number } - private fun readLines(file: String): List = + fun readLines(file: String): List = File(file) .readLines() @@ -28,7 +28,7 @@ object Day3 { Part( number.toInt(), Coordinate(x, y), - Coordinate(x + number.length, y) + Coordinate(x + number.length - 1, y) ) ) } diff --git a/src/test/kotlin/day3/Day3Test.kt b/src/test/kotlin/day3/Day3Test.kt index cf12709..07b8cac 100644 --- a/src/test/kotlin/day3/Day3Test.kt +++ b/src/test/kotlin/day3/Day3Test.kt @@ -2,6 +2,7 @@ package day3 import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import kotlin.test.assertContentEquals class Day3Test { @@ -9,4 +10,22 @@ class Day3Test { fun readParts() { assertEquals(4361, Day3.sumOfSelectedParts("src/test/resources/day3/input.txt")) } + + @Test + fun testReadParts() { + assertContentEquals( + listOf(467, 114, 35, 633, 617, 58, 592, 755, 664, 598), + Day3.readParts(Day3.readLines("src/test/resources/day3/input.txt")).map(Part::number) + ) + } + + @Test + fun testOnly114And58DropOut() { + assertContentEquals( + listOf(467, 35, 633, 617, 592, 755, 664, 598), + Day3.readLines("src/test/resources/day3/input.txt").let { lines -> + Day3.readParts(lines).filter { part -> part.isSelected(lines) }.map(Part::number) + } + ) + } } \ No newline at end of file