tvl-depot/users/sterni/exercises/aoc/2022/21/21.bqn

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
785 B
BQN
Raw Normal View History

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 {
asb " " Split 𝕩
f +-×÷˜"+-*/"s
a FReadDec b
}
EvalExprs {
pe 2((´CanEval)¨) 𝕩
ev (Eval())¨ e
c +1
((¨ev)˜<"root")EvalExprs(ReplaceIntsp),1 ev
}
•Show EvalExprs ReplaceInts i