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