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.
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
}
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
}