Skip to main content
Notice removed Reward existing answer by lyxal
Bounty Ended with naffetS's answer chosen by lyxal
Notice added Reward existing answer by lyxal
Bounty Started worth 100 reputation by lyxal
added 30 characters in body
Source Link
flawr
  • 43.9k
  • 7
  • 104
  • 249

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • You can assume the input array is limited to the range [1, n] (or [0, n-1], where n is the length).
  • all permissible permutations must have a nonzero probability of occurring.
  • Instead of shuffling an input array, you can also just take k and the length of the array n (or n+-1 alternatively) as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].
  • Alternatively to sampling one random permutation you can also output all permissible permutations.

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • You can assume the input array is limited to the range [1, n] (or [0, n-1], where n is the length).
  • all permissible permutations must have a nonzero probability of occurring.
  • Instead of shuffling an input array, you can also just take k and the length of the array as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].
  • Alternatively to sampling one random permutation you can also output all permissible permutations.

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • You can assume the input array is limited to the range [1, n] (or [0, n-1], where n is the length).
  • all permissible permutations must have a nonzero probability of occurring.
  • Instead of shuffling an input array, you can also just take k and the length of the array n (or n+-1 alternatively) as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].
  • Alternatively to sampling one random permutation you can also output all permissible permutations.
Tweeted twitter.com/StackCodeGolf/status/1511403301878865932
added 112 characters in body
Source Link
flawr
  • 43.9k
  • 7
  • 104
  • 249

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • You can assume the input array is limited to the range [1, n] (or [0, n-1], where n is the length).
  • all permissible permutations must have a nonzero probability of occuringoccurring.
  • Instead of shuffling an input array, you can also just take k and the length of the array as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].
  • Alternatively to sampling one random permutation you can also output all permissible permutations.

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • all permissible permutations must have a nonzero probability of occuring.
  • Instead of shuffling an input array, you can also just take k and the length of the array as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].
  • Alternatively to sampling one random permutation you can also output all permissible permutations.

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • You can assume the input array is limited to the range [1, n] (or [0, n-1], where n is the length).
  • all permissible permutations must have a nonzero probability of occurring.
  • Instead of shuffling an input array, you can also just take k and the length of the array as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].
  • Alternatively to sampling one random permutation you can also output all permissible permutations.
Became Hot Network Question
added 105 characters in body
Source Link
flawr
  • 43.9k
  • 7
  • 104
  • 249

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • all permissible permutations must have a nonzero probability of occuring.
  • Instead of shuffling an input array, you can also just take k and the length of the array as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].
  • Alternatively to sampling one random permutation you can also output all permissible permutations.

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • all permissible permutations must have a nonzero probability of occuring.
  • Instead of shuffling an input array, you can also just take k and the length of the array as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position.

Example

Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions:

[*, 3, *, *, * ,*] 
[*, *, 3, *, *, *]   (original position)
[*, *, *, 3, *, *]

Details

  • Uniform randomness over all permissible permutations is not required, but
  • all permissible permutations must have a nonzero probability of occuring.
  • Instead of shuffling an input array, you can also just take k and the length of the array as an input, and output a permutation in a suitable encoding (i.e as a list of indices etc). For this you can use 0 or 1 based indexing.
  • Instead of k you can also take k-1 or k+1 as an input if it is more suitable.
  • You can assume that 0 < k < [length of array].
  • Alternatively to sampling one random permutation you can also output all permissible permutations.
Source Link
flawr
  • 43.9k
  • 7
  • 104
  • 249
Loading