Skip to content

Commit

Permalink
feat: add day XIII.
Browse files Browse the repository at this point in the history
  • Loading branch information
Panadestein committed Dec 13, 2024
1 parent b729909 commit ed26524
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
36 changes: 26 additions & 10 deletions src/aoc24.org
Original file line number Diff line number Diff line change
Expand Up @@ -241,26 +241,42 @@ powers of the adjacency matrix. This is method is unfortunately slower than simp

** XII

#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both
#+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{𝕎𝕩}¨<inp
cr ← +´ 1‿1‿3‿3 {n1‿n2←𝕨‿𝕩⊏nud ⋄ n3←n1{𝕏𝕨}𝕩⊑cf
((inp≠n3)∧(inp=n2)∧inp=n1)∨(n1≠inp)∧inp≠n2}¨ 0‿2‿0‿2
DFS ← {
sf‿sp‿sc ← ⟨»˘, », «˘, «⟩‿⟨0‿¯1, ¯1‿0, 0‿1, 1‿0⟩‿⟨1‿0, 1‿2, 3‿0, 3‿2⟩
mn‿mp ← (∾¨´⋈·+´¬) inp<⊸=nud ← sf{𝕎𝕩}¨<inp
mc ← +´sc{hv←(sf⊑˜⊢´𝕨){𝔽}⊑h‿v←𝕨⊏nud ⋄ ((𝕩≠h)∧𝕩≠v)∨(𝕩≠hv)∧(𝕩=v)∧𝕩=h}¨<inp
BFS ← {
+´{𝕩⊑v?0; v 1⌾(𝕩⊸⊑)↩ ⋄ a‿p‿c ← 0‿0‿0
1⊸↓∘{𝕊: h←⊑𝕩 ⋄ a+↩1 ⋄ p+↩h⊑pr ⋄ c+↩h⊑cr
𝕩∾{𝕩⊣v 1¨⌾(𝕩⊸⊑)↩}{𝕩/˜(0=𝕩⊑⎊∞¨<v)∧(h⊑nb)∧(∧´≥⟜0∧<⟜n)¨𝕩}cn+<h
1⊸↓∘{𝕊: h←⊑𝕩 ⋄ a+↩1 ⋄ p+↩h⊑mp ⋄ c+↩h⊑mc
𝕩∾{𝕩⊣v 1¨⌾(𝕩⊸⊑)↩}{𝕩/˜(0=𝕩⊑⎊∞¨<v)∧(h⊑mn)∧(∧´≥⟜0∧<⟜n)¨𝕩}sp+<h
}•_while_{𝕊: 0<≠𝕩} ⋈𝕩 ⋄ a×p‿c}¨⥊↕≢ v ← 0¨𝕩
}
eins‿zwei ⇐ DFS inp
eins‿zwei ⇐ BFS inp
}
XII _is 12
#+end_src

#+RESULTS:
: "Computed 1473620 and 902620 in 0.018642635s"
: "Computed 1473620 and 902620 in 0.0179634179s"

** XIII

#+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 𝕩
C ← (-´×⟜⌽˝){𝕨𝔽_𝕣[a,b,c]: (𝔽÷˜·𝔽¨(𝕨+c)⌾(⊏⍉)⋈(𝕨+c)⌾(⊏⌽∘⍉))⍉a≍b}
eins‿zwei ⇐ {+´⥊3‿1×⎉1(∧´⌊⊸=)˘⊸/𝕩⊸C˘inp}¨ 0‿1e13
}
XIII _is 13
#+end_src

#+RESULTS:
: "Computed 32026 and 89013607072065 in 0.0046754515s"

#+BEGIN_EXPORT html
<div style="text-align: center; font-size: 2em; padding: 20px 0;">
Expand Down
25 changes: 17 additions & 8 deletions src/bqn/aoc24.bqn
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,25 @@ XI _is 11

XII ← {
ninp⋈>•FLines Input𝕩
cfcn ← ⟨»˘, », «˘, «⟩‿⟨0¯1, ¯10, 01, 10
nbpr ← (¨´·+´¬) inp<=nudcf{𝕎𝕩}¨<inp
cr+´ 1133 {n1n2𝕨𝕩nudn3n1{𝕏𝕨}𝕩cf
((inpn3)(inp=n2)inp=n1)(n1inp)inpn2}¨ 0202
DFS ← {
sfspsc ← ⟨»˘, », «˘, «⟩‿⟨0¯1, ¯10, 01, 10⟩‿⟨10, 12, 30, 32
mnmp ← (¨´·+´¬) inp<=nudsf{𝕎𝕩}¨<inp
mc+´sc{hv←(sf˜´𝕨){𝔽}hv𝕨nud ⋄ ((𝕩h)𝕩v)(𝕩hv)(𝕩=v)𝕩=h}¨<inp
BFS ← {
+´{𝕩v?0; v 1(𝕩)↩ ⋄ apc000
1{𝕊: h𝕩a+1p+hprc+hcr
𝕩{𝕩v 1¨(𝕩)↩}{𝕩/˜(0=𝕩¨<v)(hnb)(´0∧<n)¨𝕩}cn+<h
1{𝕊: h𝕩a+1p+hmpc+hmc
𝕩{𝕩v 1¨(𝕩)↩}{𝕩/˜(0=𝕩¨<v)(hmn)(´0∧<n)¨𝕩}sp+<h
}•_while_{𝕊: 0<≠𝕩} 𝕩a×pc}¨⥊↕≢ v0¨𝕩
}
einszweiDFS inp
einszweiBFS inp
}
XII _is 12

XIII ← {
inp ← {𝕊pqpq:
e{∾•Parsefloat⟨⟩¨'+'Split¨','Split𝕩}¨ pq
32e∾∾•Parsefloat⟨⟩¨'='Split¨','Split pq
}˘3⟨⟩¨/•FLines Input 𝕩
C ← (-´×˝){𝕨𝔽_𝕣[a,b,c]: (𝔽÷˜·𝔽¨(𝕨+c)(⊏⍉)(𝕨+c)(⊏⌽))ab}
einszwei ⇐ {+´31×1(´=)˘/𝕩C˘inp}¨ 01e13
}
XIII _is 13

0 comments on commit ed26524

Please sign in to comment.