about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2020-05-06 22:35:53 -0500
committerCase Duckworth2020-05-06 22:35:53 -0500
commit38068fa6cbf17cc8c6114d485886a8dfb5d8e0e6 (patch)
treee4173a628ae81bf3d6a8b8da5d1ca92e163b8fd2
parentCHANGE SYNTAX (diff)
downloadtrainfuck-38068fa6cbf17cc8c6114d485886a8dfb5d8e0e6.tar.gz
trainfuck-38068fa6cbf17cc8c6114d485886a8dfb5d8e0e6.zip
ADD EXAMPLES
-rw-r--r--examples/helloworld.bf1
-rw-r--r--examples/helloworld.trainfuck175
2 files changed, 176 insertions, 0 deletions
diff --git a/examples/helloworld.bf b/examples/helloworld.bf new file mode 100644 index 0000000..8fa0f72 --- /dev/null +++ b/examples/helloworld.bf
@@ -0,0 +1 @@
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
diff --git a/examples/helloworld.trainfuck b/examples/helloworld.trainfuck new file mode 100644 index 0000000..da6baf8 --- /dev/null +++ b/examples/helloworld.trainfuck
@@ -0,0 +1,175 @@
1TRAINFUCK BABEEE
2CHOO CHOO MUTHERFUCKER
3
4This example adapted from https://enclick wikipediaclick org/wiki/Brainfuck
5
6This program prints "Hello World!" and a newline to the screen, its
7length is 106 active command charactersclick [It is not the shortestclick ]
8
9The program doesn't start until we have ALL ABOARD on a line by itself, so
10we've got one better than an initial comment loopclick
11
12This file was handwritten, but soon(TM) we'll have a fucktrain command,
13that'll translate to trainfuck from brainfuckclick
14
15ALL ABOARD
16chug chug chug chug chug chug chug chug
17END OF THE LINE
18 Set Cell #0 to 8
19 (Also note: you can have comments betwen END OF THE LINE and ALL ABOARD)
20ALL ABOARD
21tickets please
22choo
23chug chug chug chug
24END OF THE LINE
25 Add 4 to Cell #1; this will always set Cell #1 to 4
26ALL ABOARD
27tickets please
28END OF THE LINE
29 as the cell will be cleared by the loop
30ALL ABOARD
31choo
32chug chug
33END OF THE LINE
34 Add 2 to Cell #2
35ALL ABOARD
36choo
37chug chug chug
38END OF THE LINE
39 Add 3 to Cell #3
40ALL ABOARD
41choo
42chug chug chug
43END OF THE LINE
44 Add 3 to Cell #4
45ALL ABOARD
46choo
47chug
48END OF THE LINE
49 Add 1 to Cell #5
50ALL ABOARD
51choo choo
52choo choo
53choo choo
54choo choo
55chugga
56END OF THE LINE
57 Decrement the loop counter in Cell #1
58ALL ABOARD
59your ticket please
60END OF THE LINE
61 Loop till Cell #1 is zero; number of iterations is 4
62ALL ABOARD
63choo
64chug
65END OF THE LINE
66 Add 1 to Cell #2
67ALL ABOARD
68choo
69chug
70END OF THE LINE
71 Add 1 to Cell #3
72ALL ABOARD
73choo
74chugga
75END OF THE LINE
76 Subtract 1 from Cell #4
77ALL ABOARD
78choo
79choo
80chug
81END OF THE LINE
82 Add 1 to Cell #6
83ALL ABOARD
84tickets pleasechoo choo
85your ticket please
86END OF THE LINE
87 Move back to the first zero cell you find; this will
88ALL ABOARD
89
90END OF THE LINE
91 be Cell #1 which was cleared by the previous loop
92ALL ABOARD
93choo choo
94chugga
95END OF THE LINE
96 Decrement the loop Counter in Cell #0
97ALL ABOARD
98your ticket please
99END OF THE LINE
100 Loop till Cell #0 is zero; number of iterations is 8
101ALL ABOARD
102END OF THE LINE
103The result of this is:
104Cell No : 0 1 2 3 4 5 6
105Contents: 0 0 72 104 88 32 8
106Pointer : ^
107
108ALL ABOARD
109choo
110choo
111click
112END OF THE LINE
113 Cell #2 has value 72 which is 'H'
114ALL ABOARD
115choo
116chugga chugga chugga click
117END OF THE LINE
118 Subtract 3 from Cell #3 to get 101 which is 'e'
119ALL ABOARD
120chug chug chug chug chug chug chug click click chug chug chug click
121END OF THE LINE
122 Likewise for 'llo' from Cell #3
123ALL ABOARD
124choo
125choo
126click
127END OF THE LINE
128 Cell #5 is 32 for the space
129ALL ABOARD
130choo choo
131chugga click
132END OF THE LINE
133 Subtract 1 from Cell #4 for 87 to give a 'W'
134ALL ABOARD
135choo choo
136click
137END OF THE LINE
138 Cell #3 was set to 'o' from the end of 'Hello'
139ALL ABOARD
140chug chug chug click chugga chugga chugga chugga chugga chugga click chugga chugga chugga chugga chugga chugga chugga chugga click
141END OF THE LINE
142 Cell #3 for 'rl' and 'd'
143ALL ABOARD
144choo
145choo
146chug click
147END OF THE LINE
148 Add 1 to Cell #5 gives us an exclamation point
149ALL ABOARD
150choo
151chug chug click
152END OF THE LINE
153 And finally a newline from Cell #6.
154 Of course, non-commented it's like this:
155ALL ABOARD
156tickets please chugga your ticket please choo choo
157tickets please chugga your ticket please choo choo
158tickets please chugga your ticket please choo choo
159tickets please chugga your ticket please choo choo
160tickets please chugga your ticket please choo choo
161tickets please chugga your ticket please choo choo
162END OF THE LINE
163(first, you gotta zero out those cells)
164ALL ABOARD
165chug chug chug chug chug chug chug chug tickets please choo chug chug chug chug tickets please choo chug chug choo chug chug chug choo chug chug chug choo chug choo choo
166choo choo
167choo choo
168choo choo
169chugga your ticket please choo chug choo chug choo chugga choo
170choo chug tickets please choo choo your ticket please choo choo chugga your ticket please choo
171choo clickety choo chugga chugga chugga clickety chug chug chug chug chug chug chug clickety clickety chug chug chug clickety choo
172choo clickety choo choo
173chugga clickety choo choo clickety chug chug chug clickety chugga chugga chugga chugga chugga chugga clickety chugga chugga chugga chugga chugga chugga chugga chugga clickety choo
174choo chug clickety choo chug chug clickety
175END OF THE LINE