| 1 | Although brainfuck is basically useless, it isn't quite so crashingly useless
|
|---|
| 2 | as people usually say. Some small tasks can be done fairly concisely.
|
|---|
| 3 | (Some of these are fairly UNIX-specific.)
|
|---|
| 4 |
|
|---|
| 5 | Do nothing, terminate successfully.
|
|---|
| 6 | (Also called "true".)
|
|---|
| 7 | (This is the shortest brainfuck quine as well.)
|
|---|
| 8 |
|
|---|
| 9 | +[>.+<]
|
|---|
| 10 | Real random byte generator.
|
|---|
| 11 | (Send output to file, stop program after a while, and take the last byte.)
|
|---|
| 12 |
|
|---|
| 13 | +++++++.
|
|---|
| 14 | Beep.
|
|---|
| 15 | (Small binary data files are easy to make with brainfuck and a pipe, too.)
|
|---|
| 16 |
|
|---|
| 17 | ,[.[-],]
|
|---|
| 18 | Copy input to output. With a pipe, a no-frills way to make text files.
|
|---|
| 19 | (Unlike most programs assuming EOF->0, this needed modification before it would
|
|---|
| 20 | work with EOF->"no change" as well.)
|
|---|
| 21 | (remove the . to get an input-devourer.)
|
|---|
| 22 |
|
|---|
| 23 | >,[>,]<[.<]
|
|---|
| 24 | Reverse input.
|
|---|
| 25 |
|
|---|
| 26 | unmatched [.
|
|---|
| 27 | A Kimian quine, for my implementation.
|
|---|
| 28 |
|
|---|
| 29 | ,[---------[-[++++++++++.[-]]],]
|
|---|
| 30 | Strip tabs and linefeeds.
|
|---|
| 31 |
|
|---|
| 32 | ++++[>++++++++<-],[[>+.-<-]>.<,]
|
|---|
| 33 | Show ASCII values of input in unary, separated by spaces.
|
|---|
| 34 | (Useful for checking your implementation's newline behavior on input.)
|
|---|
| 35 |
|
|---|
| 36 | ++++++++++[>++++++++++>+<<-]>[>.<-]
|
|---|
| 37 | Clear the screen.
|
|---|
| 38 |
|
|---|
| 39 | +++++++++++[>++++++>+<<-]>+.>-[.[-],]
|
|---|
| 40 | Play "Prisoner's Dilemma" using the robust "Tit for Tat" strategy.
|
|---|
| 41 |
|
|---|
| 42 | +++++++++++[>++++++>+<<-]>++.>-.>,[,[-]<<.>.>,]
|
|---|
| 43 | ...and using the not-so-robust "All D" strategy.
|
|---|
| 44 |
|
|---|
| 45 | +++++[>+++++++++<-],[[>--.++>+<<-]>+.->[<.>-]<<,]
|
|---|
| 46 | Translate text to brainfuck that prints it.
|
|---|
| 47 |
|
|---|
| 48 | >>,[>>,]<<[[-<+<]>[>[>>]<[.[-]<[[>>+<<-]<]>>]>]<<]
|
|---|
| 49 | Sort bytes in ascending order.
|
|---|
| 50 | (These last two are solutions from Brainfuck Golf.)
|
|---|
| 51 |
|
|---|
| 52 | >,[>>>++++++++[<[<++>-]<+[>+<-]<-[-[-<]>]>[-<]<,>>>-]<.[-]<<]
|
|---|
| 53 | Translate "binary" to ASCII, e.g. "0110100001101001" to "hi".
|
|---|
| 54 |
|
|---|
| 55 | +++++[>+++++<-]>[>++>++++<<-]>-->-<[[>[[>>+<<-]<]>>>-]>-[>+>+<<-]>]
|
|---|
| 56 | A novel way of moving to the 9999th cell.
|
|---|
| 57 |
|
|---|
| 58 | >++++[>++++++<-]>-[[<+++++>>+<-]>-]<<[<]>>>>-
|
|---|
| 59 | -.<<<-.>>>-.<.<.>---.<<+++.>>>++.<<---.[>]<<.
|
|---|
| 60 | Print "brainfuck" with a linefeed.
|
|---|
| 61 |
|
|---|
| 62 | ++++++++[>++++[>++>+++>+++>+<<<<-]>+>->+>>+[<]<-]>>.>
|
|---|
| 63 | >---.+++++++..+++.>.<<-.>.+++.------.--------.>+.>++.
|
|---|
| 64 | Print "Hello World!" with a linefeed.
|
|---|
| 65 |
|
|---|
| 66 | >++++++++++>>+<+[[+++++[>++++++++<-]>.<++++++[>--------<-]+<<]>.>[->[<++>-]<[>+
|
|---|
| 67 | <-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>[-]++<<-[>+<-]]]]]]]]]]]+>>]<<]
|
|---|
| 68 | Output powers of two, in decimal. (Doesn't terminate.)
|
|---|
| 69 |
|
|---|
| 70 | Daniel B Cristofani (cristofdathevanetdotcom)
|
|---|
| 71 | http://www.hevanet.com/cristofd/brainfuck/
|
|---|