Skip to content

Commit

Permalink
2024 - Day 24 - tweaked part 1 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 25, 2024
1 parent b43c00e commit 61de7c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/main/kotlin/no/rodland/advent_2024/Day24.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ class Day24(val input: List<String>) : Day<Long, Long, Pair<Map<String, Day24.Wi
val (values, logic) = parsed
val system = values.toMutableMap()

val map = logic.map { (k, v) -> buildNode(system, logic, k, v) }
println("hm - ran through buildNode: $i")
return map
return logic
.asSequence()
.map { (k, v) -> buildNode(system, logic, k, v) }
.filter { it.name.startsWith("z") }
.sortedByDescending { it.name }
.map { it.input.value }
.joinToString("") { if (it) "1" else "0" }
.toLong(2)
}

var i = 0
private fun buildNode(system: MutableMap<String, Wire>, input: Map<String, String>, k: String, v: String): Wire {
system[k]?.let { wire -> return wire }
i++
val (aKey, op, bKey) = v.split(" ")
val a = system[aKey] ?: buildNode(system, input, aKey, input[aKey]!!)
val b = system[bKey] ?: buildNode(system, input, bKey, input[bKey]!!)
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/no/rodland/advent_2024/Day24Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class Day24Test {
resultTwo,
{ Day24(data24) },
{ Day24(test24) },
numTestPart1 = 1
numTestPart2 = 1
)

@Nested
Expand Down

0 comments on commit 61de7c4

Please sign in to comment.