read the data
subroutine initialize() !! read the data ! open(newunit=iunit, file='inputs/day22_test.txt', status='OLD') open(newunit=iunit, file='inputs/day22.txt', status='OLD') n_lines = number_of_lines_in_file(iunit) if (allocated(istart_array)) deallocate(istart_array); allocate(istart_array(n_lines,3)) if (allocated(iend_array)) deallocate(iend_array); allocate(iend_array(n_lines,3)) do i = 1, n_lines line = read_line(iunit); start_end = split(line, '~') starts = split(start_end(1)%str, ',') ends = split(start_end(2)%str, ',') istart_array(i,:) = [(int(starts(j)%str), j = 1, 3)] iend_array(i,:) = [(int(ends(j)%str), j = 1, 3)] end do close(iunit) ! create the array to hold all the pieces: if (allocated(array)) deallocate(array) allocate(array(0:maxval([istart_array(:,1), iend_array(:,1)]),& 0:maxval([istart_array(:,2), iend_array(:,2)]),& 0:maxval([istart_array(:,3), iend_array(:,3)]))) call update_array() ! set array values from the start/end arrays call drop() ! continue forward in time until all the bricks settle. end subroutine initialize