From 736edce3381c88feb7751427b6cae13c84b57b70 Mon Sep 17 00:00:00 2001 From: sterni Date: Mon, 5 Dec 2022 19:50:58 +0100 Subject: 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 Reviewed-by: sterni Tested-by: BuildkiteCI --- users/sterni/exercises/aoc/2022/05/5.bqn | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 users/sterni/exercises/aoc/2022/05/5.bqn (limited to 'users/sterni') 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 0000000000..e65975db94 --- /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 -- cgit 1.4.1