[Question]
  [
Given \$A = (a\_1,\dots,a\_k)\ k\ge2 \$ a sequence of positive integers, in which all elements are different.
Starting from \$i=2\$, while \$a\_i\in A:\$ *(until the last element)*
* If \$d=|a\_i-a\_{i-1}|\$ is not already in \$A\$, append \$d\$ to \$A\$
* Increase \$i\$
**Output** the completed sequence.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'")
## Example
```
In:  16 21 11 2
     16 21 11 2 5
      --^
     16 21 11 2 5 10
         --^
     16 21 11 2 5 10 9
            --^
     16 21 11 2 5 10 9 3
              --^
     16 21 11 2 5 10 9 3
                --^
     16 21 11 2 5 10 9 3 1
                   --^
     16 21 11 2 5 10 9 3 1 6
                     --^
     16 21 11 2 5 10 9 3 1 6
                       --^
     16 21 11 2 5 10 9 3 1 6
                         --^
Out: 16 21 11 2 5 10 9 3 1 6
```
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~6~~ 5 bytes
```
Δ¥Ä«Ù
```
[Try it online!](https://tio.run/##yy9OTMpM/f//3JRDSw@3HFp9eOb//9GGZjoKRoY6CoZAbBQLAA "05AB1E – Try It Online")
```
Δ         until the output doesn't change:
 ¥Ä           absolute differences
   «          concatenate to the original input
    Ù         only keep unique values
```
[Answer]
# [Python 2](https://docs.python.org/2/), 57 bytes
```
l=input()
d=0
for i in l:l+={abs(d-i)}-set(l);d=i
print l
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P8c2M6@gtERDkyvF1oArLb9IIVMhM08hxypH27Y6MalYI0U3U7NWtzi1RCNH0zrFNpOroCgzr0Qh5///aEMzHQUjQx0FQyA2igUA "Python 2 – Try It Online")
[Answer]
# [J](http://jsoftware.com/), ~~17~~ 16 bytes
```
(~.@,2|@-/\])^:_
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/Ner0HHSMahx09WNiNeOs4v9r/k9TMDRTMDJUMDRUMAIA "J – 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
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 40 bytes
```
->a,i=0{a|=[(p(a[i])-a[i+=1]).abs];redo}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5RJ9PWoDqxxjZao0AjMTozVlMXSGrbGsZq6iUmFcdaF6Wm5Nf@T4uONjTTMTLUMTTUMYqN/Q8A "Ruby – 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](https://codegolf.meta.stackexchange.com/a/24552/92901)) 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](https://www.ruby-lang.org/), 48 bytes
```
->a,i=0{a|=[(p(A).-a[i+=1]||0).abs]while A=a[i]}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5RJ9PWoDqxxjZao0DDUVNPNzE6U9vWMLamxkBTLzGpOLY8IzMnVcHRFigeW/s/LTra0EzHyFDH0FDHKDb2PwA "Ruby – Try It Online")
This version avoids the TypeError at a cost of 8 bytes.
[Answer]
# [R](https://www.r-project.org/), ~~68~~ 57 bytes
```
v=scan();while(any(F-(F=v)))v=unique(c(v,abs(diff(v))));v
```
[Try it online!](https://tio.run/##K/r/v8y2ODkxT0PTujwjMydVIzGvUsNNV8PNtkxTU7PMtjQvs7A0VSNZo0wnMalYIyUzLU0DJKNpXfbf0IzLyJDL0JDLiOs/AA "R – 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... 
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 14 bytes [SBCS](https://en.wikipedia.org/wiki/SBCS)
```
{⍵,⍵~⍨|2-/⍵}⍣≡
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v/pR71YdIK571LuixkhXH8isfdS7@FHnwv9pCo/aJig86u171NX8qHfNo94th9YbP2qb@KhvanCQM5AM8fAMBqoyNFMwMlQwNFQwAgA "APL (Dyalog Unicode) – 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.
[Answer]
# [Perl 5](https://www.perl.org/) -pl, 58 bytes
```
$d=abs$a[$;]-$a[++$;],/\b$d\b/||s/$/ $d/ while(@a=split)>$
```
[Try it online!](https://tio.run/##DcZBDkAwEADAr@xhD4RaK@EixAe8AIc2lWjS0KjExdstp5mwnr4WQdtpE1FP2C7qJ8v@5DQbtLOh54mEBGgJ7s35NRl0F4N3V9qjCDdQMTBD9R7hcsceRY11UXIpKvgP "Perl 5 – 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
```
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 9 bytes
```
e⟨:ọȯ¦|⟩°
```
[Try it online!](https://tio.run/##ASYA2f9nYWlh//9l4p@oOuG7jcivwqZ84p@pwrD//1sxNiAyMSAxMSAyXQ "Gaia – 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
```
[Answer]
# 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!](https://tio.run/##K0gtyjH9/9/BrdrBrdbWwc26WiXFNjGpWEPFLdogVhdIGsZqWqu4AYVrtbXzi4ACDm6xtiop1sWJlQrFGZlpJUBNDm52hmpqRakp@bVAYQe3//8NzRSMDBUMDRWM/uUXlGTm5xX/1/U11TMwNPivmwgA "Perl 5 – Try It Online\"/@ODflvIZmZEOpOaR3KGTj8960fSwwUghXJ0m4db3uQggBa@Tq/Gn6nt97TIhTdB1ZUnZNXEkZrirARSAGs687Wv@VjbzeLNg2cQ/ \"Perl 5 – 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.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 21 bytes
```
Ｗ⁻Ｅθ↔⁻κ∧λ§θ⊖λθＦι⊞θκＩθ
```
[Try it online!](https://tio.run/##LYo9C8IwFEV3f8UbXyAO6dClk@jiUOheOsT0SUJj0uZD@@9jKl64XDj3KC2D8tKW8tHGEmBvXI7YyxU3DpdH9DYn@tOlEjejrZPubqb9cG6kAr3IJaoP@4XDxhg8fQA0DIYc9SEurDsNwbiEVxkTVqUrZRxFy6ERHERtM03l/LZf "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｗ⁻Ｅθ↔⁻κ∧λ§θ⊖λθ
```
Generate the absolute differences between adjacent elements of the input and filter out those appearing in the input.
```
Ｆι⊞θκ
```
While there were any new values, push them to the input and repeat.
```
Ｉθ
```
Output the result.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jellylanguage/wiki), ~~8~~ 7 [bytes](https://github.com/DennisMitchell/jellylanguage/wiki/Code-page)
```
;IAQƲÐL
```
-1 byte thanks to *@JonathanAllan*.
[Try it online.](https://tio.run/##y0rNyan8/9/a0zHw2KbDE3z@//8fbWimY2SoY2ioYxQLAA)
**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)
```
[Answer]
# [K (Kona)](https://github.com/kevinlawler/kona), 14 bytes
```
{?x,_abs-':x}/
```
[Try it online!](https://tio.run/##y9bNzs9L/P8/zaravkInPjGpWFfdqqJW/3@agqGZgpGhgqGhgtF/AA "K (Kona) – Try It Online")
Similar to J and APL answers.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 10 bytes
```
u{+GaM.:G2
```
[Try it online!](https://tio.run/##K6gsyfj/v7Ra2z3RV8/K3ej//2hDMx0FI0MdBUMgNooFAA "Pyth – 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
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-h`](https://codegolf.meta.stackexchange.com/a/14339/), ~~10~~ 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
£=âUäa
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWg&code=oz3iVeRh&input=WzE2IDIxIDExIDJd)
```
£=â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
```
[Answer]
# [Raku](https://github.com/nxadm/rakudo-pkg), 45 bytes
```
{|$_,{|keys abs([-] @_[++$,$++])∖@_}...^!*}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/ukYlXqe6Jju1slghMalYI1o3VsEhPlpbW0VHRVs7VvNRxzSH@Fo9Pb04Ra3a/8WJlQppGtGGZjoKRoY6CoZAbBSraf0fAA "Perl 6 – 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
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~57~~ ~~51~~ 46 bytes
*-11 bytes thanks to [att](https://codegolf.stackexchange.com/users/81203)!*
```
#//.a_:>Keys@Counts@Join[a,Abs@Differences@a]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zg@19ZX18vMd7Kzju1stjBOb80r6TYwSs/My86UccxqdjBJTMtLbUoNS85tdghMVbtf0BRZl5JdFp0taGZjoKRoY6CIRAb1cbGWv8HAA "Wolfram Language (Mathematica) – 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.
[Answer]
# 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!](https://tio.run/##DcuxDoMgEADQX2G8i3ARhw4m6Ed0JAwXweYaA00118@nDm98b1Y@t698LldbLr3vAdhKGDEsoIGjJMdxGCThukMkolp@5lkuYCTOGXQZV52dYrKCM/et1bMdhY72gjv4hzWTt8bfpoTY/w "JavaScript (Node.js) – Try It Online")
[Answer]
# [Io](http://iolanguage.org/), 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!](https://tio.run/##DcexDoQgDADQX@nYJpiIww1H@JNbqkJoouAJJP17dHjDkzIifD38xhlaKjuq4fezU4jlDrwlFKNe4eo1IcrExGulnuXfg2Mv5JRGxENqQ/sxsFgD9rUQwXVLbkceDw "Io – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~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!](https://tio.run/##FYpBCsIwFAX37xQP8itJCoX3U3sCoZcobQRduHEh7vTuMa5mGOZ1fz@eV7UhrrVttxEZOwLxqSHyGFM8coqb/phygsk8WKG5zUiX2hfs/Aagi02n1rTQRYkOnSlnQU@dMwqXHw "Retina – 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
[Answer]
# [Java (JDK)](http://jdk.java.net/), 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!](https://tio.run/##ZU9Na8MwDL33V2g3e0nM0sMu@YCx02A99Th2cBMnVebYwVYyupLfnjlZYYwJhN7TE@@hTk4y6eqPBfvBOoIucDESanGf7f7tmtFUhNasYqWl93CQaOC6AxjGk8YKPEkKY7JYQx80diSHpn17B@laz7dTgGdr/Ngrl7@ip/zFkGqVK0tooFh0Ul4b6xgaAiwe4inDKM218PilGM84NuxOi8oaCvaeTcVB0lnIk2datIoYRhFPbpCH0kLWNZt4Ni/ZFv4nE3RgUIBRn/DknLxsask27IX0K2fpYwz7NIY09J7zH59GyKpSA7HV4rY7XjypXtiRxBD@Jm1@1Xk3L98 "Java (JDK) – Try It Online")
[Answer]
# [PHP](https://php.net/), ~~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!](https://tio.run/##DYqxCsMwDAV/JYQ32DgdlKFDHJMPKaaoQ1svilGCIV@veDnu4Oq/2rrVzu@uDpzA@msR0uUVAkqOVYucI2QYfZE3q/Ll0BJ/Dgd59A0lUPYT2G9Lz5zQopnR02YyIptv "PHP – Try It Online")
EDIT: 18 bytes saved with the help of Domenico Modica, thanks!
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 50 bytes
```
#//.l:_[___,b_,a_,___]:>l<>d/;FreeQ[l,d=Abs[b-a]]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7X1lfXy/HKj46Pj5eJyleJzFeB8iKtbLLsbFL0bd2K0pNDYzO0UmxdUwqjk7STYyNVfsfUJSZVxKd5qAcq1YXnJyYV1fNVW1opmNkqGNoqGNUy1X7HwA "Wolfram Language (Mathematica) – 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`](https://reference.wolfram.com/language/ref/StringJoin.html)) is short, flattens `List`s, 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|. *)
```
[Answer]
# 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 
```
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 47 bytes
```
[ [ dup differences vabs ∪ ] to-fixed-point ]
```
[Try it online!](https://tio.run/##LYuxDcIwFAV7pngLJJJTUMAAiIYGUUUpHPtbfJHYlv0TgRA9szAWixgFKE9357SRkMrpuD/sNrhQ8jRg1HKus2jhLGzyj2dayj9Mnk2wBBPGnr3@iphI5BYTe8F2tbpDrdEoKIUGj9KihZ0iLDtHibyhjFn3Ge/nCx0kVI6vZKsYlr8rRg8D6vIB "Factor – Try It Online")
## Explanation
* `[ ... ] to-fixed-point` Do `[ ... ]` to the input until it stops changing.
```
               ! { 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...)
```
]