Brainfuck: Difference between revisions
Finished the page and added champions |
No edit summary |
||
| (4 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
Brainfuck is a Turing complete language created in 1993 by Urban Muller. | Brainfuck is a Turing complete language created in 1993 by Urban Muller. The language was designed to have an extremely tiny compiler (on the order of 200 bytes), while remaining Turing-complete. | ||
The language was designed to have an extremely tiny compiler (on the order of 200 bytes), while remaining Turing-complete | |||
== Language Overview == | == Language Overview == | ||
Brainfuck operates on an array of memory cells, each initially set to zero. In the original implementation, the array was 30,000 cells long and each cell values would be limited to numbers from 0 to 255, but this may not be part of the language specification. A | Brainfuck operates on an array of memory cells, each initially set to zero. In the original implementation, the array was 30,000 cells long and each cell values would be limited to numbers from 0 to 255, but this may not be part of the language specification. A brainfuck program can work with different, and sometimes unbounded, array length and cells size. | ||
Like in a [[Turing machine]], there is a pointer, initially pointing to the first memory cell. | Like in a [[Turing machine]], there is a pointer, initially pointing to the first memory cell. | ||
| Line 21: | Line 19: | ||
|- | |- | ||
|<code>+</code> | |<code>+</code> | ||
|Increment current cell | |Increment current cell | ||
|- | |- | ||
|<code>-</code> | |<code>-</code> | ||
| Line 40: | Line 38: | ||
== BB_brainf == | == BB_brainf == | ||
'''BB_brain(n)''' returns the maximum cell value a program with n instructions can have when halting. | '''BB_brain(n)''' returns the maximum cell value a program with n instructions can have when halting. Commands <code>.</code> and <code>,</code> are ignored. | ||
{| class="wikitable" | {| class="wikitable" | ||
!n | !n | ||
| Line 63: | Line 61: | ||
|- | |- | ||
|5 | |5 | ||
| | |5 | ||
|<code>+++++</code> | |<code>+++++</code> | ||
|- | |- | ||
|6 | |6 | ||
| | |≥ 6 | ||
|<code>++++++</code> | |<code>++++++</code> | ||
|- | |- | ||
|7 | |7 | ||
| | |≥ 7 | ||
|<code>+++++++</code> | |<code>+++++++</code> | ||
|- | |- | ||
|8 | |8 | ||
| | |≥ 8 | ||
|<code>++++++++</code> | |<code>++++++++</code> | ||
|- | |- | ||
|9 | |9 | ||
| | |≥ 9 | ||
|<code>+++++++++</code> | |<code>+++++++++</code> | ||
|- | |- | ||
|10 | |10 | ||
| | |≥ 10 | ||
|<code>++++++++++</code> | |<code>++++++++++</code> | ||
|- | |- | ||
|11 | |11 | ||
| | |≥ 11 | ||
|<code>+++++++++++</code> | |<code>+++++++++++</code> | ||
|- | |- | ||
|12 | |12 | ||
| | |≥ 12 | ||
|<code>++++++++++++</code> | |<code>++++++++++++</code> | ||
|- | |- | ||
|13 | |13 | ||
| | |≥ 16 | ||
|<code>++++[->++++<]</code> | |<code>++++[->++++<]</code> | ||
|- | |- | ||
|14 | |14 | ||
| | |≥ 20 | ||
|<code>+++++[->++++<]</code> | |<code>+++++[->++++<]</code> | ||
|- | |- | ||
|15 | |15 | ||
| | |≥ 25 | ||
|<code>+++++[->+++++<]</code> | |<code>+++++[->+++++<]</code> | ||
|- | |- | ||
|16 | |16 | ||
| | |≥ 30 | ||
|<code>++++++[->+++++<]</code> | |<code>++++++[->+++++<]</code> | ||
|- | |- | ||
|17 | |17 | ||
| | |≥ 36 | ||
|<code>++++++[->++++++<]</code> | |<code>++++++[->++++++<]</code> | ||
|- | |- | ||
|18 | |18 | ||
| | |≥ 42 | ||
|<code>+++++++[->++++++<]</code> | |<code>+++++++[->++++++<]</code> | ||
|- | |- | ||
|19 | |19 | ||
| | |≥ 49 | ||
|<code>+++++++[->+++++++<]</code> | |<code>+++++++[->+++++++<]</code> | ||
|- | |- | ||
|20 | |20 | ||
| | |≥ 56 | ||
|<code>++++++++[->+++++++<]</code> | |<code>++++++++[->+++++++<]</code> | ||
|- | |- | ||
|21 | |21 | ||
| | |≥ 64 | ||
|<code>++++++++[->++++++++<]</code> | |<code>++++++++[->++++++++<]</code> | ||
|- | |- | ||
|22 | |22 | ||
| | |≥ 72 | ||
|<code>+++++++++[->++++++++<]</code> | |<code>+++++++++[->++++++++<]</code> | ||
|- | |- | ||
|23 | |23 | ||
| | |≥ 81 | ||
|<code>+++++++++[->+++++++++<]</code> | |<code>+++++++++[->+++++++++<]</code> | ||
|- | |- | ||
|24 | |24 | ||
| | |≥ 90 | ||
|<code>+++++++++[->++++++++++<]</code> | |<code>+++++++++[->++++++++++<]</code> | ||
|- | |- | ||
|25 | |25 | ||
| | |≥ 340 | ||
|<code>++++[>+[->++<]>[-<++>]<<]</code> | |<code>++++[>+[->++<]>[-<++>]<<]</code> | ||
|- | |- | ||
|26 | |26 | ||
| | |≥ 1364 | ||
|<code>+++++[>+[->++<]>[-<++>]<<]</code> | |<code>+++++[>+[->++<]>[-<++>]<<]</code> | ||
|} | |} | ||
Latest revision as of 07:43, 18 August 2026
Brainfuck is a Turing complete language created in 1993 by Urban Muller. The language was designed to have an extremely tiny compiler (on the order of 200 bytes), while remaining Turing-complete.
Language Overview
Brainfuck operates on an array of memory cells, each initially set to zero. In the original implementation, the array was 30,000 cells long and each cell values would be limited to numbers from 0 to 255, but this may not be part of the language specification. A brainfuck program can work with different, and sometimes unbounded, array length and cells size.
Like in a Turing machine, there is a pointer, initially pointing to the first memory cell.
Programs are composed of commands, represented with symbols:
| Command | Operation |
|---|---|
>
|
Move pointer right |
<
|
Move pointer left |
+
|
Increment current cell |
-
|
Decrement current cell |
[
|
Jump forward past matching ] if current cell is zero
|
]
|
Jump back to matching [ if current cell is non-zero
|
.
|
Output current cell as a character (often ASCII) |
,
|
Input a character and store in current cell |
BB_brainf
BB_brain(n) returns the maximum cell value a program with n instructions can have when halting. Commands . and , are ignored.
| n | BB_brainf(n) | Champion |
|---|---|---|
| 1 | 1 | +
|
| 2 | 2 | ++
|
| 3 | 3 | +++
|
| 4 | 4 | ++++
|
| 5 | 5 | +++++
|
| 6 | ≥ 6 | ++++++
|
| 7 | ≥ 7 | +++++++
|
| 8 | ≥ 8 | ++++++++
|
| 9 | ≥ 9 | +++++++++
|
| 10 | ≥ 10 | ++++++++++
|
| 11 | ≥ 11 | +++++++++++
|
| 12 | ≥ 12 | ++++++++++++
|
| 13 | ≥ 16 | ++++[->++++<]
|
| 14 | ≥ 20 | +++++[->++++<]
|
| 15 | ≥ 25 | +++++[->+++++<]
|
| 16 | ≥ 30 | ++++++[->+++++<]
|
| 17 | ≥ 36 | ++++++[->++++++<]
|
| 18 | ≥ 42 | +++++++[->++++++<]
|
| 19 | ≥ 49 | +++++++[->+++++++<]
|
| 20 | ≥ 56 | ++++++++[->+++++++<]
|
| 21 | ≥ 64 | ++++++++[->++++++++<]
|
| 22 | ≥ 72 | +++++++++[->++++++++<]
|
| 23 | ≥ 81 | +++++++++[->+++++++++<]
|
| 24 | ≥ 90 | +++++++++[->++++++++++<]
|
| 25 | ≥ 340 | ++++[>+[->++<]>[-<++>]<<]
|
| 26 | ≥ 1364 | +++++[>+[->++<]>[-<++>]<<]
|
[page under construction]