diff --git a/src/aoc24.org b/src/aoc24.org index e68f7b8..2ee006f 100644 --- a/src/aoc24.org +++ b/src/aoc24.org @@ -119,15 +119,14 @@ to get more context. These definitions and imports are shared by the various puz #+begin_src bqn :tangle ./bqn/aoc24.bqn VI ← { - hinp ← (↕∘≢•HashMap○⥊⊢) inp ← >•Flines Input𝕩 + hm ← (↕∘≢•HashMap○⥊⊢) inp ← >•Flines Input𝕩 g ← ⊑/○⥊⟜(↕≢)'^'= inp ⋄ r ← ⟨¯1, 0⟩‿⟨0, 1⟩‿⟨1, 0⟩‿⟨0, ¯1⟩ Sym ← {𝕊m: s ← •HashMap˜⟨⟩ (s.Keys@) ⋈ s.Has {𝕊p‿d: s.Set˜p‿d ⋄ '#'=◶{𝕊:d⋈˜p+d⊑r}‿{𝕊:p⋈4|d+1} m.Get⎊@ p+d⊑r }•_while_{𝕊𝕩: (m.Has⊑𝕩) ∧ ¬s.Has𝕩} g‿0 } - eins‿zwei ⇐ (≠⋈·+´{nm ← (hinp.Keys@) •HashMap hinp.Values@ - 𝕩nm.Set '#' ⋄ ⊢´Sym nm }¨) ⍷⊏⍉>⊑Sym hinp + eins‿zwei ⇐ (≠⋈·+´{𝕩hm.Set'#' ⋄ (𝕩hm.Set'.')⊢⊢´Sym hm}¨) ⍷⊏⍉>⊑Sym hm } VI _is 6 #+end_src @@ -139,10 +138,10 @@ to get more context. These definitions and imports are shared by the various puz #+begin_src bqn :tangle ./bqn/aoc24.bqn VII ← { - inp ← (⋈○(•ParseFloat¨' '⊸Split)´':'⊸Split)¨•FLines Input𝕩 + inp ← (⊑⊸⋈○(•ParseFloat¨' '⊸Split)´':'⊸Split)¨•FLines Input𝕩 C ← ⊢+⊣×10⊸⋆⟜(⌊1+10⋆⁼1⌈|) - eins ⇐ +´{⊑𝕨∊(+∾×)´⌽𝕩?⊑𝕨;0}´¨ inp - zwei ⇐ +´{⊑𝕨∊(C˜∾+∾×)´⌽𝕩?⊑𝕨;0}´¨ inp + eins ⇐ +´{⊑𝕨∊(+∾×)´⌽𝕩?𝕨;0}´¨ inp + zwei ⇐ +´{⊑𝕨∊(C˜∾+∾×)´⌽𝕩?𝕨;0}´¨ inp } VII _is 7 #+end_src @@ -150,6 +149,21 @@ to get more context. These definitions and imports are shared by the various puz #+RESULTS: : ⟨ 6231007345478 333027885676693 ⟩ +** VIII + +#+begin_src bqn :tangle ./bqn/aoc24.bqn + VIII ← { + n ← ≠⊑inp‿ant ← (⊢⋈1↓⍷∘⥊)>•FLines Input𝕩 + +´(∧´≥⟜0∧<⟜n)¨⍷∾{ + (⍷∘∾⊢/○⥊˜·<⌜˜↕∘≠)(⊣-˜2⊸×){𝔽´¨⌽⊸⋈𝕩‿𝕨}⌜˜/○⥊⟜(↕≢)𝕩 + }¨ant= ⊑∘∞ diff --git a/src/bqn/aoc24.bqn b/src/bqn/aoc24.bqn index 48d3836..cc952c3 100644 --- a/src/bqn/aoc24.bqn +++ b/src/bqn/aoc24.bqn @@ -47,22 +47,29 @@ V ← { V _is 5 VI ← { - hinp ← (↕∘≢•HashMap○⥊⊢) inp ← >•Flines Input𝕩 + hm ← (↕∘≢•HashMap○⥊⊢) inp ← >•Flines Input𝕩 g ← ⊑/○⥊⟜(↕≢)'^'= inp ⋄ r ← ⟨¯1, 0⟩‿⟨0, 1⟩‿⟨1, 0⟩‿⟨0, ¯1⟩ Sym ← {𝕊m: s ← •HashMap˜⟨⟩ (s.Keys@) ⋈ s.Has {𝕊p‿d: s.Set˜p‿d ⋄ '#'=◶{𝕊:d⋈˜p+d⊑r}‿{𝕊:p⋈4|d+1} m.Get⎊@ p+d⊑r }•_while_{𝕊𝕩: (m.Has⊑𝕩) ∧ ¬s.Has𝕩} g‿0 } - eins‿zwei ⇐ (≠⋈·+´{nm ← (hinp.Keys@) •HashMap hinp.Values@ - 𝕩nm.Set '#' ⋄ ⊢´Sym nm }¨) ⍷⊏⍉>⊑Sym hinp + eins‿zwei ⇐ (≠⋈·+´{𝕩hm.Set'#' ⋄ (𝕩hm.Set'.')⊢⊢´Sym hm}¨) ⍷⊏⍉>⊑Sym hm } VI _is 6 VII ← { - inp ← (⋈○(•ParseFloat¨' '⊸Split)´':'⊸Split)¨•FLines Input𝕩 + inp ← (⊑⊸⋈○(•ParseFloat¨' '⊸Split)´':'⊸Split)¨•FLines Input𝕩 C ← ⊢+⊣×10⊸⋆⟜(⌊1+10⋆⁼1⌈|) - eins ⇐ +´{⊑𝕨∊(+∾×)´⌽𝕩?⊑𝕨;0}´¨ inp - zwei ⇐ +´{⊑𝕨∊(C˜∾+∾×)´⌽𝕩?⊑𝕨;0}´¨ inp + eins ⇐ +´{⊑𝕨∊(+∾×)´⌽𝕩?𝕨;0}´¨ inp + zwei ⇐ +´{⊑𝕨∊(C˜∾+∾×)´⌽𝕩?𝕨;0}´¨ inp } VII _is 7 + +VIII ← { + n ← ≠⊑inp‿ant ← (⊢⋈1↓⍷∘⥊)>•FLines Input𝕩 + +´(∧´≥⟜0∧<⟜n)¨⍷∾{ + (⍷∘∾⊢/○⥊˜·<⌜˜↕∘≠)(⊣-˜2⊸×){𝔽´¨⌽⊸⋈𝕩‿𝕨}⌜˜/○⥊⟜(↕≢)𝕩 + }¨ant=