Sattolo cycle: Difference between revisions

→‎{{header|BQN}}: Switch to fold-based implementation
(add BQN)
(→‎{{header|BQN}}: Switch to fold-based implementation)
Line 597:
 
=={{header|BQN}}==
Uses a fold in order to make the swaps in a functional style. It doesn't mutate the argument array, but after the initial copy is made CBQN is able to update it in place.
Defines a function which takes the same imperative approach as the pseudocode given. Will not modify the array in place, but there is modification used to create the returned result.
 
<lang bqn>Sattolo ← {
Swap ← {
Sattolo arr:
i 𝕊 𝕩:
{
𝕊j ← •rand.Range i:
j ← ⌽⌾(×וrand.Rangei‿j⊸⊏) i𝕩
{}
arr ⌽⌾(i‿j⊸⊏)↩
𝕩 Swap´ 1↓↕≠𝕩
}¨⌽↕≠arr
arr
}
 
99

edits