identification division. program-id. "AoC 2021 Day 1". author. "Carl Svensson". environment division. configuration section. object-computer. GNU-COBOL-Compiler. input-output section. file-control. select fdat assign to "1.dat" organization is line sequential. data division. file section. fd fdat. 01 rec_in. 02 rec_depth pic 9(4). working-storage section. 01 depths-table. 02 depths pic 9(4) value 0 occurs 2000 indexed by i. 01 ans_a pic 9(4) value 0. 01 ans_b pic 9(4) value 0. 01 prev_depth pic 9(4) value 0. 01 cur_depth pic 9(4) value 0. 01 range1 pic 9(6) value 0. 01 range2 pic 9(6) value 0. 01 eof pic 9 value 0. 01 idx pic 9(4) value 0. procedure division. move 1 to i. open input fdat. perform until eof = 1 read fdat at end set eof to 1 not at end perform store_line_and_solve_a end-read end-perform. close fdat. perform solve_b. display "Task A: "ans_a. display "Task B: "ans_b. stop run. store_line_and_solve_a. * Solve task A. unstring rec_depth into cur_depth if prev_depth > 0 and cur_depth > prev_depth add 1 to ans_a end-if. move cur_depth to prev_depth. * Store number in table for task B. unstring cur_depth into depths(i). add 1 to i. solve_b. perform with test before varying i from 1 by 1 until i=2000 compute range1 = depths(i) + depths(i + 1) + depths(i + 2) compute range2 = depths(i + 1) + depths(i + 2) + depths(i + 3) if range2 > range1 then add 1 to ans_b end-if end-perform.