-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.wsf
43 lines (38 loc) · 1015 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
# Advent of Code 2021
# Day 2: Dive!
# https://adventofcode.com/2021/day/2
"@string" import
# 0 x
# 1 y (part 1), aim (part 2)
# 2 y (part 2)
# 3 read temp
# 4-15 command constants
# 16+ command
-1 "forwardownup" 4 call string.store_neg
3 ^ readi retrieve
.loop:
1-
^ jn .end
16 ' ' call string.read_until
3 ^ readi retrieve
16 ^2 4 7 call string.equals 1 j= .move_forward
16 ^2 10 4 call string.equals 1 j= .move_down
16 ^2 14 2 call string.equals 1 j= .move_up
drop
-1 "Invalid command: " call string.print_neg_stack
16 swap call string.println
drop end
.end:
drop
0 retrieve 1 retrieve * printi '\n' printc # x * aim
0 retrieve 2 retrieve * printi '\n' printc # x * y
end
.move_forward:
0 ^ retrieve ^2 + store # x += n
2 ^ retrieve 1 retrieve ^3 * + store # y += aim*n
2drop jmp .loop
.move_up:
neg # n *= -1
.move_down:
1 ^ retrieve ^2 + store # aim += n
2drop jmp .loop