From: Ben Harris Date: Fri, 31 May 2024 18:52:00 +0000 (+0100) Subject: 21b that does something useful X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=be3d81721975f4ef447c5a12d9f170db06327f17;p=aoc-2022.git 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. --- 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