Live data from Hacker News

Cyclic Tag System: 1 Line of Turing-Complete Code

blog.barvinograd.com

1–10 of 14 posts

Re: Cyclic Tag System: 1 Line of Turing-Complete Code

#2
This is very cool. It's amazing how "simple" something can be and still be Turing-complete.

Also slightly shorter:

  while word[S:]: pIndex, word = (pIndex + 1) % len(C), word[1:] + C[pIndex] * (word[0] == "1")
Or, even shorter,

  while word[S:]: pIndex, word = (pIndex + 1) % len(C), word[1:] + C[pIndex] * int(word[0])
And obviously one can just use one letter variable names/remove whitespace.

Re: Cyclic Tag System: 1 Line of Turing-Complete Code

#6
post #5

"The following line of python code is able to simulate a Universal Turing Machine:" while len(word) > S : pIndex, word = (pIndex + 1) % len(C), word[1:] + C[pIndex] if (word[0] == "1") else word[1:]

It's not obvious for a non-Pythonista, but the if .. else .. is meant to be on the previous line. It's a ternary conditional like cond?a:b in C (with the condition in the middle).

Re: Cyclic Tag System: 1 Line of Turing-Complete Code

#10
post #6
post #5

"The following line of python code is able to simulate a Universal Turing Machine:" while len(word) > S : pIndex, word = (pIndex + 1) % len(C), word[1:] + C[pIndex] if (word[0] == "1") else word[1:]

It's not obvious for a non-Pythonista, but the if .. else .. is meant to be on the previous line. It's a ternary conditional like cond?a:b in C (with the condition in the middle).

Yes, they should have broken the line before `word[1:]` so it was clearer.
Post reply on HN