Skip to content

Commit aa0fe6a

Browse files
committed
Refactoring Day 14 to use entropy to find the least random configuration of points to detect the tree
1 parent eccd9ce commit aa0fe6a

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/main/kotlin/adventofcode/day14/RestroomRedoubt.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ fun List<Point2D>.calculateShannonEntropy(maxX: Int, maxY: Int, gridWidth: Int,
8888

8989
val totalPoints = size.toDouble()
9090
return histogram.values
91+
.asSequence()
9192
.map { it / totalPoints }
9293
.sumOf { -it * ln(it) }
9394
}

0 commit comments

Comments
 (0)