脑干,305
(没有来自STDIN的输入号码,请参见底部的编辑)
-[->+>+<<]>>>++++[>++++++++<-]>[<+>-]+++++++[>+++++++++<-]>[<+>-]++++++[>++++++++
<-]>[<+>-]++<<<<>>>+.-<<<[>.>.<.>>>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<
]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<
+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<+<<<
<-]>>-----<<<[->>.>.<.>>.<<<<]
我使用了这种可爱的算法来打印数字,该数字占用了整个程序的155个字节。
它适用于高达32768(算法的16位限制)的输入。它不会产生尾随空格,也可以用于输入1
:
input output
0 [infinite loop (til underflow)]
1 "1"
2 "1 ? 2 : 0"
4 "1 ? 2 ? 3 ? 4 : 0 : 0 : 0"
etc.
快速演练:
设置(97字节)
- Decrease input (position 0)
[->+>+<<] >>> Copy input twice to the right and
shift 3 positions to the right
++++[>++++++++<-]> [<+>-] Precalculate number 32 (=" ") at position 3
+++++++[>+++++++++<-]> [<+>-] Precalculate number 63 (="?") at position 4
++++++[>++++++++<-]> [<+>-] Precalculate number 48 (="0") at position 5
++<<<< Precalculate number 2 for later use. This number
will be printed in each iteration. (position 6)
第一部分(181字节)
>>>+.-<<< Go to the char "0" we saved, increase it, print it,
decrease it and go back (this prints "1" everytime)
[ While our second copy of the number isn't zero
>.>.<.>>> Move to " ", print, move to "?", print,
move to " " again, print, move to our
number at the end which is initially 2
[>>+>+<<<-]>>>[<<<+>>>-]<<+>[<->[>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]
++++++++[<++++++>-]>[<<+>>-]>[<<+>>-]<<]>]<[->>++++++++[<++++++>-]]<
[.[-]<]< Algorithm to print the number at current position
+<<<< Increase our number at the end and return to the beginning
-] Decrease the loop variable
第二部分(27字节)
>>-----<<< Move to our "?" char and decrease it by 5 to get ":"
[- While our first copy of the number isn't zero decrease it
>>.>.<.>>.<<<< Print " ", print ":", print " ", print "0"
]
如果允许将8个Brainfuck命令映射到3位,则此程序将占用114个字节和另外3位
一元,〜4.08 * 10 ^ 275字节
在这里可能太长了,但仅是4084522578628625602393299486062952863611126032086501306085250400447003793314577596676469855866584696018038896282464107885724924379287148671902707089354277989837147977861232927507437712250961455752103200401881554730750730283507507856463802516327402365571
编辑:我搞砸了,该程序并没有真正接受用户输入,它只是使用当前指针值作为输入。为了能够解析更多的数字,将需要更多,而我也不会因此而烦恼。
因此,它可以与直接输入到程序中的值一起使用(在程序前附加n次“ +”),但不适用于STDIN