++<<++<,+++<-[----->-<]<,,[<-----[->++++++++++<]++>[-<+>],]<[>>>>>>[<<<[->>+<<]>>>>>]<<[[>+<-]>>[-[<++++++++++>-]>+>]<[<<]>>[-<<+>>>+<]>>[-[<-[>>+>>]>>[+[-<<+>>]>[-<]<[>]>++>>>]<<<<<-]+>[-<+<+>>]<<[->>+<<]>>>]<[-]<[[-<+>]<<]<]<[->>+<<]<-]>>>>[>>]<<[>-[-----<+>]<----.<<]
在线尝试!
0索引。假定迭代次数最多为255。
说明
磁带的布局如下:
num_iterations 0 0 base digit0 0 digit1 0 digit2 ...
每个数字实际上都存储为该数字加1,其中0表示“没有数字”。在基数转换过程中,当前正在处理的数字向右移动一个单元格,而基数被移至当前工作区域的左侧。
++<<++ Initialize initial value 11
<,+++<-[----->-<] Get single digit as base and subtract 48 to get actual number
<,,[<-----[->++++++++++<]++>[-<+>],] Read multiple digits as number of iterations
< Go to cell containing number of iterations
[ For each iteration:
>>>>>> Go to tens digit cell
[<<<[->>+<<]>>>>>] Move base to just before most significant digit
<< Return to most significant digit
[ For each digit in number starting at the left (right on tape):
[>+<-] Move digit one cell to right (to tell where current digit is later)
>>[-[<++++++++++>-]>+>] Multiply each other digit by 10 and move left
<[<<]>> Return to base
[-<<+>>>+<] Copy base to just before digit (again) and just before next digit to right (left on tape)
>>[ For each digit at least as significant as this digit:
-[<-[>>+>>]>>[+[-<<+>>] Compute "digit" divmod base
>[-<]<[>]>++ While computing this: add quotient to next digit; initialize digit to "1" (0) first if "0" (null)
>>>]<<<<<-] End of divmod routine
+>[-<+<+>>] Leave modulo as current digit and restore base
<<[->>+<<] Move base to next position
>>>
]
<[-]< Delete (now useless) copy of base
[[-<+>]<<]< Move digits back to original cells
] Repeat entire routine for each digit
<[->>+<<] Move base to original position
<- Decrement iteration count
]
>>>>[>>]<<[>-[-----<+>]<----.<<] Output by adding 47 to each cell containing a digit