-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta.in
183 lines (183 loc) · 6.07 KB
/
meta.in
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
>>>>[-] move to case flag/instruction pointer and empty it
> to the instructions
[>]< to the last instruction
[ compact all cells by 31 (the biggest unused special ASCII char)
----- ----- ----- -----
----- ----- - <]
> back to instuctions
interpreter switch/loop
[<+> set case flag
[plus (43 minus 31)
----- ----- --
[- comma (44 minus 31)
[- minus (45 minus 31)
[- period (46 minus 31)
[less than (60 minus 31)
----- ----- ----
[-- greater than (62 minus 31)
[opening bracket (91 minus 31)
----- -----
----- -----
----- ----
[-- closing bracket (93 minus 31)
[ default case
restore and move the original value (93 minus 31)
+++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++ ++
[<<<+>>>-]
<->] kill the case flag and exit
case closing bracket
<[- kill the flag
restore the value (93 minus 31 or closing bracket)
<< ++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++ +++++
tovaluecell()
if the cell is not zero then move the instruction pointer
to the opening bracket
tovalue() value cell
[fromvaluecell()
<< move to the last instruction
[>>>+<<<-] copy it to be processed
>+ set up the bracket count
[<+ set up the case flag
<[switch:
opening bracket
----- ----- ----- ----- ----- -----
----- ----- ----- ----- ----- -----
[-- closing bracket
[default:
>-< kill flag
restore the character
++ +++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++
[>>>+<<<-] copy to be processed later
]
>[ case closing bracket:
- kill the flag
>+ increase bracket count
> ++ +++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++ restore bracket
<<
]<
]
>[ case opening bracket:
- kill the flag
>- decrease the bracket count
restore opening bracket
> +++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++
<< back to the flag
]<
]
>>[<+>-] move the bracket count
<] and loop while it's positive
we're at [P] [0] [B(0)^] [0] [opening bracket] [T]
>>[<<<+>>>-] copy the opening bracket to move inside it
<<< to the copied bracket
move to the value cell
tovaluecell()
tovalue()[fromvalue()+tovalue()-]] backup the value cell to N and exit
fromvalue()[tovalue()+fromvalue()-]tovalue() copy the value if it was backed up
fromvaluecell()
]>]
< case opening bracket
[[-] kill the flag
+ and set the bracket count instead of it
restore 91 (opening bracket)
<< +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++ +++++
>> back to the bracket count
[ matching bracket search
>+ set case flag
>[switch:
opening bracket (91 minus 31)
----- ----- ----- ----- ----- -----
----- ----- ----- ----- ----- -----
[ closing bracket (93 minus 31)
--
[ default:
<-> kill the flag
restore the character
++ +++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++
[<<<+>>>-] copy the character to the processed sector
]
<[ case closing bracket:
- kill the flag
<- subtract one from the bracket count
restore closing bracket in the processed sector
< ++ +++++ +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++
>> back to the case flag
]>
]
<[ case opening bracket:
- kill the flag
<+ add one to the bracket count
restore opening bracket in the processed sector
< +++++ +++++ +++++ +++++ +++++
+++++ +++++ +++++ +++++ +++++ +++++ +++++
>> back to the case flag
]>
]
<<[>+<-]> copy the bracket count closer and loop
] matching bracket search ends
we're at [P] [closing bracket] [0] [B(0)^] [0] [T]
<<[>>>+<<<-] copy the closing bracket to be processed next
> back to the new fake case flag
]>]
< case greater than
[- kill the flag
restore the value (62 minus 31 or greater than)
<< + +++++ +++++ +++++ +++++ +++++ +++++
add/subtract one to N
[<]<right()
back to the killed flag
>>[>]>
]>]
< case less than
[- kill the flag
restore the value (60 minus 31 or less than)
<<++++ +++++ +++++ +++++ +++++ +++++
subtract/add one to N
[<]<left()
back to the killed flag
>>[>]>
]>]
< case period
[- kill the flag
restore the value (46 minus 31 or period)
<< +++++ +++++ +++++
tovaluecell()
tovalue(). print the value cell
fromvaluecell()
]>]
< case minus
[- kill the flag
restore the value (45 minus 21 or minus)
<<++++ +++++ +++++
tovaluecell()
tovalue()- decrease it
fromvaluecell()
]>]
< case comma
[- kill the flag
restore the value (44 minus 31 or comma)
<<+++++ +++++ +++
move to the pointed cell
tovaluecell()
tovalue(), read to it
fromvaluecell()
]>]
< case plus
[- kill the flag
restore the value (43 minus 31 or plus)
<<+++++ +++++ ++
tovaluecell()
tovalue()+ increase it
fromvaluecell()
]>]
>] next instruction
move instructions to where they've been initially and add 31 back
<<<<[+++++ +++++ +++++ +++++ +++++ +++++ + [>>>+<<<-]<]
< N