Sort and Re-apply Deltas of an Array
MATL, 8 bytes
1)GdShYs
Try it online!
1) % Implicit input. Get its first entry
G % Push input again
d % Differences
S % Sort
h % Concatenate
Ys % Cumulative sum. Implicit display
Jelly, 7 bytes
IṢ;@Ḣ+\
Try it online!
How it works
IṢ;@Ḣ+\ Main link. Argument: A (array)
I Increments; compute the deltas.
Ṣ Sort them.
Ḣ Head; pop and yield the first element of A.
;@ Concatenate with swapped arguments.
+\ Take the cumulative sum.
Mathematica, 40 bytes
FoldList[Plus,#&@@#,Sort@Differences@#]&
Pure function taking a list of (anythings) as input and returning a list. FoldList[Plus
starts with a number (in this case, #&@@#
, the first element of the input) and repeatedly adds elements of the self-explanatory list Sort@Differences@#
. This mimics the behavior of the built-in Accumulate
, but the first number would need to be prepended to the list of differences by hand, which makes the byte-count higher (as far as I can tell).