-
Notifications
You must be signed in to change notification settings - Fork 0
/
014.cbl
45 lines (37 loc) · 1.27 KB
/
014.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
IDENTIFICATION DIVISION.
PROGRAM-ID. Euler014.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 n PIC 9(7) COMP.
01 tmp PIC 9(18) COMP.
01 l PIC 9(3) COMP.
01 maxl PIC 9(3) COMP VALUE 0.
01 max PIC 9(6) COMP.
01 cache.
05 len PIC 9(3) VALUE 0 OCCURS 999999 TIMES.
01 out PIC Z(10).
PROCEDURE DIVISION.
PERFORM VARYING n FROM 1 BY 1 UNTIL n = 1000000
MOVE n TO tmp
MOVE 1 TO l
PERFORM UNTIL tmp = 1
IF FUNCTION MOD (tmp, 2) = 0
DIVIDE tmp BY 2 GIVING tmp
ELSE
COMPUTE tmp = 3 * tmp + 1
END-IF
IF tmp < 1000000 AND len(tmp) > 0
ADD len(tmp) to l
EXIT PERFORM
END-IF
ADD 1 to l
END-PERFORM
MOVE l to len(n)
IF l > maxl
MOVE n TO max
MOVE l TO maxl
END-IF
END-PERFORM
MOVE max TO out
DISPLAY FUNCTION TRIM (out)
STOP RUN.