Loop program until (0, 0) is 0 so that Flip can actually be Turing-complete

This commit is contained in:
Anthony Wang 2024-03-02 21:02:45 -05:00
parent 494de8e432
commit 97c68488f0
Signed by: a
SSH key fingerprint: SHA256:B5ADfMCqd2M7d/jtXDoihAV/yfXOAbWWri9+GdCN4hQ
2 changed files with 7 additions and 2 deletions

View file

@ -34,7 +34,7 @@ We think you'll agree that the first version is way more aesthetically pleasing
If you haven't figured it out yet, the Flip program above is [NAND](https://en.wikipedia.org/wiki/NAND_logic#Making_other_gates_by_using_NAND_gates)! Currently, the final line outputs 0, but remove either of the first two lines, and the final output becomes 1. This makes Flip (drumroll please)... Turing complete!
There's only one catch. Since finite Flip programs are guaranteed to terminate, Turing completeness requires Flip programs to possibly be infinitely long. Good luck!
Actually, not quite. Since finite Flip programs are guaranteed to terminate, Turing completeness requires Flip programs to be able to loop forever. One way to do this is to repeat the program until the cell `(0, 0)` is 1 at the end of a repetition of the program.
Even better, a Flip interpreter can be trivially implemented in your favorite programming language. See [Flipper](flipper.py) for the official reference implementation written in Python.

View file

@ -12,9 +12,14 @@ def flip(x, y):
return mem[x][y]
with open(argv[1]) as f:
for line in f.readlines():
lines = f.readlines()
while True:
for line in lines:
l = list(map(int, line.split()))
x = l[0]
for i in range(1, len(l)):
x = flip(x, l[i])
print(x)
if 0 not in mem[0] or mem[0][0] == 0:
exit()