From 11abe4784c81a421178f5ebcf7ddf96dffaa7a45 Mon Sep 17 00:00:00 2001 From: sterni Date: Wed, 7 Dec 2022 20:13:45 +0100 Subject: 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 Tested-by: BuildkiteCI Autosubmit: sterni --- users/sterni/exercises/aoc/2022/07/7.bqn | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 users/sterni/exercises/aoc/2022/07/7.bqn (limited to 'users') diff --git a/users/sterni/exercises/aoc/2022/07/7.bqn b/users/sterni/exercises/aoc/2022/07/7.bqn new file mode 100644 index 000000000000..2fc387f3406d --- /dev/null +++ b/users/sterni/exercises/aoc/2022/07/7.bqn @@ -0,0 +1,24 @@ +lib ← •Import "../../lib.bqn" +cmds ← 1↓ '$' ((+`= ⟜(⊑¨))⊔⊢) •FLines "input" +paths ← (<⟨⟩) { + 𝕨 𝕊 "$ ls": 𝕨; + 𝕨 𝕊 "$ cd /": ⟨⟩; + 𝕨 𝕊 "$ cd ..": (-1)↓𝕨; + 𝕨 𝕊 𝕩: 𝕨∾<5↓𝕩 # "$ cd …" +}` ⊑¨cmds +ParseLs ← { + dirs‿files ← 2↑((lib.IsAsciiNum∘⊑∘⊑)¨⊔⊢) ((<' ')⊸lib.SplitOn)¨ 1↓𝕩 + (1⊑¨dirs)⋈(lib.ReadDec 0⊸⊑)¨files +} +dirlists ← ParseLs⌾(1⊸⊑)¨⥊⋈˘(("$ cd"⊸≢⟜(4⊸↑)∘⊑¨)∘(1⊸⊏)˘/⊢) (⍒≠¨paths)⊏⍉paths≍cmds +DirSize ← {⊑𝕨 (⊑∘(1⊸⊑¨∘⊣⊐⊢)⊑⊣) <𝕩} +DirName ← ∾'/'⊸∾¨ +dirsizes ← ⊑¨ ⟨⟩ { + szs 𝕊 ⟨dir, subdirs‿files⟩: + Canon ← DirName dir⊸∾⟜⋈ + sz ← +´files∾szs⊸DirSize∘Canon¨ subdirs + szs∾