Advent of Code 2022 day 10
12/10/2025, 5:00 AMy9san9
12/10/2025, 5:21 AMMarcin Wisniowski
12/10/2025, 7:31 AMbj0
12/10/2025, 7:41 AMJakub Gwóźdź
12/10/2025, 7:52 AMEndre Deak
12/10/2025, 7:57 AMfun main() {
solve("Factory") {
data class Parsed(
val targetVector: BitSet,
val generatorVectors: List<BitSet>,
val increments: List<List<Int>>,
val targetJoltages: List<Int>
)
val input = lines
.map { it.split(" ") }
.map { line ->
val tv = line.first().drop(1).dropLast(1)
.let { raw ->
BitSet(raw.length).apply {
raw.forEachIndexed { i, c -> if (c == '#') set(i) }
}
}
val (gv, gj) = line.drop(1).dropLast(1).map { rem ->
rem.replace("(", "")
.replace(")", "").split(",")
.let { raw ->
BitSet(raw.size).apply {
raw.forEach { set(it.toInt()) }
} to raw.map { it.toInt() }
}
}.let { p -> p.map { it.first } to p.map { it.second } }
val tj = line.last().drop(1).dropLast(1).split(",").map { it.toInt() }
Parsed(tv, gv, gj, tj)
}
fun allCombinations(k: Int, w: Int): List<List<Int>> {
if (w !in 0..k) return emptyList()
val combinations = mutableListOf<List<Int>>()
val indices = IntArray(w) { it + 1 }
var i: Int
while (true) {
combinations.add(indices.toList())
i = w - 1
while (i >= 0 && indices[i] == k - (w - 1 - i)) i--
if (i < 0) break
indices[i]++
for (j in i + 1 until w) indices[j] = indices[j - 1] + 1
}
return combinations.map {
it.map { v -> v - 1 }
}
}
fun combinations(k: Int): List<List<Int>> = (1..k).map { allCombinations(k, it) }.flatten()
part1(-1) {
input.sumOf { (t, g, _, _) ->
val curr = BitSet()
combinations(g.size)
.forEach { combination ->
combination.forEach {
curr.xor(g[it])
if (curr == t) {
return@sumOf combination.size.toLong()
}
}
curr.clear()
}
0
}
}
}ephemient
12/10/2025, 9:16 AMephemient
12/10/2025, 9:18 AMephemient
12/10/2025, 9:19 AMDan Fingal-Surma
12/10/2025, 9:37 AMDan Fingal-Surma
12/10/2025, 9:38 AMDan Fingal-Surma
12/10/2025, 9:38 AMDan Fingal-Surma
12/10/2025, 9:40 AMbrew install z3, copy paste Perl script, thank u, nextDan Fingal-Surma
12/10/2025, 9:46 AMDan Fingal-Surma
12/10/2025, 9:49 AMDan Fingal-Surma
12/10/2025, 9:55 AMephemient
12/10/2025, 10:03 AMephemient
12/10/2025, 10:04 AMMichael de Kaste
12/10/2025, 10:17 AMMichael de Kaste
12/10/2025, 10:27 AMMarcin Wisniowski
12/10/2025, 11:43 AMPetr Sýkora
12/10/2025, 11:56 AMMarcin Wisniowski
12/10/2025, 12:50 PMbj0
12/10/2025, 3:09 PMphldavies
12/10/2025, 3:49 PMJakub Gwóźdź
12/10/2025, 6:07 PMDan Fingal-Surma
12/10/2025, 8:04 PMDan Fingal-Surma
12/10/2025, 8:04 PMDan Fingal-Surma
12/10/2025, 8:06 PMDan Fingal-Surma
12/11/2025, 5:13 AMJakub Gwóźdź
12/11/2025, 5:36 AMDan Fingal-Surma
12/11/2025, 5:39 AMPetr Sýkora
12/11/2025, 10:00 AMJakub Gwóźdź
12/11/2025, 3:26 PM16:19:06.105 [main] INFO Tester -- part 1 ex took 15.498708ms: 7
16:19:06.172 [main] INFO Tester -- part 1 took 66.816875ms: 498
16:19:06.221 [main] INFO Tester -- part 2 ex 2 took 48.687375ms: 99
16:19:06.221 [main] INFO Tester -- part 2 ex took 488.583us: 33
16:19:06.524 [main] INFO Tester -- part 2 took 302.857125ms: 17133
Gauss-Jordan after all. I spent too much time on that yesterday, because there were cases when it was giving not-the-shortest path.
(So I switched to 3-mins long Branch-and-Bound).
But today I changed my approach and instead of any pruning in gauss-jordan, I let it go and collect all possible solutions, and only after that took the .minOf()
Boy I can finally rest 🙂bnorm
12/11/2025, 8:31 PMPart 1: 481 (cold: 30ms, hot: 10ms)
Part 2: 20142 (cold: 188ms, hot: 22ms)Jaap Beetstra
12/15/2025, 9:39 AMJakub Gwóźdź
12/15/2025, 10:07 AMdata class Fraction with a whole set of operations and it's suboptimal 🙂phldavies
12/15/2025, 10:18 AMJakub Gwóźdź
12/15/2025, 10:23 AMJakub Gwóźdź
12/15/2025, 10:25 AM