@@ -18,7 +18,6 @@ package adventofcode.day14
1818
1919import adventofcode.util.geom.plane.Point2D
2020import adventofcode.util.geom.plane.Ray
21- import adventofcode.util.grid.TextGrid
2221import adventofcode.util.lcmInt
2322import adventofcode.util.occurrences
2423import adventofcode.util.removeAll
@@ -69,14 +68,6 @@ fun String.calculateSafetyFactorAt(t: Int): Int {
6968 return robots.map { it.move(t, maxX, maxY) }.safetyFactor(maxX, maxY)
7069}
7170
72- fun Set<Point2D>.printGrid (maxX : Int , maxY : Int ) {
73- val grid = TextGrid (" ." .repeat(maxX * maxY).chunked(maxX))
74- forEach { (x, y) ->
75- grid[x, y] = ' #'
76- }
77- println (grid)
78- }
79-
8071fun List<Point2D>.calculateShannonEntropy (maxX : Int , maxY : Int , gridWidth : Int , gridHeight : Int ): Double {
8172 val cellWidth = maxX.toDouble() / gridWidth
8273 val cellHeight = maxY.toDouble() / gridHeight
@@ -101,7 +92,7 @@ fun String.findTree(): Int {
10192 val maxX = robots.maxOf { it.ray.origin.x } + 1
10293 val maxY = robots.maxOf { it.ray.origin.y } + 1
10394 val sequences = robots.map { it.points(maxX, maxY) }
104- val minEntropyT = (1 .. lcmInt(maxX, maxY)).minBy { t ->
95+ val minEntropyT = (1 .. lcmInt(maxX, maxY)).minBy { _ ->
10596 sequences.map { it.next() }.calculateShannonEntropy(maxX, maxY, GRID_WIDTH , GRID_HEIGHT )
10697 }
10798 return minEntropyT
0 commit comments