tvl-depot/users/sterni/exercises/aoc/2022/07/7.bqn
sterni 11abe4784c feat(sterni/aoc/2022): day07 BQN solution
Did not have the motivation to go back and improve things, so this is my
initial attempt.

Change-Id: I3e129523d8f6c03bfbe50351f78d56ec7254a2dc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7539
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Autosubmit: sterni <sternenseemann@systemli.org>
2022-12-07 19:17:34 +00:00

24 lines
999 B
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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