chiark / gitweb /
20b done
authorBen Harris <bjh21@bjh21.me.uk>
Fri, 31 May 2024 08:13:15 +0000 (09:13 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Fri, 31 May 2024 08:13:15 +0000 (09:13 +0100)
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.

20/20a.bqn
20/20b.bqn

index e1f13e76e8824d4dea163e933d81280486a75bae..bd045bf09d147ddfd0a614829c5b94d94c4e5d7b 100644 (file)
@@ -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
 }
 
index bdf00f4dbe1145ad85a76c68779b3d1ccd2b94c3..29a126d8b68a1bcabb2c5c144f4b04cc4a529db6 100644 (file)
@@ -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
 }