I have been messing around with brainfuck out of boredom. It's a pretty cool language, and it's so simple that I can teach it to you right here.
Brainfuck initializes a large array and then operates on one cell at a time. Each character is an instruction, and there are 8 of them:> Move to next cell
< Move to previous cell
+ Increment current cell
- Decrement current cell
[ Open loop
] Close loop (exits if current cell's value is 0)
, Read a character of input
. Print the current cell to output
This language makes it hard to do simple things. I have written an adder, a multiplier, and a divider. Here is the code for the divider:
It takes three characters of input, where the first is the numerator, the second is the denominator, and the third is the character to be considered 0 (brainfuck uses ASCII values, so an input of the character 0 is normally not equal to a value of 0). The program only resolves if the numbers are evenly divisible, but it is accurate and I'm proud to have managed to put it together.
You can run it and try writing your own brainfuck code here:https://tio.run/#brainfuck
What can you put together? I'd be really impressed by something like a factorial function or a Fibonacci sequence generator. Have fun and stay comfy, anons.