From e1849f11aab8aa4f466b40e04c82c3e6fffdabdd Mon Sep 17 00:00:00 2001 From: Panadestein Date: Sun, 15 Dec 2024 01:12:37 +0100 Subject: [PATCH] feat: added slow day 14. --- src/aoc24.org | 22 +++++++++++++++++----- src/bqn/aoc24.bqn | 15 +++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/aoc24.org b/src/aoc24.org index 50ceecc..960ee32 100644 --- a/src/aoc24.org +++ b/src/aoc24.org @@ -29,6 +29,8 @@ to get more context. These definitions and imports are shared by the various puz #+begin_src bqn :tangle ./bqn/aoc24.bqn Split ← (¬-˜⊢×·+`»⊸>)∘≠⊔⊢ + Ints ← {•ParseFloat¨((¯1+⊢×·+`»⊸<)𝕩∊'0'+↕10)⊔𝕩} + SInts ← {•ParseFloat¨((¯1+⊢×·+`»⊸<)𝕩∊'-'∾'0'+↕10)⊔𝕩} Input ← {"../supp/aoc/2024/"∾".inp"∾˜•Fmt𝕩} _is ← { ∾⟨"Computed ", •Fmt(𝔽𝕩).eins, " and ", @@ -285,10 +287,7 @@ powers of the adjacency matrix. This method is unfortunately slower than simple #+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both XIII ← { - inp ← {𝕊p‿q‿pq: - e ← ∾{∾•Parsefloat⎊⟨⟩¨∾'+'Split¨','Split𝕩}¨ p‿q - 3‿2⥊e∾∾•Parsefloat⎊⟨⟩¨∾'='Split¨','Split pq - }˘∘‿3⥊⟨⟩⊸≢¨⊸/•FLines Input 𝕩 + ∘‿3‿2⥊∾Ints¨⟨⟩⊸≢¨⊸/•FLines Input 𝕩 C ← (-´×⟜⌽˝){𝕨𝔽_𝕣[a,b,c]: (𝔽÷˜(𝕨+c)⌾⊏⋈○𝔽(𝕨+c)⌾(⊏⌽))a≍b} eins‿zwei ⇐ {+´⥊3‿1×⎉1(∧´⌊⊸=)˘⊸/𝕩⊸C˘inp}¨ 0‿1e13 } @@ -296,7 +295,20 @@ powers of the adjacency matrix. This method is unfortunately slower than simple #+end_src #+RESULTS: -: "Computed 32026 and 89013607072065 in 0.0044758065s" +: "Computed 480 and 875318608908 in 0.0003234552s" + +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both + XIV ← { + sm ← 0⥊˜s ← 101‿103 ⋄ inp ← 2‿2⊸⥊˘>SInts¨•FLines Input𝕩 + Q ← {𝕊r: ×´+´∘⥊¨0‿2‿6‿8⊏⥊(({/𝕩∾1∾𝕩}·⌊÷⟜2)¨s)⊔+˝{1⌾((s|𝕨+r×𝕩)⊸⊑)sm}˝˘inp} + eins ⇐ Q 100 + zwei ⇐ ⊑⍋Q¨↕1e5 + } + XIV _is 14 +#+end_src + +#+RESULTS: +: "Computed 229069152 and 7383 in 52.1381874919s" #+BEGIN_EXPORT html
diff --git a/src/bqn/aoc24.bqn b/src/bqn/aoc24.bqn index c0d9a0a..cf9f22e 100644 --- a/src/bqn/aoc24.bqn +++ b/src/bqn/aoc24.bqn @@ -1,4 +1,6 @@ Split ← (¬-˜⊢×·+`»⊸>)∘≠⊔⊢ +Ints ← {•ParseFloat¨((¯1+⊢×·+`»⊸<)𝕩∊'0'+↕10)⊔𝕩} +SInts ← {•ParseFloat¨((¯1+⊢×·+`»⊸<)𝕩∊'-'∾'0'+↕10)⊔𝕩} Input ← {"../supp/aoc/2024/"∾".inp"∾˜•Fmt𝕩} _is ← { ∾⟨"Computed ", •Fmt(𝔽𝕩).eins, " and ", @@ -141,11 +143,16 @@ XII ← { XII _is 12 XIII ← { - inp ← {𝕊p‿q‿pq: - e ← ∾{∾•Parsefloat⎊⟨⟩¨∾'+'Split¨','Split𝕩}¨ p‿q - 3‿2⥊e∾∾•Parsefloat⎊⟨⟩¨∾'='Split¨','Split pq - }˘∘‿3⥊⟨⟩⊸≢¨⊸/•FLines Input 𝕩 + ∘‿3‿2⥊∾Ints¨⟨⟩⊸≢¨⊸/•FLines Input 𝕩 C ← (-´×⟜⌽˝){𝕨𝔽_𝕣[a,b,c]: (𝔽÷˜(𝕨+c)⌾⊏⋈○𝔽(𝕨+c)⌾(⊏⌽))a≍b} eins‿zwei ⇐ {+´⥊3‿1×⎉1(∧´⌊⊸=)˘⊸/𝕩⊸C˘inp}¨ 0‿1e13 } XIII _is 13 + +XIV ← { + sm ← 0⥊˜s ← 101‿103 ⋄ inp ← 2‿2⊸⥊˘>SInts¨•FLines Input𝕩 + Q ← {𝕊r: ×´+´∘⥊¨0‿2‿6‿8⊏⥊(({/𝕩∾1∾𝕩}·⌊÷⟜2)¨s)⊔+˝{1⌾((s|𝕨+r×𝕩)⊸⊑)sm}˝˘inp} + eins ⇐ Q 100 + zwei ⇐ ⊑⍋Q¨↕1e5 +} +XIV _is 14