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