From 9e7ac0057b3e06e92fe308fbc1c6347f5bba3060 Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Thu, 12 Dec 2024 21:40:57 +0100 Subject: [PATCH] Even more obfuscation. --- src/aoc2024/Day12.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aoc2024/Day12.kt b/src/aoc2024/Day12.kt index 0fcab9e..3e952ef 100644 --- a/src/aoc2024/Day12.kt +++ b/src/aoc2024/Day12.kt @@ -55,6 +55,7 @@ MMMISSJEEE val grid = CharGrid(input) var sum = 0 val magic = listOf(3, 5, 10, 12) + val star = CharGrid.PLUS_POS.plus(CharGrid.CROSS_POS) for (p in grid.generateGridPos()) { val c = grid[p] if (c != '.') { @@ -70,10 +71,9 @@ MMMISSJEEE newPos = newSeeds } 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 crossCode = CharGrid.CROSS_POS.mapIndexed { index, relPos -> if (areaPos.contains(it.translate(relPos))) 1 shl index else 0 }.sum() - val outer = magic.count { plusCode and it == 0 } - val inner = magic.filterIndexed { i, m -> (plusCode and m == m) && (crossCode and (1 shl i) == 0) }.count() + val b = star.mapIndexed { i, rp -> if (areaPos.contains(it.translate(rp))) 1 shl i else 0 }.sum() + val outer = magic.count { b and it == 0 } + val inner = magic.filterIndexed { i, m -> (b and m == m) && (b and (16 shl i) == 0) }.count() outer + inner } sum += areaPos.size * corners