-
Notifications
You must be signed in to change notification settings - Fork 0
/
day09.mod
40 lines (37 loc) · 801 Bytes
/
day09.mod
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
MODULE Day09;
(*
Day #09 : nothing special
*)
FROM Texts IMPORT TEXT, ReadChar, OpenText, CloseText;
VAR input : TEXT;
score, removed : CARDINAL;
c : CHAR;
PROCEDURE readGarbage;
BEGIN
ReadChar(input,c);
WHILE c<>'>' DO
IF c='!' THEN ReadChar(input,c) ELSE INC(removed) END;
ReadChar(input,c);
END
END readGarbage;
PROCEDURE readGroup(level : CARDINAL);
BEGIN
ReadChar(input,c);
WHILE c<>'}' DO
CASE c OF
| '{' : readGroup(level+1)
| '<' : readGarbage
END;
ReadChar(input,c)
END;
INC(score,level)
END readGroup;
EXCEPTION FileNotFound;
BEGIN
score := 0; removed := 0;
IF NOT OpenText(input,"DAY09.IN") THEN RAISE FileNotFound END;
ReadChar(input,c);
readGroup(1);
WRITELN('score : ',score);
WRITELN('removed : ',removed);
END Day09.