chiark / gitweb /
21b done
authorBen Harris <bjh21@bjh21.me.uk>
Fri, 31 May 2024 21:05:43 +0000 (22:05 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Fri, 31 May 2024 21:05:43 +0000 (22:05 +0100)
21/21b.bqn

index a63c1d780ebb981669ca6020615f5e64863fd700..b1acbdcff451a62ea2511f3ea3a3c19b6328007b 100644 (file)
@@ -6,19 +6,26 @@ Prep←{
 Main←{
   monkeys←⟨⟩•HashMap⟨⟩
   {(⊑𝕩) monkeys.Set (1↓𝕩) }¨𝕩
-  "humn" monkeys.Set ⟨'?'⟩
+  "humn" monkeys.Set ⟨'?'⟩
   _decode←{⊑("+-*/"⊐𝕗)⊏⟨+,-,×,÷⟩}
+  GrowTree←{
+    𝕊⟨x, opcode, y⟩: ⟨𝕊 monkeys.Get x, opcode _decode, 𝕊 monkeys.Get y⟩;
+    𝕩
+  }
   # 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
+  Eval←{
+    𝕊⟨'?'⟩: ⟨'f', ⊢⟩;
+    𝕊⟨number⟩: ⟨'k', number⟩;
+    𝕊⟨xt, op, yt⟩:
+      x←Eval xt
+      y←Eval yt
+      { 𝕊⟨⟨'k', x⟩, ⟨'k', y⟩⟩: ⟨'k', x Op y⟩;
+        𝕊⟨⟨·,   x⟩, ⟨·,   y⟩⟩: ⟨'f', X Op Y⟩
+      } ⟨x, y⟩
   }
-  rootfn←Eval monkeys.Get "root"
-  •Show rootfn
-  RootFn @
+  ⟨left, ·, right⟩←GrowTree monkeys.Get "root"
+  rootfn←Eval ⟨left, -, right⟩
+  (1⊑rootfn){𝔽}⁼0
 }
 
 •Show Main Prep •file.Lines ⊑•args