diff --git a/aoc.bqn b/aoc.bqn index 953e41d..b2769ab 100644 --- a/aoc.bqn +++ b/aoc.bqn @@ -33,6 +33,7 @@ aoc3 ⇐ { Gamma ← Most˘ ∘ ⍉ ∘ BitFile A ⇐ ¬⊸(×○FromBin) ∘ Gamma + B ⇐ {"nah"!0, 𝕩} } ################################################################################ @@ -74,8 +75,8 @@ aoc5 ⇐ { ################################################################################ aoc6 ⇐ { - FishFile ← /⁼∘CSVInt∘⊑∘•FLines - Step ← (⊑ × (/⁼6‿8)˙) +○(9⊸↑) « + FishFile ← 9⊸↑ /⁼ ∘ CSVInt ∘ ⊑ ∘ •FLines + Step ← (⊑ × (/⁼6‿8)˙) + « Fishies ← {+´ Step⍟𝕨 FishFile 𝕩} A ⇐ 80⊸Fishies, B ⇐ 256⊸Fishies } @@ -83,7 +84,7 @@ aoc6 ⇐ { ################################################################################ aoc7 ⇐ { - CrabFile ← CSVInt∘⊑∘•FLines + CrabFile ← CSVInt ∘ ⊑ ∘ •FLines Range ← {l + ↕(⌈´𝕩)¬(l←⌊´𝕩)} @@ -93,3 +94,48 @@ aoc7 ⇐ { _Go ← {⌊´ ps⊸𝔽¨ Range ps←CrabFile 𝕩} A ⇐ FuelA _Go, B ⇐ FuelB _Go } + +################################################################################ + +aoc8 ⇐ {A⇐B⇐{"maybe later"!0, 𝕩}} + +################################################################################ + +aoc9 ⇐ { + SmokeFile ← > -⟜'0' ∘ •FLines + Adj ← {<⎉1 ⍉ > ⟨∞«˘𝕩, ∞»˘𝕩, ∞«˘⌾⍉𝕩, ∞»˘⌾⍉𝕩⟩} + Lowest ← ∧´¨ <⟜Adj + Risk ← 1⊸+ × Lowest + A ⇐ +´⥊ ∘ Risk ∘ SmokeFile + B ⇐ {"nah"!0, 𝕩} +} + +################################################################################ + +Fst ⇐ {0 ≡ ≠𝕩? @; ⊑𝕩} +At ⇐ {1⊑ ⊑ (⊑ ≡ 𝕩˙)¨⊸/ 𝕨} # use ⎊ for default + +aoc10 ⇐ { + BadScore1 ← ⟨')'‿3,']'‿57,'}'‿1197,'>'‿25137⟩⊸At⎊0 + BadScore ← BadScore1 ∘ {'!'‿c: c; @} + + Step ← { + '!' ≡ Fst 𝕨? 𝕨; + 𝕨 𝕊 ')': '(' = Fst 𝕨? 1↓𝕨; + 𝕨 𝕊 ']': '[' = Fst 𝕨? 1↓𝕨; + 𝕨 𝕊 '}': '{' = Fst 𝕨? 1↓𝕨; + 𝕨 𝕊 '>': '<' = Fst 𝕨? 1↓𝕨; + ⊑ 𝕩∊"([{<"? 𝕩∾𝕨; + '!'‿𝕩 + } + Find ← ""⊸(Step˜´) ⌽ + + GoodScore1 ← ⟨'('‿1,'['‿2,'{'‿3,'<'‿4⟩⊸At + GoodScoreN ← {0 ((GoodScore1 ⊣) + (5⊸× ⊢))´ 𝕩} + GoodScore ← GoodScoreN ⌽ ∘ {'!' ≡ Fst 𝕩? ""; 𝕩} + + Middle ← ((⌊÷⟜2)∘≠ ⊑ ⊢) ∧ ∘ (0⊸≠¨⊸/) + + A ⇐ +´ (BadScore∘Find¨) ∘ •FLines + B ⇐ Middle (GoodScore∘Find¨) ∘ •FLines +}