Skip to content

Commit

Permalink
day 25
Browse files Browse the repository at this point in the history
  • Loading branch information
llimllib committed Dec 25, 2017
1 parent 5c0340e commit b7b6a82
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
23 changes: 23 additions & 0 deletions misc/advent/2017/25/a.py
@@ -0,0 +1,23 @@
from collections import defaultdict


def go(inp, iters):
machine = {}
for line in inp:
state, val, towrite, move, newstate = line.strip().split()
machine[(state, int(val))] = (int(towrite), move, newstate)

tape = defaultdict(int)
ptr = 0
state = "A"
for _ in range(iters):
towrite, move, state = machine[(state, tape[ptr])]
tape[ptr] = towrite
ptr = ptr + 1 if move == "R" else ptr - 1

print(sum(tape.values()), state, ptr)


if __name__ == "__main__":
# go(open("sample.tt"), 6)
go(open("input2.txt"), 12134527)
63 changes: 63 additions & 0 deletions misc/advent/2017/25/input.txt
@@ -0,0 +1,63 @@

Begin in state A.
Perform a diagnostic checksum after 12134527 steps.

In state A:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state B.
If the current value is 1:
- Write the value 0.
- Move one slot to the left.
- Continue with state C.

In state B:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state A.
If the current value is 1:
- Write the value 1.
- Move one slot to the right.
- Continue with state C.

In state C:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state A.
If the current value is 1:
- Write the value 0.
- Move one slot to the left.
- Continue with state D.

In state D:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state E.
If the current value is 1:
- Write the value 1.
- Move one slot to the left.
- Continue with state C.

In state E:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state F.
If the current value is 1:
- Write the value 1.
- Move one slot to the right.
- Continue with state A.

In state F:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state A.
If the current value is 1:
- Write the value 1.
- Move one slot to the right.
- Continue with state E.
12 changes: 12 additions & 0 deletions misc/advent/2017/25/input2.txt
@@ -0,0 +1,12 @@
A 0 1 R B
A 1 0 L C
B 0 1 L A
B 1 1 R C
C 0 1 R A
C 1 0 L D
D 0 1 L E
D 1 1 L C
E 0 1 R F
E 1 1 R A
F 0 1 R A
F 1 1 R E
4 changes: 4 additions & 0 deletions misc/advent/2017/25/sample.tt
@@ -0,0 +1,4 @@
A 0 1 R B
A 1 0 L B
B 0 1 L A
B 1 1 R A

0 comments on commit b7b6a82

Please sign in to comment.