Skip to content

Commit

Permalink
D24
Browse files Browse the repository at this point in the history
Don't ask
  • Loading branch information
hibob224 committed Dec 24, 2024
1 parent 87a05b1 commit da886fa
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
input.txt filter=git-crypt diff=git-crypt
correctedinput.txt filter=git-crypt diff=git-crypt
sample.txt filter=git-crypt diff=git-crypt
31 changes: 26 additions & 5 deletions src/main/kotlin/y2024/day24/Day24.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package y2024.day24

import utils.getInputFile
import utils.print

fun main() {
val day = Day24()
Expand Down Expand Up @@ -31,7 +32,7 @@ class Day24 {
}
}

fun solvePartOne(): Long { // 1011110000111111111110101101011110010001110000 too high
fun solvePartOne(): Long {
val wireValues = initialWireValues.toMutableMap()

return connections.keys
Expand All @@ -40,11 +41,31 @@ class Day24 {
.reversed()
.joinToString("") { if (wireValues.wireValue(it)) "1" else "0" }
.toLong(2)
// .map { wireValues.wireValue(it) }
}

fun solvePartTwo(): Long {
return 0
fun solvePartTwo(): String {
connections.keys
.filter { it.startsWith("z") }
.filter { connections.getValue(it).third != Operation.XOR }
.print()

val expectedP1 = 51745744348272
println((solvePartOne() xor expectedP1).toString(2))
//2,281,963,520

// connections.keys
// .filter { it.startsWith("z") }
// .sortedWith(naturalOrderComparator)
// .reversed()
//// .onEach {
//// if (!wireValues.wireValue(it)) {
//// Json.encodeToString(Seq.serializer(), wireValues.sequence(it)).print()
//// }
//// }
// .print()

// This one was mostly pen and paper, with some of the above to help find the wires that needed moved...
return "bfq,bng,fjp,hkh,hmt,z18,z27,z31"
}

private enum class Operation {
Expand All @@ -64,7 +85,7 @@ class Day24 {
}
}

val naturalOrderComparator = Comparator<String> { str1, str2 ->
private val naturalOrderComparator = Comparator<String> { str1, str2 ->
val regex = "\\d+".toRegex()
var i = 0
while (i < str1.length && i < str2.length) {
Expand Down
Binary file added src/main/kotlin/y2024/day24/correctedinput.txt
Binary file not shown.
47 changes: 0 additions & 47 deletions src/main/kotlin/y2024/day24/example.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/kotlin/y2024/day24/Day24Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ internal class Day24Test {

@Test
fun solvePartTwo() {
assertEquals(0, day.solvePartTwo())
assertEquals("bfq,bng,fjp,hkh,hmt,z18,z27,z31", day.solvePartTwo())
}
}

0 comments on commit da886fa

Please sign in to comment.