,[[[-<+>>>+<<]>-[---<+>]<[[-<]>>]<[-]>>[<<,>>>[-[-<++++++++++>]]++++<[->+<]-[----->-<]<]<]>>>[[>>]+[-<<]>>[[>>]+[<<]>>-]]+[>>]<[-]<[<<]>[->[>>]<+<[<<]>]>[>.>]+[>[-]<,.[->+>+<<]>>----------]<[<<]>-<<<,]
オンラインでお試しください!
入力の最後に末尾の改行が必要です。この要件のないバージョンは6バイト長くなります。
,[[[-<+>>>+<<]>-[---<+>]<[[-<]>>]<[-]>>[<<,>>>[-[-<++++++++++>]]++++<[->+<]-[----->-<]<]<]>>>[[>>]+[-<<]>>[[>>]+[<<]>>-]]+[>>]<[-]<[<<]>[->[>>]<+<[<<]>]>[>.>]+[>[-]<,[->+>+<<]>>[----------<.<]>>]<[<<]>-<<<,]
オンラインでお試しください!
どちらのバージョンも、すべての数値が厳密に255未満であると想定しています。
説明
テープは次のように配置されます。
tempinputcopy 85 0 inputcopy number 1 a 1 a 1 r 1 d 0 w 0 o 0 l 0 f 0 ...
「数字」セルは、数字が入力されていない場合は0に等しく、数字nが入力されている場合はn + 1です。入力は、「85」とマークされたセルで行われます。
,[ take input and start main loop
[ start number input loop
[-<+>>>+<<] copy input to tempinputcopy and inputcopy
>-[---<+>] put the number 85 in the cell where input was taken
<[[-<]>>] test whether input is less than 85; ending position depends on result of comparison
(note that digits are 48 through 57 while letters are 97 through 122)
<[-]> clean up by zeroing out the cell that didn't already become zero
>[ if input was a digit:
<<,>> get next input character
>[-[-<++++++++++>]] multiply current value by 10 and add to current input
++++ set number cell to 4 (as part of subtracting 47)
<[->+<] add input plus 10*number back to number cell
-[----->-<] subtract 51
<] move to cell we would be at if input were a letter
<] move to input cell; this is occupied iff input was a digit
part 2: update/output word
>>> move to number cell
[ if occupied (number was input):
[>>]+[-<<]>> remove existing marker 1s and decrement number cell to true value
[[>>]+[<<]>>-] create the correct amount of marker 1s
]
+[>>]<[-] zero out cell containing next letter from previous word
<[<<]> return to inputcopy
[->[>>]<+<[<<]>] move input copy to next letter cell
>[>.>] output word so far
+[ do until newline is read:
>[-]< zero out letter cell
,. input and output next letter or newline
[->+>+<<] copy to letter cell and following cell
>>---------- subtract 10 to compare to newline
]
<[<<]>- zero out number cell (which was 1 to make copy loop shorter)
<<<, return to input cell and take input
] repeat until end of input
0
先頭に0
s がある以外の数はないと想定できますか?