Advertisement
Guest User

BCT

a guest
Aug 17th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # Interpreter for the turing-complete language "CT", as
  2. # described at http://esolangs.org/wiki/Bitwise_Cyclic_Tag,
  3. # in a single Python 3 expression.
  4. #
  5. # This effectively proves single-expression Python Turing-
  6. # complete, without using eval/exec and assuming a limited
  7. # call stack, which is the default.
  8. #
  9. # In this interpreter, 0 and 1 represent the equivalent CT
  10. # instructions. 2 represents ";". Any other number appearing
  11. # in the code will probably break things, so don't try.
  12. #
  13. # An additional challenge would be to write the program
  14. # without __import__ and without the mutating list methods
  15. # list.pop() and list.extend.
  16.  
  17. (lambda code, data_string:
  18.     [data_string.pop(0) if command == 2 else
  19.         data_string.extend([command] * data_string[0])
  20.             for command in __import__("itertools").cycle(code)]
  21. )(
  22.     code=[2, 1, 0],
  23.     data_string=[1, 1, 0]
  24. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement