feat(sterni/aoc/2022): day05 BQN solution
First input that is genuinely fun to parse in BQN. There surely is a nice trick for _ApplyCmd, but this works and I'm unable to think today. Change-Id: Iefccc81f1c1db03f45e31aaf7a1703ac0f91306f Reviewed-on: https://cl.tvl.fyi/c/depot/+/7529 Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
5a41c4c6aa
commit
736edce338
1 changed files with 20 additions and 0 deletions
20
users/sterni/exercises/aoc/2022/05/5.bqn
Normal file
20
users/sterni/exercises/aoc/2022/05/5.bqn
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
⟨ReadDec, SplitOn, IsAsciiNum⟩ ← •Import "../../lib.bqn"
|
||||||
|
rs‿rc ← (<"") SplitOn •FLines "../05/input"
|
||||||
|
|
||||||
|
stacks ← {
|
||||||
|
count ← '0'-˜⊑⌽' ' (≠/⊢) ⊑⌽rs
|
||||||
|
spec ← 0<(-1)↓(-1)⌽∾(∾⟜0‿0‿0)¨1+↕count
|
||||||
|
' ' (≠/⊢)¨⥊⋈˘⍉>spec⊸/¨(-1)↓rs
|
||||||
|
}
|
||||||
|
|
||||||
|
cmds ← {0‿1‿1-˜ ReadDec¨ ((∧´IsAsciiNum)¨/⊢) (<' ') SplitOn 𝕩}¨ rc
|
||||||
|
|
||||||
|
ModestTake ← ↑⍟(<⟜≠)
|
||||||
|
_ApplyCmd ← {
|
||||||
|
c‿f‿t ← 𝕩
|
||||||
|
m ← 𝔽 c ModestTake f⊑𝕨
|
||||||
|
(m⊸∾)⌾(t⊸⊑) (c⊸↓)⌾(f⊸⊑)𝕨
|
||||||
|
}
|
||||||
|
|
||||||
|
•Out "day05.1: "∾⊑¨stacks ⌽_ApplyCmd˜´ ⌽ cmds
|
||||||
|
•Out "day05.2: "∾⊑¨stacks ⊢_ApplyCmd˜´ ⌽ cmds
|
Loading…
Reference in a new issue