aboutsummaryrefslogtreecommitdiff
path: root/2024/17/disassembly
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-17 08:39:11 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-17 08:39:11 +0100
commita0e775b0a4805a7c1af12c1a956cd9fd74c54b2c (patch)
treeddfc21c0d865d6f871e6ffa0722747ce62077ec0 /2024/17/disassembly
parent5a725f1b9e8cfbad2c31d9c220061e413adbbf8e (diff)
downloadaoc-a0e775b0a4805a7c1af12c1a956cd9fd74c54b2c.tar.gz
aoc-a0e775b0a4805a7c1af12c1a956cd9fd74c54b2c.zip
Day 17 2024 - this was fun
Diffstat (limited to '2024/17/disassembly')
-rw-r--r--2024/17/disassembly41
1 files changed, 41 insertions, 0 deletions
diff --git a/2024/17/disassembly b/2024/17/disassembly
new file mode 100644
index 0000000..edabb41
--- /dev/null
+++ b/2024/17/disassembly
@@ -0,0 +1,41 @@
1start:
22 4 // B = A % 8
31 5 // B = B ^ 5
47 5 // C = A >> B
51 6 // B = B ^ 6
64 1 // B = B ^ C
75 5 // print B % 8
80 3 // A = A >> 3
93 0 // If A != 0 goto start
10
11for (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
18Goal: Find A such that one iteration prints x and leaves A = a
19Going backwards:
20A >> 3 = a -> A = 8a + Y
21B2 = x
22B1 = (A % 8) ^ 5 = Y^5
23x = (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
28At the last iteartion, x = 0 and a = 0 so:
29-> A = Y
30-> x = (Y^3) ^ (Y >> Y^5)
31
32Y = 0 => x = 3
33Y = 1 => x = 2 ^ (1 >> 4) = 2
34Y = 2 => x = 1 ^ (2 >> 7) = 1
35Y = 3 => x = 0 ^ (3 >> 2) = 0
36
37=> A = Y = 3
38
39Second to last, x = 3 and a = 3, so
40-> A = 24 + Y
413 = (A - 24) ^ 3 ^ ((A-24) >> (A-24)^5)

Generated with cgit - Back to sebastiano.tronto.net