-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.wsf
44 lines (38 loc) · 915 Bytes
/
2.wsf
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
# Advent of Code 2019
# Day 2: 1202 Program Alarm
# https://adventofcode.com/2019/day/2
"@string" import
"@vm/intcode" import
call intcode.read_program jz .read_error
# Part 1
^ call intcode.init_program
^ 12 2 call intcode.set_inputs
^ call intcode.interpret
^2 retrieve printi '\n' printc
1slide call intcode.reset_program
# Part 2
0 # noun
.loop_noun:
99 ^1 j< .not_found
0 # verb
.loop_verb:
99 ^1 j< .loop_noun_continue
3dup call intcode.set_inputs
^2 call intcode.interpret
^2 retrieve 19690720 j= .found
1slide call intcode.reset_program
1+
jmp .loop_verb
.loop_noun_continue:
drop 1+
jmp .loop_noun
.found:
3drop swap
100* + printi '\n' printc
drop end
.not_found:
"?\n" prints 2drop end
# (x -- )
.read_error:
-1 "Error: invalid program format"
call string.println_neg_stack drop end