-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday19_tests.tal
399 lines (356 loc) · 9.74 KB
/
day19_tests.tal
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
~library/macros.tal
~library/devices.tal
( variables )
|0000
|0100 @program
T< "parse-scanner: >T
S< "--- 20 "scanner 20 "0 20 "--- 0a
"-1,-1,1 0a
"-2,-2,2 0a
"-3,-3,3 0a
"-2,-3,1 0a
"5,6,-4 0a
"8,0,7 0a
0a >S ;test-scanner-parse JSR2
( EXPECT 6 beacons found )
( EXPECT [-3 -3 3] )
( EXPECT [-2 -3 1] )
( EXPECT [-2 -2 2] )
( EXPECT [-1 -1 1] )
( EXPECT [5 6 -4] )
( EXPECT [8 0 7] )
T< "parse-scanner-eof: >T
S< >S ;test-scanner-parse JSR2
( EXPECT 0 beacons found )
T< "parse-scanners: >T
S< "--- 20 "scanner 20 "0 20 "--- 0a
"-1,-1,1 0a
"-2,-2,2 0a
0a
"--- 20 "scanner 20 "1 20 "--- 0a
"4,5,6 0a
"7,8,9 0a
0a >S ;test-scanners-parse JSR2
( EXPECT 2 scanners found )
( EXPECT 0: )
( EXPECT [-2 -2 2] )
( EXPECT [-1 -1 1] )
( EXPECT 1: )
( EXPECT [4 5 6] )
( EXPECT [7 8 9] )
T< "vector3-equal >T
S< 0101 0102 0103 >S S< 0101 0102 0103 >S ;vector3/equal JSR2 DBGBYTE POP ( EXPECT 0x01 )
S< 0101 0102 0103 >S S< 0101 0102 0104 >S ;vector3/equal JSR2 DBGBYTE POP ( EXPECT 0x00 )
T< "vector3-lessthan >T
S< 0101 0102 0103 >S S< 0201 0202 0203 >S ;test-vector3-lessthan JSR2
( EXPECT [257 258 259] < [513 514 515] )
( EXPECT [513 514 515] ≥ [257 258 259] )
T< "vector3-add >T
S< 8080 8080 8080 >S DUP2 S< 0101 0201 0301 >S S< fffe ffff ffff >S ;vector3/add JSR2 ;vector3/print JSR2 LF
( EXPECT [255 512 768] )
T< "vector3-subtract >T
S< ffff ffff ffff >S DUP2 S< 0102 0103 0104 >S S< 0101 0102 0103 >S ;vector3/subtract JSR2 ;vector3/print JSR2 LF
( EXPECT [1 1 1] )
T< "vector3-manhattan >T
S< 0101 0102 0103 >S S< 0201 0202 0203 >S ;vector3/manhattan JSR2 DBGSHORTDEC POP2
( EXPECT 768 )
S< 0101 0102 0103 >S S< 0101 0202 0203 >S ;test-vector3-lessthan JSR2
( EXPECT [257 258 259] < [257 514 515] )
( EXPECT [257 514 515] ≥ [257 258 259] )
S< 0101 0102 0103 >S S< 0101 0102 0203 >S ;test-vector3-lessthan JSR2
( EXPECT [257 258 259] < [257 258 515] )
( EXPECT [257 258 515] ≥ [257 258 259] )
S< 0101 0102 0103 >S S< 0101 0102 0103 >S ;test-vector3-lessthan JSR2
( EXPECT [257 258 259] ≥ [257 258 259] )
( EXPECT [257 258 259] ≥ [257 258 259] )
S< ffff ffff ffff >S S< 0101 0102 0103 >S ;test-vector3-lessthan JSR2
( EXPECT [-1 -1 -1] < [257 258 259] )
( EXPECT [257 258 259] ≥ [-1 -1 -1] )
T< "beacon-insert-empty-list: >T
S< 8080 ffff ffff ffff >S DUP2 S< 0101 0102 0103 >S ;scanner/insert JSR2 ;scanner/dump JSR2
( EXPECT [257 258 259] )
T< "beacon-insert-at-end: >T
S< 0101 0102 0103 8080 ffff ffff ffff >S DUP2 S< 0101 0102 0104 >S ;scanner/insert JSR2 ;scanner/dump JSR2
( EXPECT [257 258 259] )
( EXPECT [257 258 260] )
T< "beacon-insert-at-start: >T
S< 0101 0102 0103 0101 0102 0104 8080 ffff ffff ffff >S DUP2 S< 0101 0102 0102 >S ;scanner/insert JSR2 ;scanner/dump JSR2
( EXPECT [257 258 258] )
( EXPECT [257 258 259] )
( EXPECT [257 258 260] )
T< "beacon-insert-middle: >T
S< 0101 0102 0102 0101 0102 0104 8080 ffff ffff ffff >S DUP2 S< 0101 0102 0103 >S ;scanner/insert JSR2 ;scanner/dump JSR2
( EXPECT [257 258 258] )
( EXPECT [257 258 259] )
( EXPECT [257 258 260] )
T< "beacon-insert-skipdups: >T
S< 0101 0102 0103 8080 ffff ffff ffff >S DUP2 S< 0101 0102 0103 >S ;scanner/insert JSR2 ;scanner/dump JSR2
( EXPECT [257 258 259] )
T< "+y+z+x >T
S< 8080 8080 8080 >S DUP2 S< 0101 0102 0103 >S ;rotations/+Y+Z+X JSR2 ;vector3/print JSR2 LF
( EXPECT [258 259 257] )
T< "+x-y-z >T
S< 8080 8080 8080 >S DUP2 S< 0101 0102 0103 >S ;rotations/+X-Y-Z JSR2 ;vector3/print JSR2 LF
( EXPECT [257 -258 -259] )
T< "rotation-get: >T
S< 8080 8080 8080 >S DUP2 S< 0101 0102 0103 >S #0017 ;rotations/get JSR2 JSR2 ;vector3/print JSR2 LF
( EXPECT [-259 -258 -257] )
T< "scanner-rotate: >T
;&sctmp S< 0101 0102 0103 0101 0102 0104 8080 >S #0017 ( -Z-Y-X ) ;scanner/rotate JSR2
;&sctmp ;scanner/dump JSR2
( EXPECT [-260 -258 -257] )
( EXPECT [-259 -258 -257] )
T< "scanner-translate: >T
;&sctmp S< 0101 0102 0103 0101 0102 0104 8080 >S S< ff01 ff01 ff01 >S ;scanner/translate JSR2
;&sctmp ;scanner/dump JSR2
( EXPECT [2 3 4] )
( EXPECT [2 3 5] )
T< "scanner-copy >T
;&sctmp S< 0101 0102 0103 0101 0102 0104 8080 >S ;scanner/copy JSR2
;&sctmp ;scanner/dump JSR2
( EXPECT [257 258 259] )
( EXPECT [257 258 260] )
T< "scanner-count-matches: >T
S< "-0- 0a
"-1,-1,1 0a
"-1,30,2 0a
"-1,-1,2 0a
"-7,8,2 0a >S
S< "-1- 0a
"0,0,0 0a
"-1,-1,1 0a
"-1,-1,2 0a
"-1,30,2 0a
"5,-1,2 0a
"-5,-1,40 0a
"-2,-2,2 0a >S ;test-scanner-count-matches JSR2
( EXPECT 3 matches found )
T< "scanner-find-alignment: >T
S< "-0- 0a
"-1,-1,1 0a
"-1,30,2 0a
"-1,-1,2 0a
"-7,8,2 0a >S
S< "-1- 0a
"10,9,8 0a
"9,8,9 0a
"9,8,10 0a
"9,39,10 0a
"15,8,10 0a
"5,8,48 0a
"8,7,10 0a
>S #0002 ;test-scanner-find-alignment JSR2
( EXPECT 0x01 )
( EXPECT [-10 -9 -8] )
(
nT< "scanners-find-matches >T
;day19sample ;make-get-byte JSR2 ;scanners/parse JSR2
[ ;scanners/count LDA2 ] DBGSHORTDECn P< 20 "scanners 20 "found >P LF POP2
#0000 ;scanners/find-matches JSR2
)
T< "🎄 >T
BRK !
[ &sctmp $100 ]
( v1* v2* -- )
@test-vector3-lessthan
DUP4 ,&test-compare JSR
SWP2 ,&test-compare JSR
RTN
( v1* v2* -- )
&test-compare
DUP4 ;vector3/less-than JSR2 STH
SWP2 ;vector3/print JSR2 SP
STHr ;&print-comparison JSR2 SP
;vector3/print JSR2 LF
RTN
( <? )
&print-comparison
,&is-less JCN
P< "≥ >P
RTN
&is-less
LIT '< EMIT
RTN
( s* -- )
@test-scanner-parse
;make-get-byte JSR2 ;&sc1 ;scanner/parse JSR2
DBGBYTEDECn P< 20 "beacons 20 "found >P LF
#00 EQU ,¬-parsed JCN
;&sc1 ;scanner/dump JSR2
¬-parsed
RTN
[ &sc1 $a0 ]
( s* -- )
@test-scanners-parse
;make-get-byte JSR2 ;scanners/parse JSR2
[ ;scanners/count LDA2 ] DBGSHORTDECn P< 20 "scanners 20 "found >P LF POP2
;scanners/dump JSR2
RTN
( s1* s2* -- )
@test-scanner-count-matches
;make-get-byte JSR2 ;&sc1 ;scanner/parse JSR2 POP
;make-get-byte JSR2 ;&sc2 ;scanner/parse JSR2 POP
;&sc1 ;&sc2 ;scanner/count-matches JSR2
DBGSHORTDECn POP2 P< 20 "matches 20 "found >P LF
RTN
[ &sc1 $100 &sc2 $100 ]
( s1* s2* count -- )
@test-scanner-find-alignment
STH2
;make-get-byte JSR2 ;&sc2 ;scanner/parse JSR2 POP
;make-get-byte JSR2 ;&sc1 ;scanner/parse JSR2 POP
;&sc1 ;&sc2 STH2r ;scanner/find-alignment JSR2 DBGBYTE POP
;scanner/find-alignment/offset ;vector3/print JSR2 LF
RTN
[ &sc1 $100 &sc2 $100 ]
( s* -- get-byte )
@make-get-byte
;input STA2
;get-byte-from-input
RTN
( -- b )
@get-byte-from-input
[ ;input LDA2 ] LDA STH
[ ;input LDA2 ] INC2 [ ;input STA2 ]
STHr
RTN
@input $2
@day19sample
"--- 20 "scanner 20 "0 20 "--- 0a
"404,-588,-901 0a
"528,-643,409 0a
"-838,591,734 0a
"390,-675,-793 0a
"-537,-823,-458 0a
"-485,-357,347 0a
"-345,-311,381 0a
"-661,-816,-575 0a
"-876,649,763 0a
"-618,-824,-621 0a
"553,345,-567 0a
"474,580,667 0a
"-447,-329,318 0a
"-584,868,-557 0a
"544,-627,-890 0a
"564,392,-477 0a
"455,729,728 0a
"-892,524,684 0a
"-689,845,-530 0a
"423,-701,434 0a
"7,-33,-71 0a
"630,319,-379 0a
"443,580,662 0a
"-789,900,-551 0a
"459,-707,401 0a
" 0a
"--- 20 "scanner 20 "1 20 "--- 0a
"686,422,578 0a
"605,423,415 0a
"515,917,-361 0a
"-336,658,858 0a
"95,138,22 0a
"-476,619,847 0a
"-340,-569,-846 0a
"567,-361,727 0a
"-460,603,-452 0a
"669,-402,600 0a
"729,430,532 0a
"-500,-761,534 0a
"-322,571,750 0a
"-466,-666,-811 0a
"-429,-592,574 0a
"-355,545,-477 0a
"703,-491,-529 0a
"-328,-685,520 0a
"413,935,-424 0a
"-391,539,-444 0a
"586,-435,557 0a
"-364,-763,-893 0a
"807,-499,-711 0a
"755,-354,-619 0a
"553,889,-390 0a
" 0a
"--- 20 "scanner 20 "2 20 "--- 0a
"649,640,665 0a
"682,-795,504 0a
"-784,533,-524 0a
"-644,584,-595 0a
"-588,-843,648 0a
"-30,6,44 0a
"-674,560,763 0a
"500,723,-460 0a
"609,671,-379 0a
"-555,-800,653 0a
"-675,-892,-343 0a
"697,-426,-610 0a
"578,704,681 0a
"493,664,-388 0a
"-671,-858,530 0a
"-667,343,800 0a
"571,-461,-707 0a
"-138,-166,112 0a
"-889,563,-600 0a
"646,-828,498 0a
"640,759,510 0a
"-630,509,768 0a
"-681,-892,-333 0a
"673,-379,-804 0a
"-742,-814,-386 0a
"577,-820,562 0a
" 0a
"--- 20 "scanner 20 "3 20 "--- 0a
"-589,542,597 0a
"605,-692,669 0a
"-500,565,-823 0a
"-660,373,557 0a
"-458,-679,-417 0a
"-488,449,543 0a
"-626,468,-788 0a
"338,-750,-386 0a
"528,-832,-391 0a
"562,-778,733 0a
"-938,-730,414 0a
"543,643,-506 0a
"-524,371,-870 0a
"407,773,750 0a
"-104,29,83 0a
"378,-903,-323 0a
"-778,-728,485 0a
"426,699,580 0a
"-438,-605,-362 0a
"-469,-447,-387 0a
"509,732,623 0a
"647,635,-688 0a
"-868,-804,481 0a
"614,-800,639 0a
"595,780,-596 0a
" 0a
"--- 20 "scanner 20 "4 20 "--- 0a
"727,592,562 0a
"-293,-554,779 0a
"441,611,-461 0a
"-714,465,-776 0a
"-743,427,-804 0a
"-660,-479,-426 0a
"832,-632,460 0a
"927,-485,-438 0a
"408,393,-506 0a
"466,436,-512 0a
"110,16,151 0a
"-258,-428,682 0a
"-393,719,612 0a
"-211,-452,876 0a
"808,-476,-593 0a
"-575,615,604 0a
"-485,667,467 0a
"-680,325,-822 0a
"-627,-443,-432 0a
"872,-547,-609 0a
"833,512,582 0a
"807,604,487 0a
"839,-516,451 0a
"891,-625,532 0a
"-652,-548,-490 0a
"30,-46,-14 0a
~library/test.tal
~day19_lib.tal