Skip to content

Commit ef43e54

Browse files
committed
Document 2025 day 9 part 2 solution assumptions
1 parent 72ed088 commit ef43e54

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

src/main/scala/eu/sim642/adventofcode2025/Day9.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ object Day9 {
6161
/**
6262
* Solution, which compresses the grid to 2-unit distances between occurring coordinates
6363
* and checks validity by counting outside cells (in the compressed grid) using a [[SumGrid]].
64+
*
65+
* Grid compression assumes no adjacent coordinates occur.
6466
*/
6567
object CompressGridPart2Solution extends Part2Solution {
6668
def makeCompressPos(redTiles: Seq[Pos]): Pos => Pos = {
@@ -113,6 +115,9 @@ object Day9 {
113115

114116
/**
115117
* Solution, which checks validity geometrically using axis-aligned line-box intersection.
118+
*
119+
* Assumes largest area won't be outside.
120+
* Assumes no adjacent coordinates occur.
116121
*/
117122
object IntersectionPart2Solution extends Part2Solution {
118123
override def makeIsValid(redTiles: Seq[Pos]): Box => Boolean = {

src/test/scala/eu/sim642/adventofcode2025/Day9Test.scala

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,74 @@ object Day9Test {
2323
|2,3
2424
|7,3""".stripMargin
2525

26+
val largeUInput =
27+
"""1,1
28+
|3,1
29+
|3,1000
30+
|1000,1000
31+
|1000,1
32+
|1002,1
33+
|1002,1002
34+
|1,1002""".stripMargin
35+
36+
val adjacentCoordinateInput = // from Timvde on Libera IRC
37+
"""1,1
38+
|3,1
39+
|3,6
40+
|4,6
41+
|4,1
42+
|6,1
43+
|6,10
44+
|1,10""".stripMargin
45+
2646
class Part1Test extends AnyFunSuite {
2747

2848
test("Part 1 examples") {
2949
assert(Part1.largestArea(parseRedTiles(exampleInput)) == 50)
3050
}
3151

52+
test("Part 1 large U") {
53+
assert(Part1.largestArea(parseRedTiles(largeUInput)) == 1004004)
54+
}
55+
56+
test("Part 1 adjacent coordinate") {
57+
assert(Part1.largestArea(parseRedTiles(adjacentCoordinateInput)) == 60)
58+
}
59+
3260
test("Part 1 input answer") {
3361
assert(Part1.largestArea(parseRedTiles(input)) == 4729332959L)
3462
}
3563
}
3664

37-
abstract class Part2SolutionTest(part2Solution: Part2Solution) extends AnyFunSuite {
65+
abstract class Part2SolutionTest(val part2Solution: Part2Solution) extends AnyFunSuite {
3866

3967
test("Part 2 examples") {
4068
assert(part2Solution.largestArea(parseRedTiles(exampleInput)) == 24)
4169
}
4270

71+
ignore("Part 2 adjacent coordinate") {
72+
// should not be 30
73+
assert(part2Solution.largestArea(parseRedTiles(adjacentCoordinateInput)) == 60)
74+
}
75+
4376
test("Part 2 input answer") {
4477
assert(part2Solution.largestArea(parseRedTiles(input)) == 1474477524L)
4578
}
4679
}
4780

48-
class CompressGridPart2SolutionTest extends Part2SolutionTest(CompressGridPart2Solution)
81+
class CompressGridPart2SolutionTest extends Part2SolutionTest(CompressGridPart2Solution) {
82+
83+
test("Part 2 large U") {
84+
// should not be 998000, which would be the completely outside box in the large U
85+
assert(part2Solution.largestArea(parseRedTiles(largeUInput)) == 3006)
86+
}
87+
}
4988

50-
class IntersectionPart2SolutionTest extends Part2SolutionTest(IntersectionPart2Solution)
89+
class IntersectionPart2SolutionTest extends Part2SolutionTest(IntersectionPart2Solution) {
90+
91+
ignore("Part 2 large U") { // fails due to assumption
92+
// should not be 998000, which would be the completely outside box in the large U
93+
assert(part2Solution.largestArea(parseRedTiles(largeUInput)) == 3006)
94+
}
95+
}
5196
}

0 commit comments

Comments
 (0)