Even more obfuscation.

This commit is contained in:
Chris Hodges 2024-12-12 21:40:57 +01:00
parent 90cf5a8335
commit 9e7ac0057b

View File

@ -55,6 +55,7 @@ MMMISSJEEE
val grid = CharGrid(input) val grid = CharGrid(input)
var sum = 0 var sum = 0
val magic = listOf(3, 5, 10, 12) val magic = listOf(3, 5, 10, 12)
val star = CharGrid.PLUS_POS.plus(CharGrid.CROSS_POS)
for (p in grid.generateGridPos()) { for (p in grid.generateGridPos()) {
val c = grid[p] val c = grid[p]
if (c != '.') { if (c != '.') {
@ -70,10 +71,9 @@ MMMISSJEEE
newPos = newSeeds newPos = newSeeds
} }
val corners = areaPos.sumOf { val corners = areaPos.sumOf {
val plusCode = CharGrid.PLUS_POS.mapIndexed { index, relPos -> if (areaPos.contains(it.translate(relPos))) 1 shl index else 0 }.sum() val b = star.mapIndexed { i, rp -> if (areaPos.contains(it.translate(rp))) 1 shl i else 0 }.sum()
val crossCode = CharGrid.CROSS_POS.mapIndexed { index, relPos -> if (areaPos.contains(it.translate(relPos))) 1 shl index else 0 }.sum() val outer = magic.count { b and it == 0 }
val outer = magic.count { plusCode and it == 0 } val inner = magic.filterIndexed { i, m -> (b and m == m) && (b and (16 shl i) == 0) }.count()
val inner = magic.filterIndexed { i, m -> (plusCode and m == m) && (crossCode and (1 shl i) == 0) }.count()
outer + inner outer + inner
} }
sum += areaPos.size * corners sum += areaPos.size * corners