chiark / gitweb /
Prep for 05a
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 5 May 2024 10:28:33 +0000 (11:28 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 5 May 2024 10:45:38 +0000 (11:45 +0100)
05/05a.bqn [new file with mode: 0644]

diff --git a/05/05a.bqn b/05/05a.bqn
new file mode 100644 (file)
index 0000000..f144cf1
--- /dev/null
@@ -0,0 +1,22 @@
+Split←{
+  blocknums ← +`𝕨
+  # Set entries in blocknums to -1 when they correspond with delimiters.
+  blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums
+  blocknums⊔𝕩
+}
+
+Prep1Proc←{ # Prepare one step of procedure
+  # Converts "move 3 from 1 to 3" into [⟨1,3⟩,⟨1,3⟩,⟨1,3⟩].
+  ⟨n,f,t⟩←•ParseFloat¨⟨1,3,5⟩⊏(' '=𝕩)Split𝕩
+  ⟨n⟩/[⟨f,t⟩]
+}
+
+Prep←{
+  ⟨rawmap, rawproc⟩←(""⊸≡¨𝕩)Split𝕩
+  map0←{(𝕩≠' ')/𝕩}¨<˘⍉⌽>¯1↓rawmap
+  map1←⟨""⟩∾(1=4|↕≠map0)/map0
+  proc←∾Prep1Proc¨rawproc
+  ⟨map1, proc⟩
+}
+
+•Show Prep •file.Lines ⊑•args