From: Ben Harris Date: Fri, 31 May 2024 08:13:15 +0000 (+0100) Subject: 20b done X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=2902a81d6c0152fec9f739280478bd480a1ed618;p=aoc-2022.git 20b done The problem was that my input included repeated numbers, so I needed to keep track of which instance of a repeated number I was moving. I achieved this by applying the mixing operation to a list of indices into the original array, looking up shift amounts in the original array and translating back to the original values at the end. --- diff --git a/20/20a.bqn b/20/20a.bqn index e1f13e7..bd045bf 100644 --- a/20/20a.bqn +++ b/20/20a.bqn @@ -1,8 +1,9 @@ Prep←•ParseFloat¨ Main←{ 𝕊 orig: - Twiddle←{ (1⊸⌽)⌾((1+(¯1+≠𝕩)|𝕨)⊸↑) (𝕩⊐𝕨)⌽𝕩 } - cur ← orig Twiddle´ ⌽orig + Twiddle←{ (1⊸⌽)⌾((1+(¯1+≠𝕩)|(𝕨⊑orig))⊸↑) (𝕩⊐𝕨)⌽𝕩 } + perm ← (↕≠orig) Twiddle´ ⌽↕≠orig + cur ← perm⊏orig +´((≠cur)|(cur⊐0)+⟨1000,2000,3000⟩)⊏cur } diff --git a/20/20b.bqn b/20/20b.bqn index bdf00f4..29a126d 100644 --- a/20/20b.bqn +++ b/20/20b.bqn @@ -1,10 +1,11 @@ Prep←•ParseFloat¨ Main←{ 𝕊 orig: - Twiddle←{ (1⊸⌽)⌾((1+(¯1+≠𝕩)|𝕨)⊸↑) (𝕩⊐𝕨)⌽𝕩 } + Twiddle←{ (1⊸⌽)⌾((1+(¯1+≠𝕩)|(𝕨⊑orig))⊸↑) (𝕩⊐𝕨)⌽𝕩 } Mix←Twiddle´⟜⌽ orig ×↩ 811589153 - cur ← orig Mix˜⍟10 orig + perm ← (↕≠orig) Mix˜⍟10 ↕≠orig + cur ← perm⊏orig +´((≠cur)|(cur⊐0)+⟨1000,2000,3000⟩)⊏cur }