派克(Pyke),5个字符
0h.CE
这能够产生无限大的数字,将其转换为字符串,然后将其评估为Pyke代码。
代码说明:
0-将0加到堆栈中。这是开始输入号码所必需的
h-之前增加数字。通过任意多次重复此操作,您可以创建无限大的数字。Pyke支持使用Python编写的bignums,它将使用它们作为默认值。
.C-使用以下算法将数字转换成字符串:(Github link)
def to_string(num):
    string = ""
    while num > 256:
        num, new = divmod(num, 256)
        string = chr(new) + string
    string = chr(num) + string
    return string
至此,我们可以在Pyke中使用任意值创建任意数量的字符串和自然数。可以以与正则表达式相对应的形式创建数字,0(h)*并可以使用0(h)*.C。它们可以相互交织在一起,以创建字符串和整数的任意混合。
E-将字符串评估为Pyke代码。这使用与已经运行的Pyke代码相同的环境,因此将共享诸如输入之类的内容。
尝试证明Pyke已完成Turing。
显示语言完整的最简单方法之一是在其中实现Brainf * ck。在Pyke中,这可能比许多其他语言要难得多,因为它的列表和字典操作几乎不存在,因为在Pyke设计用于的区域(code-golf)中不需要它们。
首先,我们为Brainf * ck创建一个解释器,并使用上面的算法对其进行编码以创建一个数字,然后使用0和表示该数字h。然后,我们创建包含要以完全相同的方式运行的代码的字符串。如果我们将其留在那,我们将获得堆栈
string containing brainf*ck code
string containing brainf*ck interpreter
这意味着代码必须采用与Pyke堆栈先进先出的相反形式。
现在开始有趣的部分:高达216个字节的brainf * ck解释器!
Q~B"><ht.,".:=B;Z]1=L;W~Bo@D=c"ht"{I~c~LZ@EZ]1~LR3:=L)~c\,qIz.oZ]1~LR3:=L)~c\.qI~LZ@.CpK)~c"<>"{I~c"<>""th".:ZE=ZZ1_qI0=Z~L0"":0]10:=L)Z~LlqI~L~Ll"":1_]10:=L))~c\[qI~LZ@0qI\]~B~o>@~o+h=o))~c\]qI~o\[~B~o<_@-t=o)~o~BlN
在这里尝试!
如果您想尝试半完成但可编辑的形式的代码,请在此处尝试!
要将字符串转换为数字,可以使用以下Python代码:
def conv(string, t=0):
    t *= 256
    t += ord(string[0])
    if len(string) != 1:
        return conv(string[1:], t)
    return t
(几乎)最终解决方案可以在这里尝试!
Brainf * ck解释器的解释
首先,将程序分为几部分:
Q~B"><ht.,".:=B;Z]1=L; - The initialisation part
Q~B"><ht.,".:          - input.replace("><+-.,[]", "><ht.,")
                       - replace the characters in brainf*ck with some modified ones. 
                       - this means we can `eval` the add and subtract bits easily.
             =B;       - set `B` to this.
                       - The `B` variable contains the instructions
                Z]1=L; - set `L` to [0]
                       - `L` contains the stack, initialised with 0
W~Bo@D=c !code! ~o~BlN - The main loop
W                      - do
 ~Bo@D=c               -  c=B[o++]
                       -  the c variable is used to store the current character.
                ~o~BlN - while
                ~o     -   o 
                     N -  ^ != V 
                  ~Bl  -   len(B)
                       -  this stops the program running once it's finished.
"ht"{I~c~LZ@EZ]1~LR3:=L) - The bit that does incrementing and decrementing
"ht"{I                 ) - if c in "ht"
        ~LZ@             -  L[Z]
                         -  `Z` contains the current stack pointer
      ~c    E            -  eval current character with ^ as an argument
                         -  returns the contents of `Z` either incremented or decremented
             Z]1~LR3:=L  - L[Z] = ^
~c\,qIz.oZ]1~LR3:=L) - The code for output 
~c\,qI             ) -  if character == ",":
      z.o            -    ord(input)
         Z]1~LR3:=L  -   L[Z] = ^
~c\.qI~LZ@.CpK) - The code for input 
~c\.qI        ) - if c == ".":
      ~LZ@      -    L[Z]
          .C    -   chr(^)
            pK  -  print(^)
~c"<>"{I~c"<>""th".:ZE=Z - main part 
~c"<>"{I                 - if "<>" in c:
        ~c"<>""th".:     -  c.replace("<>", "th")
                    ZE=Z -  Z = eval(char, Z)
Z1_qI0=Z~L0"":0]10:=L) - lower bound check
Z1_qI                ) - if Z == -1:
     0=Z               -  Z = 0
        ~L0"":         -  L.insert("", 0)
              0]10:=L  -  L[0] = 0
Z~LlqI~L~Ll"":1_]10:=L) - upper bound check
Z~LlqI                ) - if Z == len(L):
        ~Ll"":          -  L.insert("", len(L))
      ~L      1_]10:=L  -  L[-1] = 0
~c\[qI~LZ@0qI\]~B~o>@~o+h=o)) - Code for `[`
~c\[qI                      ) - if c == "[":
      ~LZ@0qI              )  -  if L[Z] == 0:
               ~B~o>          -     B[o:]
             \]     @         -    ^.find("]")
                     ~o+h=o   -   o = o + ^ + 1
-并且]:
~c\]qI~o\[~B~o<_@-t=o) - Code for `]`
~c\]qI               ) - if c == "]":
          ~B~o<_       -    reversed(B[:o])
        \[      @      -   ^.find("[")
      ~o         -t=o  -  o = o - ^ -1