-
Notifications
You must be signed in to change notification settings - Fork 0
/
day19.mod
43 lines (35 loc) · 1015 Bytes
/
day19.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
41
42
MODULE Day19;
(*
Day #19: Luckily enough, the 40 KB map fits into memory...
*)
IMPORT Texts,Strings;
CONST Size = 201;
VAR map : ARRAY [1..Size] OF ARRAY [0..Size] OF CHAR;
path : Strings.String;
i, steps, pathSize : CARDINAL;
input : Texts.TEXT;
x, y, dx, dy, tmp : INTEGER;
EXCEPTION FileNotFound;
BEGIN
IF NOT Texts.OpenText(input,"DAY19.IN") THEN RAISE FileNotFound END;
FOR i:=1 TO Size DO Texts.ReadLine(input,map[i]) END;
Texts.CloseText(input);
y:=1; x:=0; WHILE map[y][x] <> '|' DO INC(x) END;
WRITELN('start from x=',x);
dx:=0; dy:=+1;
steps:=0; pathSize:=0;
WHILE map[y][x]#' ' DO
INC(steps);
IF map[y][x]='+' THEN
tmp := dx; dx := dy; dy := tmp;
IF map[y+dy][x+dx]=' ' THEN dx := -dx; dy := -dy END;
ELSIF (map[y][x]>='A') AND (map[y][x]<='Z') THEN
path[pathSize]:=map[y][x];
INC(pathSize)
END;
x := x + dx; y := y + dy;
END;
path[pathSize]:=0C;
WRITELN('Path : ',path);
WRITELN('Steps : ',steps);
END Day19.