chiark / gitweb /
07b done (also slight readability improvement in 07a
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 7 May 2024 20:27:47 +0000 (21:27 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 7 May 2024 20:27:47 +0000 (21:27 +0100)
07/07a.bqn
07/07b.bqn [new file with mode: 0644]

index c0489255679d7994aa89aa34218a7c25a796c02b..f445839c17c82e86e5b8727e6fea1769555f48c1 100644 (file)
@@ -30,7 +30,7 @@ Main←{
   [sizes,filepaths]←⍉files
   sizes •ParseFloat¨↩
   DirSize←{𝕊dir:+´({∨´dir⊸≡¨↑𝕩}¨filepaths)/sizes}
-  +´ 100000⊸≥⊸/ DirSize¨dirs
+  +´ {100000≥𝕩}⊸/ DirSize¨dirs
 }
 
 •Show Main Prep •file.Lines ⊑•args
diff --git a/07/07b.bqn b/07/07b.bqn
new file mode 100644 (file)
index 0000000..439c968
--- /dev/null
@@ -0,0 +1,38 @@
+Split←{
+  blocknums ← +`𝕨
+  # Set entries in blocknums to -1 when they correspond with delimiters.
+  blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums
+  blocknums⊔𝕩
+}
+
+Prep←{
+  1↓(+`{"$ "≡2↑𝕩}¨𝕩)⊔𝕩
+}
+
+FS←{𝕤
+  cwd←⟨⟩
+  nothing←⟨0,2⟩⥊⟨⟩ # 0 by 23 array, to return from "cd"
+  Exec⇐{
+    ⟨⟩𝕊⟨"cd", "/"⟩:  cwd↩⟨⟩,       nothing;
+    ⟨⟩𝕊⟨"cd", ".."⟩: cwd ¯1⊸↓↩,    nothing;
+    ⟨⟩𝕊⟨"cd", dir⟩:  cwd ∾⟜⟨dir⟩↩, nothing;
+    input𝕊⟨"ls"⟩: >{𝕊⟨size,name⟩:⟨size,cwd∾⟨name⟩⟩}∘{(' '=𝕩)Split𝕩}¨input
+  }
+  Cmd⇐{𝕨 Exec 1↓(' '=𝕩)Split𝕩}
+}
+
+Main←{
+  dev←FS @
+  files←∾{(1↓𝕩)dev.Cmd(⊑𝕩)}¨𝕩
+  dirs ←⍷({"dir"≡⊑𝕩}˘files)/files
+  dirs ↩¯1⊏⍉dirs
+  files↩⍷({"dir"≢⊑𝕩}˘files)/files
+  [sizes,filepaths]←⍉files
+  sizes •ParseFloat¨↩
+  DirSize←{𝕊dir:+´({∨´dir⊸≡¨↑𝕩}¨filepaths)/sizes}
+  free←70000000-DirSize⟨⟩
+  need←30000000-free
+  ⌊´{need≤𝕩}⊸/DirSize¨dirs
+}
+
+•Show Main Prep •file.Lines ⊑•args