Skip to content

Instantly share code, notes, and snippets.

@nelhage
Created May 8, 2014 07:27
Show Gist options
  • Save nelhage/aa701c446478edf0a0b0 to your computer and use it in GitHub Desktop.
Save nelhage/aa701c446478edf0a0b0 to your computer and use it in GitHub Desktop.
[A simple Brainfuck quine. This program is not a quine, but if you run
it, its output (which will be the same as the input, but stripped of
all comments and whitespace) will be.
We're going to represent things using four tape cells as one logical
struct. Skip right four cells to leave an empty start-of-tape marker.]
>>>>
[The following line was automatically-generated based on everything
that follows in the program. For each program character in the rest of
the program, we output N plus signs (N = the ASCII value of the
character) and four >'s]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>
[Now the real code begins. First, find the start of the tape again.]
<<<<[<<<<]
[Now output the initial four > characters, then clean up after
ourselves for good measure]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++....[-]
[Now, for each character in the data generated by the above long
line...]
>>>>
[
We left four cells for each input byte; Use the scratch cells now
Fill the next cell over with a plus for later printing
>+++++++++++++++++++++++++++++++++++++++++++<
Now print that plus N times and copy N into each of the remaining
scratch cells
[>.>+>+<<<-]>
Turn the plus into a greater than and print four of those
+++++++++++++++++++....
>>>
]
[We have now output everything up through the giant line above. All
that remains is to output this block of code itself. This is simple
enough -- just loop over and . each cell, making sure to account for
the slight moving-around that happened above.]
<[<<<<]
>>>
[.>>>>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment