tvl-depot/users/sterni/exercises/aoc/2022/07/7.bqn

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
999 B
BQN
Raw Normal View History

lib •Import "../../lib.bqn"
cmds 1 '$' ((+`= (¨))) •FLines "input"
paths (<) {
𝕨 𝕊 "$ ls": 𝕨;
𝕨 𝕊 "$ cd /": ;
𝕨 𝕊 "$ cd ..": (-1)𝕨;
𝕨 𝕊 𝕩: 𝕨<5𝕩 # "$ cd …"
}` ¨cmds
ParseLs {
dirsfiles 2((lib.IsAsciiNum)¨) ((<' ')lib.SplitOn)¨ 1𝕩
(1¨dirs)(lib.ReadDec 0)¨files
}
dirlists ParseLs(1)¨˘(("$ cd"(4)¨)(1)˘/) (¨paths)pathscmds
DirSize {𝕨 ((1¨)) <𝕩}
DirName '/'¨
dirsizes ¨ {
szs 𝕊 dir, subdirsfiles:
Canon DirName dir
sz +´filesszsDirSizeCanon¨ subdirs
szs<szDirName dir
}˜´ dirlists
•Out "day07.1: "•Fmt +´ 100000 (/) dirsizes
•Out "day07.2: "•Fmt (30000000-70000000-´dirsizes) ´(/) dirsizes