From: Ben Harris Date: Tue, 21 May 2024 19:10:31 +0000 (+0200) Subject: 16b done X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=b2d7a4ac5106cc7d530458633313f99babc8e47e;p=aoc-2022.git 16b done A little light memoization did the trick (but 27s CPU time!) --- diff --git a/16/16b.bqn b/16/16b.bqn new file mode 100644 index 0000000..5e2b566 --- /dev/null +++ b/16/16b.bqn @@ -0,0 +1,59 @@ +Prep←{ + name⇐2↑6↓𝕩 + flow⇐•ParseFloat(𝕩∊"0123456789")/𝕩 + tunnels⇐⟨∘,2⟩⥊3↓(𝕩∊('A'+↕(1+'Z'-'A')))/𝕩 +} + +Mem←{𝕊 f: + cache←⟨⟩•HashMap⟨⟩ + { + cache.Has 𝕩 ? cache.Get 𝕩; + result ← F 𝕩 + 𝕩 cache.Set result + result + } +} + +Main←{ + names←{𝕩.name}¨𝕩 + flows←{𝕩.flow}¨𝕩 + tunnelses←{names⊐⥊⋈˘𝕩.tunnels}¨𝕩 + tunnels←{⊑𝕨∊𝕩⊑tunnelses}⌜˜↕≠𝕩 + paths←{𝕩(⊢⌊⊏˘+⌜⊏)´↕≠𝕩}(tunnels⊏⟨∞,1⟩) # Stolen from BQNcrate + paths 0¨⌾(⋈˜¨∘↕∘≠⊸⊑) ↩ # Every valve zero distance from itself + paths +↩1 # Add in time to open destination valve + paths + aa←⊑names⊐<"AA" + nonzero←0