From: Ben Harris Date: Tue, 7 May 2024 21:26:37 +0000 (+0100) Subject: 07: slight cleanups though I'm still not happy X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=6a4e0db6f7676dfb4ac0363ef04f29ea60a3db71;p=aoc-2022.git 07: slight cleanups though I'm still not happy --- diff --git a/07/07a.bqn b/07/07a.bqn index f445839..98706c7 100644 --- a/07/07a.bqn +++ b/07/07a.bqn @@ -11,7 +11,7 @@ Prep←{ FS←{𝕤 cwd←⟨⟩ - nothing←⟨0,2⟩⥊⟨⟩ # 0 by 23 array, to return from "cd" + nothing←⟨0,2⟩⥊⟨⟩ # 0 by 2 array, to return from "cd" Exec⇐{ ⟨⟩𝕊⟨"cd", "/"⟩: cwd↩⟨⟩, nothing; ⟨⟩𝕊⟨"cd", ".."⟩: cwd ¯1⊸↓↩, nothing; @@ -23,13 +23,13 @@ FS←{𝕤 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} + [sizes,paths]←⍉⍷∾{(1↓𝕩)dev.Cmd(⊑𝕩)}¨𝕩 + isdir←"dir"⊸≡¨sizes + dirs ←isdir/paths + files←(¬isdir)/paths + sizes↩•ParseFloat¨(¬isdir)/sizes + files↩({"dir"≢⊑𝕩}˘files)/files + DirSize←{𝕊dir:+´({∨´dir⊸≡¨↑𝕩}¨files)/sizes} +´ {100000≥𝕩}⊸/ DirSize¨dirs } diff --git a/07/07b.bqn b/07/07b.bqn index 439c968..ec8cd4d 100644 --- a/07/07b.bqn +++ b/07/07b.bqn @@ -11,7 +11,7 @@ Prep←{ FS←{𝕤 cwd←⟨⟩ - nothing←⟨0,2⟩⥊⟨⟩ # 0 by 23 array, to return from "cd" + nothing←⟨0,2⟩⥊⟨⟩ # 0 by 2 array, to return from "cd" Exec⇐{ ⟨⟩𝕊⟨"cd", "/"⟩: cwd↩⟨⟩, nothing; ⟨⟩𝕊⟨"cd", ".."⟩: cwd ¯1⊸↓↩, nothing; @@ -23,13 +23,13 @@ FS←{𝕤 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} + [sizes,paths]←⍉⍷∾{(1↓𝕩)dev.Cmd(⊑𝕩)}¨𝕩 + isdir←"dir"⊸≡¨sizes + dirs ←isdir/paths + files←(¬isdir)/paths + sizes↩•ParseFloat¨(¬isdir)/sizes + files↩({"dir"≢⊑𝕩}˘files)/files + DirSize←{𝕊dir:+´({∨´dir⊸≡¨↑𝕩}¨files)/sizes} free←70000000-DirSize⟨⟩ need←30000000-free ⌊´{need≤𝕩}⊸/DirSize¨dirs