Skip to content

Commit

Permalink
feat: added day 22.
Browse files Browse the repository at this point in the history
  • Loading branch information
Panadestein committed Dec 24, 2024
1 parent 5747878 commit 85935e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
37 changes: 27 additions & 10 deletions src/aoc24.org
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Welcome to my [[https://adventofcode.com/2024][Advent of Code]] solutions for th
to get more context. These definitions and imports are shared by the various puzzles:

#+begin_src bqn :tangle ./bqn/aoc24.bqn
Xor ← {s32 ← 2⋆31 ⋄ 𝕨(s32⊸×⊸+´32•bit._xor○(s32⊸(⌊∘÷˜⋈|)))𝕩}
Split ← (¬-˜⊢×·+`»⊸>)∘≠⊔⊢
Ints ← {•ParseFloat¨((¯1+⊢×·+`»⊸<)𝕩∊𝕨∾'0'+↕10)⊔𝕩}
Input ← {"../supp/aoc/2024/"∾".inp"∾˜•Fmt𝕩}
Expand Down Expand Up @@ -437,8 +438,7 @@ At the end, we have identified all tiles that are part of at least one best path

#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both
XVII ← {
s32 ← 2⋆31 ⋄ inp ← 3(↑⋈∘‿2⥊↓)∾⟨⟩⊸Ints¨•FLines Input𝕩
Xor ← s32⊸×⊸+´32•bit._xor○(s32⊸(⌊∘÷˜⋈|))
inp ← 3(↑⋈∘‿2⥊↓)∾⟨⟩⊸Ints¨•FLines Input𝕩
M ← {r𝕊p:
Cmb ← {𝕩≤3? 𝕩; r⊑˜𝕩-4}
out←⟨⟩ ⋄ out ⊣ {
Expand All @@ -464,7 +464,7 @@ At the end, we have identified all tiles that are part of at least one best path
#+end_src

#+RESULTS:
: "Computed ""2,0,1,3,4,0,2,1,7"" and 236580836040301 in 0.0484539675s"
: "Computed ""2,0,1,3,4,0,2,1,7"" and 236580836040301 in 0.0570494434s"

** XVIII

Expand Down Expand Up @@ -524,24 +524,41 @@ At the end, we have identified all tiles that are part of at least one best path

#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both
XXI ← {
inp ← 3⊸↑¨•FLines Input𝕩
inp ← •FLines Input𝕩
kbs ← ["789","456","123"," 0A"]‿[" ^A","<v>"] ⋄ dp ← •HashMap˜⟨⟩
F ← {
𝕊s‿k‿r: k>r ? ≠s; dp.Has 𝕩 ? dp.Get 𝕩;
>´1↓𝕩 ? ≠⊑𝕩; dp.Has 𝕩 ? dp.Get 𝕩;
𝕊s‿k‿r:
𝕩{𝕩⊣𝕨dp.Set𝕩}⊑+˝{
p‿q‿nl ← (𝕩∾' ')(⊑=/○⥊·↕∘≢⊢)¨<kbs⊑˜k>0
ns ← {0<+´×⟜⌽˝q‿p>∘=nl?⌽𝕩;𝕩}"<v^>"/˜0⌈∾¯1‿1⊸ר⋈⟜⌽q-p
F⟨ns∾'A', k+1, r⟩
p‿q‿nl ← (𝕩∾' ')(⊑=/○⥊·↕∘≢⊢)¨<⍉kbs⊑˜k>0
F⟨'A'∾˜{0≠+´×⟜⌽˝q‿p>∘=<nl?⌽𝕩;𝕩}"<v^>"/˜0⌈∾¯1‿1⊸ר⋈⟜⌽q-p, k+1, r⟩
}˘2↕'A'∾s
}
eins‿zwei ⇐ 2‿25 {+´𝕨{(•ParseFloat𝕩)×F𝕩‿0‿𝕨}¨𝕩}⌜ <inp
eins‿zwei ⇐ 2‿25 {+´𝕨{(•ParseFloat 3↑𝕩)×F𝕩‿0‿𝕨}¨𝕩}⌜ <inp
}
XXI _is 21
#+end_src

#+RESULTS:
: "Computed 195224 and 308034893632420 in 0.0011020566s"
: "Computed 246990 and 306335137543664 in 0.0011588057s"

** XXII

#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both
XXII ← {
dp ← •HashMap˜⟨⟩ ⋄ inp ← •ParseFloat¨ •FLines Input𝕩
Ev ← {{16777216|𝕩Xor𝕎𝕩}´⟨2048×⊢, ⌊32÷˜⊢, 64×⊢, 𝕩⟩}
Ctn ← dp.Has∘⊢◶⟨dp.Set˜,⊢dp.Set+⟜dp.Get⟩
sn ← Ev⍟(↕2001)¨ inp
{𝕩{@⊣(4↓𝕨) ⊑⊸Ctn˘○((∊w)⊸/)w←4↕𝕩}¨{-´˘2↕𝕩}¨𝕩} 10|sn
eins ⇐ +´⊢´¨sn
zwei ⇐ ⌈´dp.Values@
}
XXII _is 22
#+end_src

#+RESULTS:
: "Computed 18317943467 and 2018 in 2.3386385084s"

#+BEGIN_EXPORT html
<div style="text-align: center; font-size: 2em; padding: 20px 0;">
Expand Down
26 changes: 18 additions & 8 deletions src/bqn/aoc24.bqn
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Xor ← {s32231𝕨(s32×+´32•bit._xor(s32(÷˜⋈|)))𝕩}
Split ← (¬-˜⊢×·+`»>)≠⊔⊢
Ints ← {•ParseFloat¨((¯1+⊢×·+`»<)𝕩𝕨'0'+↕10)𝕩}
Input ← {"../supp/aoc/2024/"".inp"˜•Fmt𝕩}
Expand Down Expand Up @@ -188,8 +189,7 @@ XVI ← {
XVI _is 16

XVII ← {
s32231inp3(↑⋈2⥊↓)⟨⟩Ints¨•FLines Input𝕩
Xors32×+´32•bit._xor(s32(÷˜⋈|))
inp3(↑⋈2⥊↓)⟨⟩Ints¨•FLines Input𝕩
M ← {r𝕊p:
Cmb ← {𝕩3? 𝕩; r˜𝕩-4}
out←⟨⟩ ⋄ out {
Expand Down Expand Up @@ -247,17 +247,27 @@ XX ← {
XX _is 20

XXI ← {
inp3¨•FLines Input𝕩
inp•FLines Input𝕩
kbs ← ["789","456","123"," 0A"]‿[" ^A","<v>"] ⋄ dp•HashMap˜⟨⟩
F ← {
𝕊skr: k>r ? s; dp.Has 𝕩 ? dp.Get 𝕩;
>´1𝕩 ? 𝕩; dp.Has 𝕩 ? dp.Get 𝕩;
𝕊skr:
𝕩{𝕩𝕨dp.Set𝕩}⊑+˝{
pqnl ← (𝕩' ')(⊑=/·≢⊢)¨<kbs˜k>0
ns ← {0<+´×˝qp>=nl?𝕩;𝕩}"<v^>"/˜0⌈∾¯11רq-p
Fns'A', k+1, r
pqnl ← (𝕩' ')(⊑=/·≢⊢)¨<⍉kbs˜k>0
F'A'˜{0≠+´×˝qp>=<nl?𝕩;𝕩}"<v^>"/˜0⌈∾¯11רq-p, k+1, r
}˘2'A's
}
einszwei225 {+´𝕨{(ParseFloat𝕩)×F𝕩0𝕨}¨𝕩} <inp
einszwei225 {+´𝕨{(ParseFloat 3𝕩)×F𝕩0𝕨}¨𝕩} <inp
}
XXI _is 21

XXII ← {
dp•HashMap˜⟨⟩ ⋄ inp•ParseFloat¨ •FLines Input𝕩
Ev ← {{16777216|𝕩Xor𝕎𝕩}´2048×⊢, 32÷˜, 64×⊢, 𝕩⟩}
Ctndp.Hasdp.Set˜,dp.Set+dp.Get
snEv(2001)¨ inp
{𝕩{@(4𝕨) Ctn˘((w)/)w4𝕩}¨{-´˘2𝕩}¨𝕩} 10|sn
eins+´´¨sn
zwei´dp.Values@
}
XXII _is 22

0 comments on commit 85935e0

Please sign in to comment.