-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.wsf
41 lines (33 loc) · 905 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
# Advent of Code 2020
# Day 2: Password Philosophy
# https://adventofcode.com/2020/day/2
"@array" import
"@bool" import
"@int" import
"@math" import
"@string" import
2 ^ readi retrieve neg
.validate_loop:
2 '-' call int.read_until jz .read_error # x
2 ' ' call int.read_until jz .read_error # y
2 ^ readc retrieve # ch
2 ^ readc readc
2 call string.read_line # len
# Part 1 validity criterion
^3 ^3
2 ^3 ^5 call array.count # 2 len ch
call math.in_range # x <= count <= y
0 retrieve + 0 swap store
# Part 2 validity criterion
^3 1+ retrieve ^2 -
^3 1+ retrieve ^3 -
call bool.xor
1 retrieve + 1 swap store
4drop 1+
^ jn .validate_loop
0 retrieve printi '\n' printc
1 retrieve printi '\n' printc
end
.read_error:
-1 "Error: invalid int format"
call string.println_neg_stack end