Skip to main content
added 533 characters in body
Source Link
lyxal
  • 34.3k
  • 2
  • 64
  • 141

Vyxal, 11 bytes

ż-ȧZ⁽tṡfyĠ•

Try it Online!

The pains of not having tons of array focused built-ins

Explained

ż-ȧZ⁽tṡfyĠ•
ż           # The range [1, len(input)]
 -ȧ         # and the absolute difference with the input
   Z        # Zip those together
    ⁽tṡ     # and sort that by tail - this is a work around way to group one list by the results of a function applied to it
       fy   # flatten and uninterleave this - this pushes the original list and the absolute differences but sorted
         Ġ  # group the indexes on consecutive items
          • # and mold the other list to the shape of that.

Vyxal, 11 bytes

ż-ȧZ⁽tṡfyĠ•

Try it Online!

The pains of not having tons of array focused built-ins

Vyxal, 11 bytes

ż-ȧZ⁽tṡfyĠ•

Try it Online!

The pains of not having tons of array focused built-ins

Explained

ż-ȧZ⁽tṡfyĠ•
ż           # The range [1, len(input)]
 -ȧ         # and the absolute difference with the input
   Z        # Zip those together
    ⁽tṡ     # and sort that by tail - this is a work around way to group one list by the results of a function applied to it
       fy   # flatten and uninterleave this - this pushes the original list and the absolute differences but sorted
         Ġ  # group the indexes on consecutive items
          • # and mold the other list to the shape of that.
Source Link
lyxal
  • 34.3k
  • 2
  • 64
  • 141

Vyxal, 11 bytes

ż-ȧZ⁽tṡfyĠ•

Try it Online!

The pains of not having tons of array focused built-ins