aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

disassembly (834B)


      1 start:
      2 2 4 // B = A % 8
      3 1 5 // B = B ^ 5
      4 7 5 // C = A >> B
      5 1 6 // B = B ^ 6
      6 4 1 // B = B ^ C
      7 5 5 // print B % 8
      8 0 3 // A = A >> 3
      9 3 0 // If A != 0 goto start
     10 
     11 for (A = a; A != 0; A >> 3) {
     12 	B1 = (A % 8) ^ 5;
     13 	C = A >> B1;
     14 	B2 = (B1 ^ 6) ^ C;
     15 	print(B2 % 8);
     16 }
     17 
     18 Goal: Find A such that one iteration prints x and leaves A = a
     19 Going backwards:
     20 A >> 3 = a -> A = 8a + Y
     21 B2 = x
     22 B1 = (A % 8) ^ 5 = Y^5
     23 x = (B1 ^ 6) ^ (A >> B1) = (Y^5 ^ 6) ^ (A >> Y^5)
     24   = (Y ^ 3) ^ (A >> Y^5)
     25 -> x ^ (Y^3) = A >> Y^5
     26 -> A = ((a^Y^3) << Y^5) + Z for some Z < Y^5 < 8
     27 
     28 At the last iteartion, x = 0 and a = 0 so:
     29 -> A = Y
     30 -> x = (Y^3) ^ (Y >> Y^5)
     31 
     32 Y = 0 => x = 3
     33 Y = 1 => x = 2 ^ (1 >> 4) = 2
     34 Y = 2 => x = 1 ^ (2 >> 7) = 1
     35 Y = 3 => x = 0 ^ (3 >> 2) = 0
     36 
     37 => A = Y = 3
     38 
     39 Second to last, x = 3 and a = 3, so
     40 -> A = 24 + Y
     41 3 = (A - 24) ^ 3 ^ ((A-24) >> (A-24)^5)