From: Ben Harris Date: Sun, 12 May 2024 10:41:46 +0000 (+0100) Subject: 12: Use the primitive •_while_: it's actually easier to understand X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=aaa4d1680709d6a5799049159d0ff6c8ba850463;p=aoc-2022.git 12: Use the primitive •_while_: it's actually easier to understand --- diff --git a/12/12a.bqn b/12/12a.bqn index 12a1975..f0ebe28 100644 --- a/12/12a.bqn +++ b/12/12a.bqn @@ -1,6 +1,3 @@ -# From https://mlochbaum.github.io/BQN/doc/control.html -While ← {𝕩•_while_𝕨@}´ - Prep←{ start⇐'S'=𝕩 end⇐'E'=𝕩 @@ -15,12 +12,8 @@ Main←{𝕊⟨start,end,map⟩: Flow←{ 𝕩∨(«𝕩∧can_go_n)∨(»𝕩∧can_go_s)∨(«˘𝕩∧can_go_w)∨(»˘𝕩∧can_go_e) } - now←start count←0 - While {𝕤,¬∨´⥊(now∧end)}‿{𝕤 - now↩Flow now - count+↩1 - } + {count+↩1 ⋄ Flow 𝕩} •_while_ {¬∨´⥊(𝕩∧end)} start count } diff --git a/12/12b.bqn b/12/12b.bqn index 177d917..d92f7c9 100644 --- a/12/12b.bqn +++ b/12/12b.bqn @@ -1,6 +1,3 @@ -# From https://mlochbaum.github.io/BQN/doc/control.html -While ← {𝕩•_while_𝕨@}´ - Prep←{ start⇐'S'=𝕩 end⇐'E'=𝕩 @@ -16,12 +13,8 @@ Main←{𝕊⟨start,end,map⟩: Flow←{ 𝕩∨(«𝕩∧can_go_n)∨(»𝕩∧can_go_s)∨(«˘𝕩∧can_go_w)∨(»˘𝕩∧can_go_e) } - now←start count←0 - While {𝕤,¬∨´⥊(now∧end)}‿{𝕤 - now↩Flow now - count+↩1 - } + {count+↩1 ⋄ Flow 𝕩} •_while_ {¬∨´⥊(𝕩∧end)} start count }