Skip to content

Commit

Permalink
feat: added day 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
Panadestein committed Dec 8, 2024
1 parent 2e86205 commit 2b01d04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
26 changes: 20 additions & 6 deletions src/aoc24.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -139,17 +138,32 @@ 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

#+RESULTS:
: ⟨ 6231007345478 333027885676693 ⟩

** VIII

#+begin_src bqn :tangle ./bqn/aoc24.bqn
VIII ← {
n ← ≠⊑inp‿ant ← (⊢⋈1↓⍷∘⥊)>•FLines Input𝕩
+´(∧´≥⟜0∧<⟜n)¨⍷∾{
(⍷∘∾⊢/○⥊˜·<⌜˜↕∘≠)(⊣-˜2⊸×){𝔽´¨⌽⊸⋈𝕩‿𝕨}⌜˜/○⥊⟜(↕≢)𝕩
}¨ant=<inp
}
VIII 8
#+end_src

#+RESULTS:
: 291

#+BEGIN_EXPORT html
<div style="text-align: center; font-size: 2em; padding: 20px 0;">
<a href="https://panadestein.github.io/blog/" style="text-decoration: none;">⊑∘∞</a>
Expand Down
19 changes: 13 additions & 6 deletions src/bqn/aoc24.bqn
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,29 @@ V ← {
V _is 5

VI ← {
hinp ← (≢•HashMap⥊⊢) inp>•Flines Input𝕩
hm ← (≢•HashMap⥊⊢) inp>•Flines Input𝕩
g⊑/(↕≢)'^'= inpr ← ⟨¯1, 0⟩‿⟨0, 1⟩‿⟨1, 0⟩‿⟨0, ¯1
Sym ← {𝕊m: s•HashMap˜⟨⟩
(s.Keys@) s.Has {𝕊pd:
s.Set˜pd'#'={𝕊:d˜p+dr}‿{𝕊:p4|d+1} m.Get@ p+dr
}•_while_{𝕊𝕩: (m.Has⊑𝕩) ¬s.Has𝕩} g0
}
einszwei ⇐ (≠⋈·+´{nm ← (hinp.Keys@) •HashMap hinp.Values@
𝕩nm.Set '#'´Sym nm }¨) ⍷⊏⍉>⊑Sym hinp
einszwei ⇐ (≠⋈·+´{𝕩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+101⌈|)
eins+´{𝕨(+∾×)´𝕩?𝕨;0}´¨ inp
zwei+´{𝕨(C˜∾+∾×)´𝕩?𝕨;0}´¨ inp
eins+´{𝕨(+∾×)´𝕩?𝕨;0}´¨ inp
zwei+´{𝕨(C˜∾+∾×)´𝕩?𝕨;0}´¨ inp
}
VII _is 7

VIII ← {
n≠⊑inpant ← (⊢⋈1↓⍷)>•FLines Input𝕩
+´(´0∧<n)¨⍷∾{
(∾⊢/˜·<⌜˜)(⊣-˜2×){𝔽´¨𝕩𝕨}⌜˜/(↕≢)𝕩
}¨ant=<inp
}
VIII 8

0 comments on commit 2b01d04

Please sign in to comment.