A Brainfuck program in 5 characters that repeats what you type?
Question ?
Is it possible to write a program in only 5 characters that repeats what was just typed?
Answer !
Yes, indeed! Thanks to the Brainfuck programming language, a minimalist programming language that uses only 8 characters. It was created to be the most minimalistic programming language possible, and today we will see a program in Brainfuck that repeats what you write.
In fact, this code will read characters from the input and write them directly to the output until it encounters the end of the input.
The code:
, [,.]
Here is an explanation of the code:
1. ,
: Read a character from the input and store it in the current cell.
2. [
: Begin a loop. If the current cell is zero, go to the command after the matching ].
3. .
: Write the character in the current cell to the output.
4. ,
: Read a new character from the input and store it in the current cell.
5. ]
: Return to the command after the matching [ if the current cell is not zero.
This continues to read and write characters until a character with a value of zero is read, indicating the end of the input.
Brainfuck interpreter:
If you want to test this program, you can use an Brainfuck interpreter.
Exemple:
YouTube ๐ฅ โ
https://youtube.com/shorts/AICYMTIsLPs?feature=shared
Painting :
Character | Meaning |
> | Increment the data pointer by one (to point to the next cell to the right). |
< | Decrement the data pointer by one (to point to the next cell to the left). |
+ | Increment the byte at the data pointer by one. |
- | Decrement the byte at the data pointer by one. |
. | Output the byte at the data pointer. |
, | Accept one byte of input, storing its value in the byte at the data pointer. |
[ | If the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching] command. |
] | If the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it backto the command after the matching[ command. |
Subscribe to my newsletter
Read articles from Brainphantom directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Brainphantom
Brainphantom
I am a French developer specializing in Brainfuck