-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAOC07_1.f90
38 lines (30 loc) · 856 Bytes
/
AOC07_1.f90
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
program AOC07_1
use fs_mod
implicit none
integer(i8_k) :: totsize, tmp
call init('..\input.txt')
! call dump (root,0)
tmp = dirsize(root)
print *, totsize
contains
function dirsize (start) result (lclsize)
integer(i8_k) :: lclsize
type(fs_t), target, intent(in) :: start
type(fs_t), pointer :: curr
lclsize = 0
curr => start
curr => curr%next
do while (associated(curr))
if (.not. associated(curr%down)) then ! file
lclsize = lclsize + curr%fsize
else
lclsize = lclsize + dirsize(curr%down)
end if
curr => curr%next
end do
if (lclsize <= 100000) then
totsize = totsize + lclsize
write (*,*) start%fname, lclsize
end if
end function dirsize
end program AOC07_1