From 835ea6ca7db3b2b22a3cc9e323132b2769af235d Mon Sep 17 00:00:00 2001 From: sterni Date: Fri, 23 Dec 2022 15:28:48 +0100 Subject: 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 Reviewed-by: sterni --- users/sterni/exercises/aoc/2022/21/21.bqn | 25 +++++++++++++++++++++++++ users/sterni/exercises/aoc/lib.bqn | 1 + 2 files changed, 26 insertions(+) create mode 100644 users/sterni/exercises/aoc/2022/21/21.bqn (limited to 'users/sterni/exercises/aoc') diff --git a/users/sterni/exercises/aoc/2022/21/21.bqn b/users/sterni/exercises/aoc/2022/21/21.bqn new file mode 100644 index 000000000000..2f91f55d445e --- /dev/null +++ b/users/sterni/exercises/aoc/2022/21/21.bqn @@ -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 diff --git a/users/sterni/exercises/aoc/lib.bqn b/users/sterni/exercises/aoc/lib.bqn index 37c518d1fd61..e870a5dfa426 100644 --- a/users/sterni/exercises/aoc/lib.bqn +++ b/users/sterni/exercises/aoc/lib.bqn @@ -1,4 +1,5 @@ IsAsciiNum ⇐ ('0'⊸≤∧≤⟜'9') +IsAlpha ⇐ (('a'⊸≤∧≤⟜'z')∨('A'⊸≤∧≤⟜'Z')) # based on leah2's function ReadInt ⇐ { -- cgit 1.4.1