diff --git a/.gitattributes b/.gitattributes index de50394..15092f8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/src/main/kotlin/y2024/day24/Day24.kt b/src/main/kotlin/y2024/day24/Day24.kt index 38eaf4f..8b470c3 100644 --- a/src/main/kotlin/y2024/day24/Day24.kt +++ b/src/main/kotlin/y2024/day24/Day24.kt @@ -1,6 +1,7 @@ package y2024.day24 import utils.getInputFile +import utils.print fun main() { val day = Day24() @@ -31,7 +32,7 @@ class Day24 { } } - fun solvePartOne(): Long { // 1011110000111111111110101101011110010001110000 too high + fun solvePartOne(): Long { val wireValues = initialWireValues.toMutableMap() return connections.keys @@ -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 { @@ -64,7 +85,7 @@ class Day24 { } } - val naturalOrderComparator = Comparator { str1, str2 -> + private val naturalOrderComparator = Comparator { str1, str2 -> val regex = "\\d+".toRegex() var i = 0 while (i < str1.length && i < str2.length) { diff --git a/src/main/kotlin/y2024/day24/correctedinput.txt b/src/main/kotlin/y2024/day24/correctedinput.txt new file mode 100644 index 0000000..c4192a6 Binary files /dev/null and b/src/main/kotlin/y2024/day24/correctedinput.txt differ diff --git a/src/main/kotlin/y2024/day24/example.txt b/src/main/kotlin/y2024/day24/example.txt deleted file mode 100644 index 09fb230..0000000 --- a/src/main/kotlin/y2024/day24/example.txt +++ /dev/null @@ -1,47 +0,0 @@ -x00: 1 -x01: 0 -x02: 1 -x03: 1 -x04: 0 -y00: 1 -y01: 1 -y02: 1 -y03: 1 -y04: 1 - -ntg XOR fgs -> mjb -y02 OR x01 -> tnw -kwq OR kpj -> z05 -x00 OR x03 -> fst -tgd XOR rvg -> z01 -vdt OR tnw -> bfw -bfw AND frj -> z10 -ffh OR nrd -> bqk -y00 AND y03 -> djm -y03 OR y00 -> psh -bqk OR frj -> z08 -tnw OR fst -> frj -gnj AND tgd -> z11 -bfw XOR mjb -> z00 -x03 OR x00 -> vdt -gnj AND wpb -> z02 -x04 AND y00 -> kjc -djm OR pbm -> qhw -nrd AND vdt -> hwm -kjc AND fst -> rvg -y04 OR y02 -> fgs -y01 AND x02 -> pbm -ntg OR kjc -> kwq -psh XOR fgs -> tgd -qhw XOR tgd -> z09 -pbm OR djm -> kpj -x03 XOR y03 -> ffh -x00 XOR y04 -> ntg -bfw OR bqk -> z06 -nrd XOR fgs -> wpb -frj XOR qhw -> z04 -bqk OR frj -> z07 -y03 OR x01 -> nrd -hwm AND bqk -> z03 -tgd XOR rvg -> z12 -tnw OR pbm -> gnj \ No newline at end of file diff --git a/src/test/kotlin/y2024/day24/Day24Test.kt b/src/test/kotlin/y2024/day24/Day24Test.kt index 680c76d..3b1d8e6 100644 --- a/src/test/kotlin/y2024/day24/Day24Test.kt +++ b/src/test/kotlin/y2024/day24/Day24Test.kt @@ -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()) } }