-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpart1.fth
60 lines (53 loc) · 1.05 KB
/
part1.fth
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
CREATE line-buf 128 ALLOT
VARIABLE line-idx
VARIABLE cnum
VARIABLE cidx
: READLN \ [4] -> continue
128 0 DO 0 line-buf I + c! LOOP
line-buf 128 STDIN READ-LINE THROW
DROP DROP
line-buf c@ 0 = IF
DROP
0
ELSE
0 line-idx !
0 cnum !
0 cidx !
BEGIN
line-buf line-idx @ + c@ 48 >=
line-buf line-idx @ + c@ 57 <=
AND IF
line-buf line-idx @ + c@ 48 - cnum @ 10 * + cnum !
ELSE
DUP cidx @ CELL * + cnum @ SWAP !
0 cnum !
cidx @ 1 + cidx !
THEN
line-idx @ 1 + line-idx !
line-buf line-idx @ + c@ 0 = UNTIL
cidx @ CELL * + cnum @ SWAP !
1
THEN
;
CREATE buf 4 CELLS ALLOT
VARIABLE num
: READLNS \ -> num
0 num !
BEGIN
buf READLN
buf 0 CELL * + @ buf 2 CELL * + @ <=
buf 1 CELL * + @ buf 3 CELL * + @ >=
AND OVER AND IF
num @ 1 + num !
ELSE
buf 0 CELL * + @ buf 2 CELL * + @ >=
buf 1 CELL * + @ buf 3 CELL * + @ <=
AND OVER AND IF
num @ 1 + num !
THEN THEN
0 = UNTIL
num @
;
READLNS CR .
CR
BYE