chiark / gitweb /
21b that does something useful
authorBen Harris <bjh21@bjh21.me.uk>
Fri, 31 May 2024 18:52:00 +0000 (19:52 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Fri, 31 May 2024 18:52:00 +0000 (19:52 +0100)
It constructs a function to evaluate the result, so then we can make
it depend on the human's number.

21/21b.bqn [new file with mode: 0644]

diff --git a/21/21b.bqn b/21/21b.bqn
new file mode 100644 (file)
index 0000000..a63c1d7
--- /dev/null
@@ -0,0 +1,24 @@
+Prep←{
+  17=≠𝕩 ? (⋈⚇0⟨↕4,6+↕4,11,13+↕4⟩)⊑𝕩;
+  ⟨(↕4)⊏𝕩,•ParseFloat 6↓𝕩⟩
+}¨
+
+Main←{
+  monkeys←⟨⟩•HashMap⟨⟩
+  {(⊑𝕩) monkeys.Set (1↓𝕩) }¨𝕩
+  # "humn" monkeys.Set ⟨'?'⟩
+  _decode←{⊑("+-*/"⊐𝕗)⊏⟨+,-,×,÷⟩}
+  # The value we're constructing is a function on what "humn" shouts.
+  Eval←{ 𝕊⟨number⟩: number;
+    𝕊⟨'?'⟩: ⊢;
+    𝕊⟨x, opcode, y⟩:
+      fx←(Eval monkeys.Get x)
+      fy←(Eval monkeys.Get y)
+      Fx(opcode _decode)Fy
+  }
+  rootfn←Eval monkeys.Get "root"
+  •Show rootfn
+  RootFn @
+}
+
+•Show Main Prep •file.Lines ⊑•args