Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Interpreter for the turing-complete language "CT", as
- # described at http://esolangs.org/wiki/Bitwise_Cyclic_Tag,
- # in a single Python 3 expression.
- #
- # This effectively proves single-expression Python Turing-
- # complete, without using eval/exec and assuming a limited
- # call stack, which is the default.
- #
- # In this interpreter, 0 and 1 represent the equivalent CT
- # instructions. 2 represents ";". Any other number appearing
- # in the code will probably break things, so don't try.
- #
- # An additional challenge would be to write the program
- # without __import__ and without the mutating list methods
- # list.pop() and list.extend.
- (lambda code, data_string:
- [data_string.pop(0) if command == 2 else
- data_string.extend([command] * data_string[0])
- for command in __import__("itertools").cycle(code)]
- )(
- code=[2, 1, 0],
- data_string=[1, 1, 0]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement