feat(sterni/aoc/2022): day21.1 BQN solution
This one is not finished yet, but needs to move of this laptop by ways of git. Change-Id: I2c8c0a7b581a654f7cfab92dd21ced82a14c5f42 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7616 Tested-by: BuildkiteCI Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
9008fb0839
commit
835ea6ca7d
2 changed files with 26 additions and 0 deletions
25
users/sterni/exercises/aoc/2022/21/21.bqn
Normal file
25
users/sterni/exercises/aoc/2022/21/21.bqn
Normal file
|
@ -0,0 +1,25 @@
|
|||
⟨ImportBqnLibs, IsAsciiNum, ReadDec⟩ ← •Import "../../lib.bqn"
|
||||
⟨ReplaceAll, Split⟩ ← ImportBqnLibs "strings.bqn"
|
||||
|
||||
i ← ": "⊸Split¨ •FLines "input"
|
||||
ReplaceInts ← {
|
||||
𝕊 𝕩: 𝕊´ 2↑(¬∘(∧´IsAsciiNum∘⊑∘⌽)¨⊔⊢) 𝕩;
|
||||
# TODO: Efficient replace on tokens
|
||||
is 𝕊 es: (((•Fmt⍟(0⊸≠•Type))¨⌾(1⊸⊑) <˘⍉>is)⊸ReplaceAll⌾(1⊸⊑))¨ es
|
||||
}
|
||||
|
||||
c ← 0
|
||||
CanEval ← (IsAsciiNum∨∊⟜"+-/* ")
|
||||
Eval ← {
|
||||
a‿s‿b ← " " Split 𝕩
|
||||
f ← ⊑+‿-‿×‿÷⊏˜"+-*/"⊐s
|
||||
a F○ReadDec b
|
||||
}
|
||||
EvalExprs ← {
|
||||
p‿e ← 2↑((∧´CanEval∘⊑∘⌽)¨⊔⊢) 𝕩
|
||||
ev ← (Eval⌾(⊑⌽))¨ e
|
||||
c +↩1
|
||||
(⊑(⊑¨ev)∊˜<"root")◶⟨EvalExprs∘(ReplaceInts⟜p),1⊸⊑⊑⟩ ev
|
||||
}
|
||||
|
||||
•Show EvalExprs ReplaceInts i
|
|
@ -1,4 +1,5 @@
|
|||
IsAsciiNum ⇐ ('0'⊸≤∧≤⟜'9')
|
||||
IsAlpha ⇐ (('a'⊸≤∧≤⟜'z')∨('A'⊸≤∧≤⟜'Z'))
|
||||
|
||||
# based on leah2's function
|
||||
ReadInt ⇐ {
|
||||
|
|
Loading…
Reference in a new issue