Skip to content

Commit

Permalink
day17 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 22, 2024
1 parent c2f5cf1 commit 65e9618
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
11 changes: 3 additions & 8 deletions examples/aoc2024/day17/part1.jou
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class Machine:
def run(self) -> None:
while *self->ip != -1:
self->step()
self->print()
#getchar()

# Prints machine code and registers to stdout in human-readable form.
def print(self) -> None:
Expand Down Expand Up @@ -154,7 +156,7 @@ class Machine:


def main() -> int:
f = fopen("sampleinput.txt", "r")
f = fopen("input", "r")
assert f != NULL

m = Machine{}
Expand Down Expand Up @@ -192,13 +194,6 @@ def main() -> int:
# Output: 4 if A != 0: jump to 0
m.print()

# Output: Registers: A=364 B=0 C=0
# Output: 0 A /= 2**1
# Output: --> 2 output A % 8
# Output: 4 if A != 0: jump to 0
m.step()
m.print()

# Output: 4,6,3,5,6,3,5,2,1,0
m.run()
for i = 0; i < m.output_len; i++:
Expand Down
31 changes: 31 additions & 0 deletions examples/aoc2024/day17/part2.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# My input looked like this, as printed by code in part 1:
#
# Registers: A=... B=0 C=0
# 0 B = A % 8
# 2 B ^= 1
# 4 C = A / 2**B
# 6 B ^= 5
# 8 B ^= C
# 10 A /= 2**3
# 12 output B % 8
# 14 if A != 0: jump to 0
#
# Suppose that value of A register in binary looks like ....abcdefgh, where
# abcdefgh are the last bits. For example, if A = 420 = binary 110100100, then
# abcdefgh = 10100100. Let's step through the code and see what it does:
#
# Registers: A=...abcdefgh B=0 C=0
# 0 B = def
# 2 B = deF here F denotes the opposite of f
# 4 C = fgh if deF=000
# efg if deF=001
# def if deF=010
# cde if deF=011
# bcd if deF=100
# abc if deF=100
# ..
# 6 B ^= 5
# 8 B ^= C
# 10 A /= 2**3
# 12 output B % 8
# 14 if A != 0: jump to 0

0 comments on commit 65e9618

Please sign in to comment.