Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
A 0 1 R B | ||
A 1 0 L B | ||
B 0 1 L A | ||
B 1 1 R A |