about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-12-05T18·50+0100
committerclbot <clbot@tvl.fyi>2022-12-05T18·58+0000
commit736edce3381c88feb7751427b6cae13c84b57b70 (patch)
tree08406d1749f8e94f98c98c83b9bea70913ba9530
parent5a41c4c6aa148af716daa77da381bbc318a4a032 (diff)
feat(sterni/aoc/2022): day05 BQN solution r/5392
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
-rw-r--r--users/sterni/exercises/aoc/2022/05/5.bqn20
1 files changed, 20 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2022/05/5.bqn b/users/sterni/exercises/aoc/2022/05/5.bqn
new file mode 100644
index 000000000000..e65975db9476
--- /dev/null
+++ b/users/sterni/exercises/aoc/2022/05/5.bqn
@@ -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