diff --git a/day17/d17p2.swift b/day17/d17p2.swift index 22308ac..699310e 100644 --- a/day17/d17p2.swift +++ b/day17/d17p2.swift @@ -84,8 +84,8 @@ struct Register : Comparable, CustomStringConvertible { func possibleAs(fromB5 b5Suffix: Int) -> [Register] { let choices: [Register] = (0b000...0b111).compactMap { aSuffix in - let aShift = aSuffix ^ 1 - let b4 = aShift ^ 5 + let aShift = aSuffix ^ 1 // Replace this with first XOR literal + let b4 = aShift ^ 5 // Replace this with second XOR literal let a = Register(value: (b4^b5Suffix) << aShift, mask: 0b111 << aShift) return a.combine(with: Register(value: aSuffix, mask: 0b111)) } diff --git a/day17/minami.swift b/day17/minami.swift new file mode 100644 index 0000000..ef7c7d2 --- /dev/null +++ b/day17/minami.swift @@ -0,0 +1,29 @@ +/* +2,4, 1,5, 7,5, 1,6, 0,3, 4,1, 5,5, 3,0 +bst 4 // B = A % 8 +bxl 5 // B = B ^ 5 +cdv 5 // C = A >> B +bxl 6 // B = B ^ 6 +adv 3 // A = A >> 3 +bxc 1 // B = B ^ C +out 5 // print(B % 8) +jnz 0 // loop while A != 0 +*/ + +import Foundation + +var A = 44374556 +var B = 0 +var C = 0 +while true { + B = A % 8 + B = B ^ 0b101 + C = A >> B + B = B ^ 0b110 + A = A >> 3 + B = B ^ C + print(B % 8, terminator: ",") + if A == 0 { break } +} +print() +