g | x | w | all
Bytes Lang Time Link
034Juby240227T173930ZJordan
073PowerShell Core240301T000104ZJulian
014Uiua SBCS240221T060034Zchunes
047Factor + math.unicode220309T003607Zchunes
040Ruby200605T141625ZDingus
046Wolfram Language Mathematica200607T131529ZLegionMa
044APLNARS200709T023356Zuser5898
045Raku200708T044123ZJo King
050Wolfram Language Mathematica200708T025134Zatt
009Gaia200605T185125ZGiuseppe
078PHP200608T095213ZKaddath
058Perl 5 pl200605T175822ZKjetil S
090Java JDK200608T083935ZOlivier
066Retina200606T214034Zmath jun
006Japt h200606T094845ZShaggy
010Pyth200607T135546ZSok
00505AB1E200605T131115Zovs
059Io200606T084339Zuser9206
014K Kona200606T072913ZGalen Iv
016J200605T162623Zxash
014APL Dyalog Unicode200606T000504ZRGS
057R200605T201156ZDominic
007Jelly200605T134055ZKevin Cr
063JavaScript ES6200605T154626ZArnauld
021Charcoal200605T153812ZNeil
079perl M5.010 a200605T153657ZAbigail
057Python 2200605T134540Zovs

J-uby, 34 bytes

:!~&:|%(~:each_cons&2|:*&(+:-|:|))

Attempt This Online!

Explanation

:!~ & :| % (~:each_cons & 2 | :* & (+:- | :|))
:!~ &                                           # Until fixed point...
      :| % (                                 )  #   Union of input and...
                                    +:- | :|    #     absolute differences of...
            ~:each_cons & 2 | :* & (        )   #     consecutive pairs

PowerShell Core, 73 bytes

for($t=$args;$t[$i+2]){$t+=,($d=$t[$i++]-$t[$i]-replace'-')*!($d-in$t)}$t

Try it online!

Uiua SBCS, 14 bytes

⍥(◴⊂:⌵↘1°\+.)∞

Try it!

⍥(◴⊂:⌵↘1°\+.)∞
⍥(          )∞  # to fixed point
           .    # duplicate
      ↘1°\+     # differences
     ⌵          # abs
   ⊂:           # append
  ◴             # deduplicate

Factor + math.unicode, 47 bytes

[ [ dup differences vabs ∪ ] to-fixed-point ]

Try it online!

Explanation

               ! { 16 21 11 2 }
dup            ! { 16 21 11 2 } { 16 21 11 2 }
differences    ! { 16 21 11 2 } { 5 -10 -9 }
vabs           ! { 16 21 11 2 } { 5 10 9 }
∪              ! { 16 21 11 2 5 10 9 }   (set union)
               ! (etc...)

Ruby, 40 bytes

->a,i=0{a|=[(p(a[i])-a[i+=1]).abs];redo}

Try it online!

Takes an array a as input and adds unique new elements to it using the set append operator |=. Terminates by throwing a rescuable TypeError (which is now allowed) when attempting to subtract beyond the last element of the array. By that point all of the required output has already been printed to STDOUT.


Ruby, 48 bytes

->a,i=0{a|=[(p(A).-a[i+=1]||0).abs]while A=a[i]}

Try it online!

This version avoids the TypeError at a cost of 8 bytes.

Wolfram Language (Mathematica), 57 51 46 bytes

-11 bytes thanks to att!

#//.a_:>Keys@Counts@Join[a,Abs@Differences@a]&

Try it online! Pure function. Takes a list as input and returns another list as output. It just repeatedly appends the absolute differences to the end of the list and removes duplicates, until the list no longer changes.

APL(NARS), 22 chars, 44 bytes

{⍬≡k←∪⍵∼⍨∣2-/⍵:⍵⋄∇⍵,k}

test:

  f←{⍬≡k←∪⍵∼⍨∣2-/⍵:⍵⋄∇⍵,k}
  f 16 21 11 2 
16 21 11 2 5 10 9 3 1 6 
  f 2 3 4 5
2 3 4 5 1 

