From be3d81721975f4ef447c5a12d9f170db06327f17 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 31 May 2024 19:52:00 +0100 Subject: [PATCH] 21b that does something useful It constructs a function to evaluate the result, so then we can make it depend on the human's number. --- 21/21b.bqn | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 21/21b.bqn diff --git a/21/21b.bqn b/21/21b.bqn new file mode 100644 index 0000000..a63c1d7 --- /dev/null +++ b/21/21b.bqn @@ -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 -- 2.30.2