From: Ben Harris Date: Fri, 31 May 2024 21:05:43 +0000 (+0100) Subject: 21b done X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=bf95e7e789798abecdbb47882c447721517ba621;p=aoc-2022.git 21b done --- diff --git a/21/21b.bqn b/21/21b.bqn index a63c1d7..b1acbdc 100644 --- a/21/21b.bqn +++ b/21/21b.bqn @@ -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