From b7299093eda4cdc2df09cfa98dd55791a7577f48 Mon Sep 17 00:00:00 2001 From: Panadestein Date: Thu, 12 Dec 2024 23:56:03 +0100 Subject: [PATCH] feat: day 12 full. --- src/aoc24.org | 81 ++++++++++++++++++++++++++++++++--------------- src/bqn/aoc24.bqn | 27 +++++++++++++--- 2 files changed, 78 insertions(+), 30 deletions(-) diff --git a/src/aoc24.org b/src/aoc24.org index b0a02a9..2bb747f 100644 --- a/src/aoc24.org +++ b/src/aoc24.org @@ -30,7 +30,10 @@ to get more context. These definitions and imports are shared by the various puz #+begin_src bqn :tangle ./bqn/aoc24.bqn Split ← (¬-˜⊢×·+`»⊸>)∘≠⊔⊢ Input ← {"../supp/aoc/2024/"∾".inp"∾˜•Fmt𝕩} - _is ← {(𝔽𝕩).eins⋈(𝔽𝕩).zwei} + _is ← { + ∾⟨"Computed ", •Fmt(𝔽𝕩).eins, " and ", + •Fmt(𝔽𝕩).zwei, " in ", •Fmt 10𝔽•_timed𝕩, "s"⟩ + } #+end_src #+RESULTS: @@ -38,7 +41,7 @@ to get more context. These definitions and imports are shared by the various puz ** I -#+begin_src bqn :tangle ./bqn/aoc24.bqn +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both I ← { inp ← >(•ParseFloat¨' '⊸Split)¨•FLines Input𝕩 eins ⇐ +´|-´˘∧˘⌾⍉inp @@ -48,11 +51,11 @@ to get more context. These definitions and imports are shared by the various puz #+end_src #+RESULTS: -: ⟨ 2057374 23177084 ⟩ +: "Computed 2057374 and 23177084 in 0.0002433342s" ** II -#+begin_src bqn :tangle ./bqn/aoc24.bqn +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both II ← { inp ← (-´˘·2⊸↕·•ParseFloat¨' '⊸Split)¨•FLines Input𝕩 P‿Q ← ⟨3≥⌈´∘|, ≠=·|+´∘×⟩ @@ -64,11 +67,11 @@ to get more context. These definitions and imports are shared by the various puz #+end_src #+RESULTS: -: ⟨ 483 528 ⟩ +: "Computed 483 and 528 in 0.0006116174s" ** III -#+begin_src bqn :tangle ./bqn/aoc24.bqn +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both III ← { mem ← •FChars Input𝕩 prg ← mem/˜1=×∘+`2×-´"do()"‿"don't()"(≢∘⊢↑⍷)¨•FLines Input 𝕩 t‿ts ← ⟨"XMAS"‿"SAMX", "MSAMS"‿"SMASM"‿"SSAMM"‿"MMASS"⟩ @@ -98,11 +101,11 @@ to get more context. These definitions and imports are shared by the various puz #+end_src #+RESULTS: -: ⟨ 2397 1824 ⟩ +: "Computed 2397 and 1824 in 0.0044790454s" ** V -#+begin_src bqn :tangle ./bqn/aoc24.bqn +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both V ← { p‿r ← ",|" •ParseFloat⚇1∘(Split¨)¨ 1↓(∧`⊸+⟨⟩⊸≢¨)⊸⊔ •FLines Input𝕩 M ← (⍒∊⟜(>r)∘⋈⌜˜)¨⊏¨⊢ @@ -113,11 +116,11 @@ to get more context. These definitions and imports are shared by the various puz #+end_src #+RESULTS: -: ⟨ 6242 5169 ⟩ +: "Computed 6242 and 5169 in 0.2089791522s" ** VI -#+begin_src bqn :tangle ./bqn/aoc24.bqn +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both VI ← { hm ← (↕∘≢•HashMap○⥊⊢) inp ← >•Flines Input𝕩 g ← ⊑/○⥊⟜(↕≢)'^'= inp ⋄ r ← ⟨¯1, 0⟩‿⟨0, 1⟩‿⟨1, 0⟩‿⟨0, ¯1⟩ @@ -132,11 +135,11 @@ to get more context. These definitions and imports are shared by the various puz #+end_src #+RESULTS: -: ⟨ 5444 1946 ⟩ +: "Computed 5444 and 1946 in 11.5659486128s" ** VII -#+begin_src bqn :tangle ./bqn/aoc24.bqn +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both VII ← { inp ← (⊑⊸⋈○(•ParseFloat¨' '⊸Split)´':'⊸Split)¨•FLines Input𝕩 C ← ⊢+⊣×10⊸⋆⟜(⌊1+10⋆⁼1⌈|) @@ -147,26 +150,26 @@ to get more context. These definitions and imports are shared by the various puz #+end_src #+RESULTS: -: ⟨ 6231007345478 333027885676693 ⟩ +: "Computed 6231007345478 and 333027885676693 in 0.0148443502s" ** VIII -#+begin_src bqn :tangle ./bqn/aoc24.bqn +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both VIII ← { n ← ≠⊑inp‿ant ← (⊢⋈1↓⍷∘⥊)>•FLines Input𝕩 _tcd ← {(𝕨⊸×-(𝕨-1)×⊣)⌜˜⊸𝔽/○⥊⟜(↕≢)𝕩} - eins ⇐ ≠⍷(∧´≥⟜0∧<⟜n)⊸/∾ 2 (⥊∘⊣/˜·¬⥊⊸∊)_tcd¨ ant='0'-˜•FLines Input𝕩 I ← {(𝕨⊸=/○⥊⟜(↕≢)⊢)𝕩} @@ -201,20 +207,20 @@ to get more context. These definitions and imports are shared by the various puz } AMP ← { am ← (1=-⌜˜⥊𝕩)∧1=+´∘|∘-⌜˜⥊↕≢𝕩 - +´⥊ am +˝∘×⎉1‿∞˜⍟9 9=⥊𝕩 + +´⥊(0=⥊𝕩)/⌾⍉(9=⥊𝕩)/{𝕩𝕨⊸𝕊⍟≢𝕨+𝕨+˝∘×⎉1‿∞𝕩}˜am } eins ⇐ +´BFS¨ 0 I inp - zwei ⇐ (DP≡AMP)◶@‿DP inp + zwei ⇐ DP inp } X _is 10 #+end_src #+RESULTS: -: ⟨ 776 1657 ⟩ +: "Computed 776 and 1657 in 0.0073447794s" ** XI -#+begin_src bqn :tangle ./bqn/aoc24.bqn +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both XI ← { inp ← •ParseFloat¨' 'Split⊑•Flines Input𝕩 ⋄ m ← •HashMap˜⟨⟩ B ← { @@ -231,7 +237,30 @@ to get more context. These definitions and imports are shared by the various puz #+end_src #+RESULTS: -: ⟨ 199982 237149922829154 ⟩ +: "Computed 199982 and 237149922829154 in 0.0604116584s" + +** XII + +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both + XII ← { + n‿inp ← ≠⊸⋈>•FLines Input𝕩 + cf‿cn ← ⟨»˘, », «˘, «⟩‿⟨0‿¯1, ¯1‿0, 0‿1, 1‿0⟩ + nb‿pr ← (∾¨´⋈·+´¬) inp<⊸=nud ← cf{𝕎𝕩}¨ diff --git a/src/bqn/aoc24.bqn b/src/bqn/aoc24.bqn index 9ef0c90..d4409fa 100644 --- a/src/bqn/aoc24.bqn +++ b/src/bqn/aoc24.bqn @@ -1,6 +1,9 @@ Split ← (¬-˜⊢×·+`»⊸>)∘≠⊔⊢ Input ← {"../supp/aoc/2024/"∾".inp"∾˜•Fmt𝕩} -_is ← {(𝔽𝕩).eins⋈(𝔽𝕩).zwei} +_is ← { + ∾⟨"Computed ", •Fmt(𝔽𝕩).eins, " and ", + •Fmt(𝔽𝕩).zwei, " in ", •Fmt 10𝔽•_timed𝕩, "s"⟩ +} I ← { inp ← >(•ParseFloat¨' '⊸Split)¨•FLines Input𝕩 @@ -69,7 +72,7 @@ VII _is 7 VIII ← { n ← ≠⊑inp‿ant ← (⊢⋈1↓⍷∘⥊)>•FLines Input𝕩 _tcd ← {(𝕨⊸×-(𝕨-1)×⊣)⌜˜⊸𝔽/○⥊⟜(↕≢)𝕩} - eins ⇐ ≠⍷(∧´≥⟜0∧<⟜n)⊸/∾ 2 (⥊∘⊣/˜·¬⥊⊸∊)_tcd¨ ant=•FLines Input𝕩 + cf‿cn ← ⟨»˘, », «˘, «⟩‿⟨0‿¯1, ¯1‿0, 0‿1, 1‿0⟩ + nb‿pr ← (∾¨´⋈·+´¬) inp<⊸=nud ← cf{𝕎𝕩}¨