>>++++[->++++[->+>++++++<<]<]>>->[-<[-<<<<++++[->++++++++<]]>>>[<<<<<++++++++[->>++<<<+>]>>-<<<++>>]<<[>>>>>>[>>>]>+<<<<<[<<<]<<-]>>>>>>[>>>]++++[-<++++++++>]>[-<+>]<<[<<<]>>]<[-]<<,[[->+>+<<],[-]++++[->>--------<<]>>[>>>>[>>>]+[<<<]<-]>>>>[>>>]<<[-]<[<<<]<<[>>>>>[>>>]<<+<[<<<]<<-]>>>>>[>>>]<<<[[-]<<<]>[.>.>>]++++++++++[->+>++<<]>>[-<.>]<[-]<<<<[<<<]<,]
BrainFuck的选项非常有限,因此输出在终端中,并且屏幕上有20个换行符来“清除”屏幕。输入应为ASCII字符,以换行符分隔。
在线尝试!
格式化并记录
这些是我用来编写程序的调试说明。我使用了解释器,该解释器可以选择在每个“〜”字符处打印磁带的状态以进行调试。
[
run.bf
codegolf.stackexchange.com/questions/124306/map-inputted-ascii-characters
]
[
Calculate 16 * 6
Resulting tape state:
[0 0 0 0 0 0 16 96 0 0 0 0 ...]
^
Note that, to obtain a 16-by-6 grid, the 16
immediately to the right is decreased to 15
(since we will decrease it by 1 each loop
until we reach 0 and immediately reset)
]
>>>>++++[->++++[->+>++++++<<]<]>~
[
Our next goal is to make 96 sets of 3 cells each in the pattern [C D 0]
The first cell will represent an entered character--when the corresponding
input on the keyboard is pressed, it will change to the entered key.
The first cell is initialized to 32 (' ').
The second cell will represent the delimiter after that character.
Every 16 cells, this should be 10 for '\n'. Otherwise, it should be 32 for ' '.
The third cell is a buffer cell, used for traversal of the grid. In general,
it should be only temporarily modified and then reset to 0.
]
>->[-<
[
-<<<<++++[->++++++++<]
[
The second cell of our 3-set should be 32, so the above line
writes 32 to the 3rd cell from the beginning of the tape (0-indexed)
]
]
>>>
[
<<<[ The second cell of our 3-set should be 10, and we must reset the line counter ]
<<++++++++[->>++<<<+>]>>-<<<++>>
]
[ At this point, the delimiting cell we need is two cells to the left. ]
<<[>>>>>>[>>>]>+<<<<<[<<<]<<-]
>>>>>>[>>>]++++[-<++++++++>]
[ Debug Mode: In the previous loop, add a + in the string of 8 +'s to get visible spaces in the grid ($-signs) ]
>[-<+>]<<[<<<]>>
]
[ Go back to the beginning of the tape and clear up the residual '15' ]
<[-]~
<<,
[
[->+>+<<],[-]++++[->>--------<<]
[
Take input such that the state of the tape now looks like this:
[0 0 0 0 0 c c-32 0 32 32 0 32 32 0 32 32 0 ...]
^
Where 'c' was the entered character.
We now set up 1's in the buffer zones of the first c-32
3-sets and clear the character that is currently there.
All that is left, then, is to copy c to that location.
]
[ Set up the row of 1's. ]
>>[>>>>[>>>]+[<<<]<-]
[ Clear the current character. ]
>>>>[>>>]<<[-]~<[<<<]
[ Copy the new character. ]
<<[>>>>>[>>>]<<+<[<<<]<<-]
[ Clean up the 1's. ]
>>>>>[>>>]~<<<[[-]<<<]
[ Print the grid. ]
>[.>.>>]~
[ Print a bunch of newlines ]
++++++++++[->+>++<<]>>[-<.>]<[-]
[ Take a new input. ]
<<<<[<<<]<,
]