Skip to main content
deleted 48 characters in body
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384

05AB1E, 9 77 6 bytes

āœʒāα@Pœʒāα@P

Outputs all possible permutations of the 1-based indicesinput-list, and outputs all possible permutations. Outputting a random one would be 2 bytes longer by adding a trailing .

Try it online.Try it online.

Explanation:

ā œ       # Push a list inof thepermutations rangeof [1,the first (implicit) first input-length]
 œ       # Pop and get all its permutations list
  ʒ      # Filter this list of permutations by:
   ā     #  Push a list in the range [1,length] (without popping)
    α    #  Get the absolute difference between the values at the same positions
     @   #  Check for each whether the second (implicit) input is >= the value
      P  #  Product to check if all are truthy
         # (after which the filtered list is output implicitly)

05AB1E, 9 7 bytes

āœʒāα@P

Outputs all possible permutations of the 1-based indices. Outputting a random one would be 2 bytes longer by adding a trailing .

Try it online.

Explanation:

ā        # Push a list in the range [1, (implicit) first input-length]
 œ       # Pop and get all its permutations 
  ʒ      # Filter this list of permutations by:
   ā     #  Push a list in the range [1,length] (without popping)
    α    #  Get the absolute difference between the values at the same positions
     @   #  Check for each whether the second (implicit) input is >= the value
      P  #  Product to check if all are truthy
         # (after which the filtered list is output implicitly)

05AB1E, 9 7 6 bytes

œʒāα@P

1-based input-list, and outputs all possible permutations. Outputting a random one would be 2 bytes longer by adding a trailing .

Try it online.

Explanation:

œ       # Push a list of permutations of the first (implicit) input-list
 ʒ      # Filter this list of permutations by:
  ā     #  Push a list in the range [1,length] (without popping)
   α    #  Get the absolute difference between the values at the same positions
    @   #  Check for each whether the second (implicit) input is >= the value
     P  #  Product to check if all are truthy
        # (after which the filtered list is output implicitly)
deleted 129 characters in body
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384

05AB1E, 99 7 bytes

œʒ¹k>āα@Pāœʒāα@P

Outputs all possible permutations of the 1-based indices. Outputting a random one would be 2 bytes longer by adding a trailing .

Try it online.Try it online.

Explanation:

œ ā        # Get allPush possiblea permutationslist ofin the firstrange [1, (implicit) first input-listlength]
 ʒ œ       # FilterPop thisand listget ofall its permutations by:
  ¹ ʒ      #  Push theFilter firstthis input-list again
   k      #  Get the 0-based index of each value in the permutation
    >     #  Increase thempermutations by 1 to 1-based indices:
     ā     #  Push a list in the range [1,length] (without popping)
      α    #  Get the absolute difference between the values at the same positions
       @   #  Check for each whether the second (implicit) input is >= the value
        P  #  Product to check if all are truthy
          # (after which the filtered list of permutations is output implicitly)

05AB1E, 9 bytes

œʒ¹k>āα@P

Outputs all possible permutations. Outputting a random one would be 2 bytes longer by adding a trailing .

Try it online.

Explanation:

œ         # Get all possible permutations of the first (implicit) input-list
 ʒ        # Filter this list of permutations by:
  ¹       #  Push the first input-list again
   k      #  Get the 0-based index of each value in the permutation
    >     #  Increase them by 1 to 1-based indices
     ā    #  Push a list in the range [1,length] (without popping)
      α   #  Get the absolute difference between the values at the same positions
       @  #  Check for each whether the second (implicit) input is >= the value
        P #  Product to check if all are truthy
          # (after which the filtered list of permutations is output implicitly)

05AB1E, 9 7 bytes

āœʒāα@P

Outputs all possible permutations of the 1-based indices. Outputting a random one would be 2 bytes longer by adding a trailing .

Try it online.

Explanation:

ā        # Push a list in the range [1, (implicit) first input-length]
 œ       # Pop and get all its permutations 
  ʒ      # Filter this list of permutations by:
   ā     #  Push a list in the range [1,length] (without popping)
    α    #  Get the absolute difference between the values at the same positions
     @   #  Check for each whether the second (implicit) input is >= the value
      P  #  Product to check if all are truthy
         # (after which the filtered list is output implicitly)
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384

05AB1E, 9 bytes

œʒ¹k>āα@P

Outputs all possible permutations. Outputting a random one would be 2 bytes longer by adding a trailing .

Try it online.

Explanation:

œ         # Get all possible permutations of the first (implicit) input-list
 ʒ        # Filter this list of permutations by:
  ¹       #  Push the first input-list again
   k      #  Get the 0-based index of each value in the permutation
    >     #  Increase them by 1 to 1-based indices
     ā    #  Push a list in the range [1,length] (without popping)
      α   #  Get the absolute difference between the values at the same positions
       @  #  Check for each whether the second (implicit) input is >= the value
        P #  Product to check if all are truthy
          # (after which the filtered list of permutations is output implicitly)