-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday-1.dylan
45 lines (40 loc) · 987 Bytes
/
day-1.dylan
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
Module: day-1
Synopsis:
Author:
Copyright:
let file-stream = make(<file-stream>, locator: "list.txt");
let first-time = #t;
let previous-int = 0;
let num-increased = 0;
while (~stream-at-end?(file-stream))
let line = read-line(file-stream);
let int = string-to-integer(line);
if (first-time)
first-time := #f;
elseif (previous-int < int)
num-increased := num-increased + 1;
end;
previous-int := int;
end;
format-out("%=\n", num-increased);
file-stream := make(<file-stream>, locator: "list.txt");
let times = 0;
let int1 = 0;
let int2 = 0;
let int3 = 0;
let previous-sum = 0;
num-increased := 0;
while (~stream-at-end?(file-stream))
int3 := int2;
int2 := int1;
let line = read-line(file-stream);
int1 := string-to-integer(line);
let cur-sum = int1 + int2 + int3;
if (times < 3)
times := times + 1;
elseif (previous-sum < cur-sum)
num-increased := num-increased + 1;
end;
previous-sum := cur-sum;
end;
format-out("%=\n", num-increased);