source: trunk/Examples/Others/short.b

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