diff options
Diffstat (limited to '')
-rw-r--r-- | 2022/day07.awk | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/2022/day07.awk b/2022/day07.awk new file mode 100644 index 0000000..4143a8b --- /dev/null +++ b/2022/day07.awk @@ -0,0 +1,27 @@ +function parent(dir) { + p = match(dir, "/[^/]+$"); + return substr(dir, 1, p-1); +} +/\$ cd \// { + cwd = "/"; + next; +} +/\$ cd \.\./ { + cwd = parent(cwd); + next; +} +/\$ cd/ { + cwd = cwd "/" $3; +} +/^[0-9]+/ { + for (dir = cwd; dir != ""; dir = parent(dir)) { + dirs[dir] += $1; + } +} +END { + for (dir in dirs) { + if (dirs[dir] > 100000) continue; + sum += dirs[dir]; + } + print sum; +} |