-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_explanation.py
253 lines (252 loc) · 7.82 KB
/
create_explanation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
explanations = {
"☻" : "push 16",
"♥" : "push 32",
"♦" : "push 64",
"♣" : "push 128",
"♠" : "push 256",
"•" : "push 512",
"◘" : "push 1024",
"○" : "push 2048",
"◙" : "push 4096",
"♂" : "push 10",
"♀" : "push 100",
"♪" : "push 1000",
"♫" : "push 10000",
"☼" : "push 100000",
"►" : "push 1000000",
"◄" : "push 10000000",
"↕" : "push 100000000",
"¶" : "is_prime(n)",
"§" : "get from array",
"↑" : "while true without popping",
"↓" : "while false without popping",
"→" : "while true with pop",
"←" : "while false with pop",
"∟" : "do while true without popping",
"↔" : "do while false without popping",
"↨" : "pop a, b, loop from a to b (inclusive)",
"▲" : "do while true with pop",
"▼" : "do while false with pop",
" " : "space character",
"!" : "gamma(n+1)",
"\"" : "string notation",
"#" : "pop a, b : push(a**b)",
"▬" : "pop a, b : push(b**a)",
"$" : "pop(a), push ord(a) or char(a)",
"%" : "modulo",
"'" : "push single character",
"(" : "decrement",
")" : "increment",
"*" : "pop a, b : push(a*b)",
"." : "pop a, b : push(b*a)",
"+" : "pop a, b : push(a+b)",
"-" : "pop a, b : push(a-b)",
"/" : "pop a, b : push(a/b), split strings",
"0" : "push 0",
"1" : "push 1",
"2" : "push 2",
"3" : "push 3",
"4" : "push 4",
"5" : "push 5",
"6" : "push 6",
"7" : "push 7",
"8" : "push 8",
"9" : "push 9",
";" : "discard TOS",
"<" : "pop(a, b), push(a<b)",
"=" : "pop(a, b), push(a==b)",
">" : "pop(a, b), push(a>b)",
"?" : "rot3",
"@" : "rrot3",
"A" : "push 11",
"B" : "push 12",
"C" : "push 13",
"D" : "push 14",
"E" : "push 15",
"F" : "push 17",
"G" : "push 18",
"H" : "push 19",
"I" : "push 20",
"J" : "push 21",
"K" : "push 22",
"L" : "push 23",
"M" : "push 24",
"N" : "push 25",
"O" : "push 26",
"P" : "push 27",
"Q" : "push 28",
"R" : "push 29",
"S" : "push 30",
"T" : "push 31",
"U" : "push 33",
"V" : "push 34",
"W" : "push 35",
"X" : "push 36",
"Y" : "push 37",
"Z" : "push 38",
"[" : "start array",
"\\" : "swap top elements",
"]" : "end array / wrap stack in array",
"^" : "zip top two elements on stack",
"_" : "duplicate TOS",
"`" : "duplicate the top two items",
"a" : "wrap in array",
"b" : "push -1",
"c" : "push -2",
"d" : "push -3",
"e" : "push e (2.71828...)",
"f" : "pop a, push fibonacci(a)",
"g" : "pop a, (b), pop operator from code, filter",
"h" : "length of array/string without popping",
"i" : "convert to integer (implicit map)",
"j" : "read float from input",
"k" : "read integer from input",
"l" : "read string from input",
"m" : "explicit map",
"n" : "newline char, or map array with newlines",
"o" : "print TOS without popping",
"p" : "print with newline",
"q" : "print without newline",
"r" : "range(0, n)",
"s" : "sort(array)",
"t" : "unix timestamp as integer milliseconds",
"u" : "join with separator",
"v" : "random integer in [-2**31, 2**31-1]",
"w" : "random integer in range, random item from list",
"x" : "reverse int/array/string",
"y" : "join array without separator to string or number",
"z" : "reverse sort(array)",
"{" : "start block or arbitrary length",
"}" : "end block",
"~" : "evaluate string, dump array, negate integer",
"⌂" : "asterisk character (for challenges where a printable character is needed)",
"Ç" : "inverted filter",
"ü" : "ceiling with implicit map",
"â" : "convert to binary",
"ä" : "convert from binary",
"à" : "convert to binary string",
"å" : "convert from binary string",
"ç" : "implicit faulty filter",
"ê" : "read entire input as int array",
"ë" : "read entire input as float array",
"è" : "read entire input as string array",
"ï" : "index of current loop, or length of last loop",
"î" : "index of current loop (1-based)",
"ì" : "get loop value in foreach loop",
"Ä" : "start block of length 1",
"Å" : "start block of length 2",
"É" : "start block of length 3",
"æ" : "start block of length 4",
"Æ" : "start block of length 5",
"ô" : "start block of length 6",
"ö" : "start block of length 7",
"ò" : "start block of length 8",
"û" : "start string of length 2",
"ù" : "start string of length 3",
"ÿ" : "start string of length 4",
"¢" : "convert to/from hexadecimal",
"£" : "length of array/string with pop",
"¥" : "modulo 2",
"ƒ" : "random float in range [0,1]",
"á" : "sort by comparator",
"í" : "get total number of iterations of for loop",
"ó" : "pop(a), push(2**a)",
"ú" : "pop(a), push(10**a)",
"ñ" : "pop(a), push palindromize(a) string/list/number",
"Ñ" : "check if palindrome",
"ª" : "push [1]",
"º" : "push [0]",
"¿" : "if/else (uses one of the next two characters/blocks in the code)",
"⌐" : "rotate entire stack",
"¬" : "rotate entire stack in reverse",
"½" : "pop a : push(a//2 if int else a/2)",
"¼" : "pop a : push(a//4 if int else a/4)",
"¡" : "push a, b, push a != b",
"«" : "end compressed string (etaoinsrdluczbfp)",
"»" : "end compressed string (gwymvkxjqh ?*#.,)",
"░" : "convert to string (implicit map)",
"▒" : "split to list of chars/digits",
"▓" : "get average of list",
"│" : "get differences of list",
"┤" : "pop from right of string/array",
"╡" : "discard from right of string/array",
"╢" : "start compressed string of length 2 (etaoinsrdluczbfp)",
"╖" : "start compressed string of length 3 (etaoinsrdluczbfp)",
"╕" : "start compressed string of length 4 (etaoinsrdluczbfp)",
"╣" : "start compressed string of length 2 (gwymvkxjqh ?*#.,)",
"║" : "start compressed string of length 3 (gwymvkxjqh ?*#.,)",
"╗" : "start compressed string of length 4 (gwymvkxjqh ?*#.,)",
"╜" : "else without if",
"╛" : "if without else",
"┐" : "push TOS-1 without popping",
"└" : "push TOS+1 without popping",
"┴" : "check if equal to 1",
"┬" : "check if equal to 0",
"├" : "pop from left of string/array",
"─" : "flatten array",
"┼" : "duplicate second item from top and push to top",
"╞" : "discard from left of string/array",
"╟" : "push 60",
"╚" : "push 3600",
"╔" : "push 86400",
"╩" : "fetch single dictionary word (top 256)",
"╦" : "fetch single dictionary word (all)",
"╠" : "pop a, b, push b/a",
"═" : "pad list elements to equal length",
"╧" : "pop a, b, a.contains(b)",
"╨" : "closest power of two above",
"╤" : "range(-n, n+1)",
"╥" : "closest power of two below",
"╙" : "maximum of two elements, max of list, maximum by filter",
"╘" : "discard everything in stack",
"╒" : "range(1,n+1)",
"╓" : "minimum of two elements, min of list, minimum by filter",
"╫" : "left-rotate bits in int, list/str",
"╪" : "right-rotate bits in int, list, str",
"┘" : "convert to boolean",
"┌" : "convert to inverted boolean",
"▄" : "lowercase alphabet as string",
"▌" : "prepend to start of list",
"▐" : "append to end of list",
"▀" : "unique elements of string/list",
"α" : "wrap last two elements in array",
"ß" : "wrap last three elements in array",
"Γ" : "wrap last four elements in array",
"π" : "pi (3.14159...)",
"Σ" : "sum(list), digit sum(int)",
"σ" : "remove leading zeroes",
"µ" : "swap array/string items",
"τ" : "tau (2*pi)",
"Φ" : "increment array/string item",
"Θ" : "decrement array/string item",
"Ω" : "center string/int",
"δ" : "capitalize string",
"∞" : "pop a, push 2*a",
"φ" : "golden ratio (1.618...)",
"ε" : "reduce list with operator",
"±" : "absolute value",
"≥" : "greater or equal",
"≤" : "lesser or equal",
"⌠" : "increment twice",
"⌡" : "decrement twice",
"÷" : "is divisible",
"°" : "is perfect square",
"∩" : "pop a : push 1/a (implicit map)",
"∙" : "triplicate TOS",
"·" : "quadruplicate TOS",
"√" : "pop a : push(sqrt(a)), split string to list",
"ⁿ" : "pop a : push(a*a*a)",
"²" : "pop a : push(a*a)",
"■" : "cartesian product with itself for lists, next collatz item for numbers",
" " : "discard everything but TOS"
}
def create_explanation(code):
l = len(code)
print('## Explanation\n')
for i, c in enumerate(code):
if c in explanations:
explained = explanations[c]
else:
explained = "not implemented yet"
row = (4+i)*" " + c + (l-i+2)*" " + explained
print(row)