-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAOC1b.cbl
126 lines (117 loc) · 4.07 KB
/
AOC1b.cbl
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
identification division.
program-id. AOC1b.
author. COBOL-Erik.
environment division.
input-output section.
file-control.
select input-file-1
assign to 'C:\WS\AOC2021\AOC1.txt'
organization is line sequential.
select input-file-2
assign to 'C:\WS\AOC2021\AOC1.txt'
organization is line sequential.
select input-file-3
assign to 'C:\WS\AOC2021\AOC1.txt'
organization is line sequential.
configuration section.
data division.
file section.
fd input-file-1
block 0 records
label records omitted
data record is input-record-1.
01 input-record-1.
05 cur-num-1 pic X(4).
fd input-file-2
block 0 records
label records omitted
data record is input-record-2.
01 input-record-2.
05 cur-num-2 pic X(4).
fd input-file-3
block 0 records
label records omitted
data record is input-record-3.
01 input-record-3.
05 cur-num-3 pic X(4).
working-storage section.
77 a-dummy pic X.
77 a-work-num pic S9(4) comp-4.
77 a-prev-num pic S9(4) comp-4 value zero.
77 a-inc pic S9(4) comp-4 value -1. *> To offset first comp.
01 work-slide-sums.
05 ssum1 pic S9(4) comp-4 value zero.
05 ssum2 pic S9(4) comp-4 value zero.
05 ssum3 pic S9(4) comp-4 value zero.
01 done-slide-sums.
05 dsum1 pic S9(4) comp-4 value zero.
05 dsum2 pic S9(4) comp-4 value zero.
05 dsum3 pic S9(4) comp-4 value zero.
01 indexes.
05 ix1 pic S9(2) comp-4 value zero.
05 ix2 pic S9(2) comp-4 value zero.
05 ix3 pic S9(2) comp-4 value zero.
01 file-eof pic X(4) value 'on'.
88 eof-in value 'EOFi'.
procedure division.
open input input-file-1 input-file-2 input-file-3
read input-file-1 at end set eof-in to true end-read
read input-file-2 at end set eof-in to true end-read
read input-file-2 at end set eof-in to true end-read
read input-file-3 at end set eof-in to true end-read
read input-file-3 at end set eof-in to true end-read
read input-file-3 at end set eof-in to true end-read
perform until eof-in
perform advance-1
perform advance-2
perform advance-3
end-perform
display a-inc
close input-file-1
close input-file-2
close input-file-3
accept a-dummy *> To keep the console open
goback
.
advance-1 section.
compute a-work-num = function numval(cur-num-1)
add a-work-num to ssum1
add 1 to ix1
if ix1 = 3
move zero to ix1
move ssum1 to dsum1
if dsum1 > dsum3
add 1 to a-inc
end-if
move zero to ssum1
end-if
read input-file-1 at end set eof-in to true end-read
.
advance-2 section.
compute a-work-num = function numval(cur-num-2)
add a-work-num to ssum2
add 1 to ix2
if ix2 = 3
move zero to ix2
move ssum2 to dsum2
if dsum2 > dsum1
add 1 to a-inc
end-if
move zero to ssum2
end-if
read input-file-2 at end set eof-in to true end-read
.
advance-3 section.
compute a-work-num = function numval(cur-num-3)
add a-work-num to ssum3
add 1 to ix3
if ix3 = 3
move zero to ix3
move ssum3 to dsum3
if dsum3 > dsum2
add 1 to a-inc
end-if
move zero to ssum3
end-if
read input-file-3 at end set eof-in to true end-read
.