Skip to content

Commit

Permalink
feat: day 3 fully array!
Browse files Browse the repository at this point in the history
  • Loading branch information
Panadestein committed Dec 3, 2024
1 parent d995f19 commit e5d3558
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
42 changes: 31 additions & 11 deletions src/aoc24.org
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,30 @@
:UNNUMBERED: notoc
:END:

These are my [[https://adventofcode.com/2024][Advent of Code]] solutions for the year 2024. The following definitions and imports
are shared by the various puzzles:
Welcome to my [[https://adventofcode.com/2024][Advent of Code]] solutions for the year 2024. Please read the puzzles' descriptions upstream
to get more context. Each day corresponds to a function, and the following top-level export serves the
the additional purpose of tracking my progress:

#+begin_src bqn :tangle ./bqn/aoc24.bqn :results none
⟨I, II⟩⇐
#+end_src

These definitions and imports are shared by the various puzzles:

#+begin_src bqn :tangle ./bqn/aoc24.bqn
Split ← (¬-˜⊢×·+`»⊸>)∘≠⊔⊢
Input ← •Flines{"../supp/aoc/2024/"∾".inp"∾˜•Fmt𝕩}
Input ← {"../supp/aoc/2024/"∾".inp"∾˜•Fmt𝕩}
_is ← {(𝔽𝕩).eins⋈(𝔽𝕩).zwei}
#+end_src

#+RESULTS:
: (1-modifier block)

The top level export tracks the progress:

#+begin_src bqn :tangle ./bqn/aoc24.bqn :results none
⟨I, II⟩⇐
#+end_src

** I

#+begin_src bqn :tangle ./bqn/aoc24.bqn
I ← {
inp ← >(•ParseFloat¨' '⊸Split)¨Input𝕩
inp ← >(•ParseFloat¨' '⊸Split)¨•FLines Input𝕩
eins ⇐ +´|-´˘∧˘⌾⍉inp
zwei ⇐ {+´𝕨×-´(∧𝕩)⊸⍋¨(⊢⋈-⟜1)𝕨}´<˘⍉inp
}
Expand All @@ -60,7 +61,7 @@ The top level export tracks the progress:

#+begin_src bqn :tangle ./bqn/aoc24.bqn
II ← {
inp ← (-´˘·2⊸↕·•ParseFloat¨' '⊸Split)¨Input𝕩
inp ← (-´˘·2⊸↕·•ParseFloat¨' '⊸Split)¨•FLines Input𝕩
P‿Q ← ⟨3≥⌈´∘|, ≠=·|+´∘×⟩
F1‿F2‿F3 ← P‿P‿Q {𝕎∧𝕏}¨ ⟨Q, 1=≠-·|·+´×, 1=·+´3>|⟩
eins ⇐ +´F1¨inp
Expand All @@ -73,6 +74,25 @@ The top level export tracks the progress:
: ⟨ 483 528 ⟩

** III

#+begin_src bqn :tangle ./bqn/aoc24.bqn
III ← {
mem ← •FChars Input𝕩
prg ← mem/˜1{·𝕊¯1:0;·𝕊1:1;𝕨𝕊0:𝕨}`-´"do()"‿"don't()"(≢∘⊢↑⍷)¨<mem
mul‿cmd ← {(12↑↓⟜𝕩)¨4+"mul("/∘(≢∘⊢↑⍷)𝕩}¨mem‿prg
V ← {
l‿r←⊑⎊0¨1(↑⋈↓)','Split𝕩
l×○•ParseFloat⎊0 (∨´⎊0')'⊸=)◶⟨0, ⊑')'⊸Split⟩r
}
eins ⇐ +´V¨mul
zwei ⇐ +´V¨cmd
}
III _is 3
#+end_src

#+RESULTS:
: ⟨ 165225049 108830766 ⟩

** IV
** V
** VI
Expand Down
23 changes: 18 additions & 5 deletions src/bqn/aoc24.bqn
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
I, II⟩⇐

Split ← (¬-˜⊢×·+`»>)≠⊔⊢
Input•Flines{"../supp/aoc/2024/"".inp"˜•Fmt𝕩}
Input ← {"../supp/aoc/2024/"".inp"˜•Fmt𝕩}
_is ← {(𝔽𝕩).eins(𝔽𝕩).zwei}

I, II⟩⇐

I ← {
inp>(•ParseFloat¨' 'Split)¨Input𝕩
inp>(•ParseFloat¨' 'Split)¨•FLines Input𝕩
eins+´|-´˘˘inp
zwei ⇐ {+´𝕨×-´(𝕩)¨(⊢⋈-1)𝕨}´<˘inp
}
I _is 1

II ← {
inp ← (-´˘·2·•ParseFloat¨' 'Split)¨Input𝕩
inp ← (-´˘·2·•ParseFloat¨' 'Split)¨•FLines Input𝕩
PQ ← ⟨3≥⌈´|, ≠=·|+´×
F1F2F3PPQ {𝕎∧𝕏}¨Q, 1=≠-·|·+´×, 1=·+´3>|
eins+´F1¨inp
zweieins + {abab: ab-˜b+a} ⟨F2, F3, F2∧F3⟩ {≠𝕎¨/𝕩}¨ <(¬F1¨)/inp
}
II _is 2

III ← {
mem•FChars Input𝕩
prgmem/˜1𝕊¯1:0𝕊1:1;𝕨𝕊0:𝕨}`-´"do()""don't()"(⊢↑⍷)¨<mem
mulcmd ← {(12↑↓𝕩)¨4+"mul("/(⊢↑⍷)𝕩}¨memprg
V ← {
lr0¨1(↑⋈↓)','Split𝕩
lוParseFloat0 (´0')'=)0, ')'Splitr
}
eins+´V¨mul
zwei+´V¨cmd
}
III _is 3

0 comments on commit e5d3558

Please sign in to comment.