Raku, 45 bytes

{|$_,{|keys abs([-] @_[++$,$++])∖@_}...^!*}

Try it online!

Explanation

{                                         }    # Anonymous codeblock
                                    ...        # Generating a sequence
 |$_,                                          # Starting with the input
     {                             }           # Where we add to the sequence
            abs([-]            )               # The absolute difference
                    @_[++$,$++]                # Of the next pair of elements
      |keys                     ∖@_            # Set subtracting the sequence
                                    ...!*      # Continue until we run out of pairs

Wolfram Language (Mathematica), 50 bytes

#//.l:_[___,b_,a_,___]:>l<>d/;FreeQ[l,d=Abs[b-a]]&

Try it online!

Takes a sequence with any head. If the sequence is already complete, returns it unchanged. Otherwise, returns the completed sequence in a StringJoin.

<> (StringJoin) is short, flattens Lists, does not operate on integer (non-string) arguments, and is Flat. It's also not Orderless, so can store ordered data.

      _[             ]                           (* match a nonatomic expression with any head, *)
    l:                                           (*  and name it l. it contains: *)
            b_,a_,                               (*   two adjacent numbers, b,a, *)
        ___,      ___                            (*   as close to the front as possible, *)
                            /;                   (* subject to the condition that *)
                              FreeQ[l,d=Abs[b-a] (*  |b-a| is not in l. *)
#//.                  :>l<>d                     (* while the condition holds, append |b-a|. *)

Gaia, 9 bytes

e⟨:ọȯ¦|⟩°

Try it online!

Note that the documentation states that ȯ is sign of z when z is a numeric type, but it's actually abs...

e		# eval input as Gaia code (push as a list)
 ⟨	⟩°	# until there's no change:
  :		# dup the list
   ọ		# take the differences
    ȯ¦		# take the absolute values
      |		# and set union

PHP, 96 78 bytes

for($a=$argv;$n=$a[++$i];print"$n ")in_array($v=abs($n-$a[$i+1]),$a)?:$a[]=$v;

Try it online!

EDIT: 18 bytes saved with the help of Domenico Modica, thanks!

Perl 5 -pl, 58 bytes

$d=abs$a[$;]-$a[++$;],/\b$d\b/||s/$/ $d/ while(@a=split)>$

Try it online!

Ungolfed:

# with -pl the special var $_ is initialized with the input line string
while(
       @a = split    # array @a = the numbers currently in the $_ special var
   and $i++ < @a     # and the $i index (counter) is less than the length of @a
                     # in the golfed version $; is used instead of $i
){
  $d = abs $a[$i] - $a[$i-1] # $d = non-zero absolute diff btw element $i and $i-1
  and !/\b$d\b/              # and $d unseen before? \b is "borders" around digits
  and s/$/ $d/               # and if so append space and $d to $_
}
# with -pl the current $_ and \n is printed

Run:

$ echo 16 21 11 2 | perl -pl program_58_bytes.pl
16 21 11 2 5 10 9 3 1 6

Java (JDK), 90 bytes

l->{for(int i=0,v;i+1<l.size();)if(!l.contains(v=Math.abs(l.get(i++)-l.get(i))))l.add(v);}

Try it online!

Retina, 84 68 66 bytes

Edit: Saved 16 18 bytes thanks to @Neil !! This answer is now mildly competitive :P

\d+
*
^
# 
{`#( _+)(_*)(\1(_*).*)
$1$2#$3 $2$4
)D` _+
^ |#

_+
$.&

Try it online!

Not the shortest answer to this question, but it was fun to golf anyway :)

Explanation

\d+
*

Convert each input number to unary (using _'s)

^
#

Insert a # at the start of the input

{`
)`

Run the following 2 stages in a loop until the input stops changing:

#( _+)(_*)(\1(_*).*)
$1$2#$3 $2$4

Take the two numbers to the right of the # and remove the maximal number of _'s from each. This results in the absolute difference between the two numbers. Append this result to the end of the list.

D` _+

Deduplicate. If the number that was just added matches a number already in the list, remove it.

^ |#

_+
$.&

Once the loop breaks, remove the # and leading space, and convert back to decimal

Japt -h, 10 6 bytes

£=âUäa

Try it

£=âUäa     :Implicit input of array U
£          :Map
 =         :Reassign to U, for the next iteration
  â        :Setwise union of U and
   Uä      :Consecutive pairs of U
     a     :  Reduced by absolute difference

Pyth, 10 bytes

u{+GaM.:G2

Try it online!

u{+GaM.:G2   
u            Apply inner function until a repeat is found, current value G, starting with input
      .:G2     Find all sublists of length 2
    aM         Absolute difference between each pair
  +G           Append to G
 {             Deduplicate
             Implicit print

05AB1E, 6 5 bytes

Δ¥Ä«Ù

Try it online!

Δ         until the output doesn't change:
 ¥Ä           absolute differences
   «          concatenate to the original input
    Ù         only keep unique values

Io, 59 bytes

Port of the Python 2 answer.

method(x,a :=0;x foreach(i,x=x push((i-a)abs)unique;a=i);x)

Try it online!

K (Kona), 14 bytes

{?x,_abs-':x}/

Try it online!

Similar to J and APL answers.

J, 17 16 bytes

(~.@,2|@-/\])^:_

Try it online!

How it works

(~.@,2|@-/\])^:_
(           )^:_   until output does not change
     2   /\]       for each neighboring pair
      |@-          get the absolute difference
    ,              append the result to the list 
 ~.@               and remove duplicates

APL (Dyalog Unicode), 14 bytes SBCS

{⍵,⍵~⍨|2-/⍵}⍣≡

Try it online!

Same method as the J answer; I came up with this on my own :) also ended up being 3 bytes shorter, at least atm.

R, 68 57 bytes

v=scan();while(any(F-(F=v)))v=unique(c(v,abs(diff(v))));v

Try it online!

Edit: -9 bytes thanks to Giuseppe, and -2 more from (F-(F=v)) (had to be tested to see whether that would work...)

Boringly follows the instructions in the question, in the same order...

Jelly, 8 7 bytes

;IAQƲÐL

-1 byte thanks to @JonathanAllan.

Try it online.

Explanation:

         # Full program taking a single list argument
     ÐL  # Repeat until the result no longer changes,
    Ʋ    # using the previous four links as monads:
 I       #  Get the forward differences of the current list
  A      #  Take their absolute values
;        #  Merge it to the current list
   Q     #  And uniquify it
         # (after which it is output implicitly as result)

JavaScript (ES6), 63 bytes

f=(a,i=0)=>(v=a[i]-a[++i])?f([...new Set(a).add(v>0?v:-v)],i):a

Try it online!

Charcoal, 21 bytes

W⁻Eθ↔⁻κ∧λ§θ⊖λθFι⊞θκIθ

Try it online! Link is to verbose version of code. Explanation:

W⁻Eθ↔⁻κ∧λ§θ⊖λθ

Generate the absolute differences between adjacent elements of the input and filter out those appearing in the input.

Fι⊞θκ

While there were any new values, push them to the input and repeat.

Iθ

Output the result.

perl -M5.010 -a, 79 bytes

@F{@F}=@F;{$d=abs($F[0]-$F[1]);$F{$d}++or$F[@F]=$d;say shift@F;@F>1&&redo}say@F

Try it online!

Reads in a line of input, with the integers space separated. Outputs the sequence with each number on a different line.

How does it work? It gets the input in the array @F (due to the -a command line argument). In the hash %F it stores the numbers already in @F (here we use the given that all numbers in sequence are positive integers). Then, in a loop, we find the distance between the first two elements of @F; if not seen before, we add it to @F (and %F). We then remove the first element of @F and print it. We exit the loop if only one element is left, which is printed just before exiting the program.

The sequence can never contain a zero, as that requires two subsequent elements to be the same, but that is not allowed.

Python 2, 57 bytes

l=input()
d=0
for i in l:l+={abs(d-i)}-set(l);d=i
print l

Try it online!