User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
Printable ASCII characters and newlines supported (codes 10, 32–126)
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

About

Brainfuck operates on a tape of 30000 byte cells with only 8 commands: + - > < [ ] . ,. Encoding text naively produces extremely long output. A character like z (ASCII 122) would need 122 consecutive + operations. This tool applies loop-based multiplication and inter-character delta encoding to reduce output length by a factor of 5Γ— to 10Γ—. It computes the optimal loop base b such that b Γ— k approximates each target ASCII value, then emits the minimal residual adjustment. Consecutive characters reuse the current cell value, encoding only the difference Ξ΄ = ci βˆ’ ciβˆ’1. The generator handles all printable ASCII (codes 32 - 126) and common control characters like newline (ASCII 10). Note: this tool approximates optimal Brainfuck. Truly minimal Brainfuck generation is NP-hard in the general case.

brainfuck code generator esoteric language brainfuck encoder text to brainfuck

Formulas

The generator uses two encoding strategies per character and selects the shorter result.

Strategy 1 - Absolute Encoding: For a target ASCII value c, find the integer factor pair (a, b) where a Γ— b c and a + b is minimized. The residual is:

r = c βˆ’ (a Γ— b)

Output: a repetitions of +, then the loop [> b repetitions of + <-]>, then |r| repetitions of + or -, then .

Strategy 2 - Delta Encoding: For consecutive characters ciβˆ’1 and ci, compute:

Ξ΄ = ci βˆ’ ciβˆ’1

If |Ξ΄| is small enough that |Ξ΄| + 1 (for the .) is shorter than the absolute encoding, emit |Ξ΄| repetitions of + or - followed by ..

Compression ratio:

R = LbfLtext

Where Lbf is the length of the generated Brainfuck code and Ltext is the length of the input text. Typical ratios range from 8 to 20 characters of Brainfuck per input character.

Reference Data

CharacterASCII CodeNaive LengthOptimized Length (approx.)Brainfuck Pattern
A6567~18++++++++++[>++++++<-]>+++++.
Z9092~18++++++++++[>+++++++++<-]>.
a9799~20++++++++++[>++++++++++<-]>---.
z122124~22++++++++++[>++++++++++++<-]>++.
04850~16+++++++[>+++++++<-]>-.
95759~18++++++[>++++++++++<-]>---.
(space)3234~14++++++++[>++++<-]>.
!3335~14++++++++[>++++<-]>+.
\n (newline)1012~10++++++++++.
~126128~22++++++++++[>+++++++++++++<-]>-.
H7274~18+++++++++[>++++++++<-]>.
e101103~20++++++++++[>++++++++++<-]>+.
l108110~20+++++++++[>++++++++++++<-]>.
o111113~20++++++++++[>+++++++++++<-]>+.
W8789~18+++++++++[>++++++++++<-]>---.

Frequently Asked Questions

The algorithm exploits delta encoding between consecutive characters. Text with characters close in ASCII value (e.g., "abcd") produces shorter Brainfuck because each delta Ξ΄ is small (1 - 3). Text with wildly varying characters (e.g., "aZaZ") forces frequent absolute encodings with loop constructs, increasing output length.
No. Standard Brainfuck cells are 8-bit (values 0 - 255). This generator targets printable ASCII (codes 10, 32 - 126). Characters outside this range are silently skipped. Unicode would require multi-byte encoding schemes not supported by standard Brainfuck interpreters.
No. Finding the globally optimal Brainfuck program is computationally intractable for non-trivial inputs. This generator uses a greedy heuristic: for each character, it compares absolute loop encoding against delta encoding and picks the shorter one. More advanced techniques (dynamic programming across multiple cells, copy loops) could yield shorter programs but at significantly higher computational cost.
The pattern +++[>++++<-]> sets cell 0 to 3, then loops: each iteration adds 4 to cell 1 and decrements cell 0. After 3 iterations, cell 1 holds 3 Γ— 4 = 12. The generator finds the factor pair (a, b) that minimizes a + b + |r| where r = c βˆ’ a Γ— b.
The generator produces an empty Brainfuck program (zero instructions). This is valid Brainfuck that produces no output when executed.
Yes. The tool includes a built-in interpreter that executes the generated Brainfuck code and displays the output. You can confirm the output matches your original input text. The interpreter uses a tape of 30000 cells initialized to zero, with 8-bit wrapping arithmetic.