[Question]
  [
*A continuation of [Inverse Deltas of an Array](https://codegolf.stackexchange.com/questions/101057/inverse-deltas-of-an-array)*
Your task is to take an array of signed 32 bit integers, recompile it with its deltas reversed.
## Example
The List,
```
18  19  17  20  16
```
has the deltas:
```
   1  -2   3  -4
```
which, when reversed, yields:
```
  -4   3  -2   1
```
then when recompiled, using yields:
```
18  14  17  15  16
```
which should be your return value.
Recompiling consists of taking the `C`, which is the first value of the array. In this case, `18`, and applying the deltas to it in order.
So `18 + -4` gives `14`, `14 + 3` gives `17`, and so on.
## Input/Output
You will be given a list/array/table/tuple/stack/etc. of signed integers as input through any standard input method.
You must output the modified data once again in any acceptable form, following the above delta reversing method.
You will receive N inputs where `0 < N < 10` where each number falls within the range `-1000 < X < 1000`
## Test Cases
```
1 2 3 4 5      -> 1 2 3 4 5
18 19 17 20 16 -> 18 14 17 15 16
5 9 1 3 8 7 8  -> 5 6 5 10 12 4 8
6 5 4 1 2 3    -> 6 7 8 5 4 3
```
## Notes
* As stated in above, you will always receive at least 1 input, and no more than 9.
* The first and last number of your output, will **always** match that of the input.
* Only Standard Input Output is accepted
* Standard loopholes apply
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the lowest byte-count wins!
* Have fun!
## And the winner is...
[Dennis!](https://codegolf.stackexchange.com/users/12012/dennis) Who firstly took the first place, then beat himself with a shorter solution, giving himself both the first and second place!
Honorable mention to [ais523](https://codegolf.stackexchange.com/users/62131/ais523) with their Jelly, that if not for Dennis getting in just before them, would have held the second place.
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
I;ḢṚ+\
```
[Try it online!](https://tio.run/nexus/jelly#@@9p/XDHooc7Z2nH/D/c/qhpjfv//9GGOgpGOgrGOgomOgqmsToK0YYWOgqGlkBsDpQxANJmIFFTHQWQGFglUAFQzgIkbAbUBNYKNSYWAA "Jelly – TIO Nexus")
### How it works
```
I;ḢṚ+\  Main link. Argument: A (array)
I       Increments; compute the deltas of A.
  Ḣ     Head; yield the first element of A.
 ;      Concatenate the results to both sides.
   Ṛ    Reverse the resulting array.
    +\  Compute the cumulative sum of the reversed array.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
.ịS_Ṛ
```
This uses the algorithm from [Glen O's Julia answer](https://codegolf.stackexchange.com/a/102162/12012).
[Try it online!](https://tio.run/nexus/jelly#@6/3cHd3cPzDnbP@H25/1LTG/f//aEMdBSMdBWMdBRMdBdNYHYVoQwsdBUNLIDYHyhgAaTOQqKmOAkgMrBKoAChnARI2A2oCa4UaEwsA "Jelly – TIO Nexus")
### How it works
```
.ịS_Ṛ  Main link. Argument: A (array)
.ị     At-index 0.5; retrieve the values at the nearest indices (0 and 1). Since
       indexing is 1-based and modular, this gives the last and first element.
  S    Compute their sum.
    Ṛ  Yield A, reversed.
   _   Subtract the result to the right from the result to the left.
```
[Answer]
# Julia, 24 bytes
```
!x=x[end]+x[]-reverse(x)
```
This is the "clever" way to solve the problem. The negative reverse of the array has the "deltas" reversed, and then you just need to fix the fact that it starts/ends at the wrong places.
[Answer]
## [Snowman](http://github.com/KeyboardFire/snowman-lang/) 1.0.2, 72 bytes
```
((}#0AaGwR#`wRaCaZ`0NdE`aN0AaG:dU,0aA|1aA,nS;aM`0wRaC|#0aA*|:#nA*#;aM*))
```
[Try it online!](https://tio.run/nexus/snowman#q@UytCgPSuAytASSic5AhjmUYWQAEzGDMrT@a2jUKhs4JrqXByknlAclOidGJRj4pbgmJPqBRK1SQnUMEh1rDBMddfKCrRN9EwxAimqUgYJaNVbKeY5aykBRLU3N/8olwcUB/wE "Snowman – TIO Nexus")
This is a subroutine that takes input from and outputs to the current permavar.
```
((
  }       enable variables b, e, and g
  #       store the input in variable b
  0AaG    remove the first element (take indices > 0)
  wR      wrap the array in another array
  #`wRaC  concatenate with the original input array
  aZ      zip (transpose); we now have pairs of elements
  `0NdE   obtain the number -1 (by decrementing 0)
  `aN     reverse the zipped array
  0AaG    remove first (there is one fewer delta than array elements)
  :       map over the array of pairs:
    dU     duplicate; we now have b=[x,y] e=[x,y]
    ,0aA   move the copy and get the first element; b=x g=[x,y]
    |1aA   get the second element from the copy; b=y g=x
    ,nS    subtract; we now have b=y-x which is returned from the map
  ;aM     (map)
  `0wRaC  prepend a zero (in preparation for the next step)
  |#0aA   get the first element of the original array
  *       store this in the permavar
  |:      map over the array of deltas with 0 prepended:
    #       store the permavar in e
    nA      add the delta and the permavar
    *#      make this the new value of the permavar
  ;aM     (map)
  *       "return" the resulting array from the subroutine
))
```
[Answer]
## JavaScript (ES6), ~~45~~ 37 bytes
```
a=>a.reverse(z=a[0]).map(e=>z+a[0]-e)
```
Port of @JHM's Mathematica answer. (I'm sure I could have derived it myself, but not at this time of night.) Edit: Saved 8 bytes thanks to @edc65.
[Answer]
# Mathematica, 23 bytes
```
#&@@#+Last@#-Reverse@#&
```
Unnamed function. The result is simply: reverse( (first element) + (last element) - (each element) ).
[Answer]
# Python 2, ~~96~~ ~~74~~ ~~54~~ 44 bytes
```
lambda l:[l[0]+l[-1]-j for j in l][::-1]
```
Input is given as an array surrounded by square brackets. Output is in the same format.
*Thanks to @Kade for saving ~~22~~ 42 bytes by using a much more simple method than whatever I was doing before!*
*Thanks to @Sherlock9 for saving 10 bytes by eliminating the index counter from the list comprehension!*
Great, now if I golf it anymore I'll get the "crossed out 44 is still 44" problem. ;\_;
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 8 bytes
```
¬s¤sR(++
```
[Try it online!](http://05ab1e.tryitonline.net/#code=wqxzwqRzUigrKw&input=WzE4LCAxOSwgMTcsIDIwLCAxNl0)
Translation of my MATL answer, second approach.
```
¬    % Implicit input. Head, without consuming the input
s    % Swap
¤    % Tail, without consuming the input
s    % Swap
R(   % Reverse and negate
++   % Add head and tail of input to reversed and negated input. Implicitly display
```
[Answer]
## R, 37 30 bytes
Edit: Now using the approach in Glen O's Julia answer
```
x=scan();x[1]+tail(x,1)-rev(x)
```
Old:
```
x=scan();cumsum(c(x[1],rev(diff(x))))
```
Reads input, compute deltas, concatenate with first element and calculate the cumulative sum.
[Answer]
# [MATL](http://github.com/lmendo/MATL), 8 bytes
```
1)GdPhYs
```
[Try it online!](http://matl.tryitonline.net/#code=MSlHZFBoWXM&input=WzE4ICAxOSAgMTcgIDIwICAxNl0)
This is direct application of the definition. Consider input `[18 19 17 20 16]` as an example.
```
1)     % Implicit input. Get its first entry
       % STACK: 18
G      % Push input again
       % STACK: 18, [18 19 17 20 16]
d      % Consecutive differences
       % STACK: 18, [1 -2 3 -4]
P      % Reverse
       % STACK: 18, [-4 3 -2 1]
h      % Concatenate
       % STACK: [18 -4 3 -2 1]
Ys     % Cumulative sum. Implicitly display
       % STACK: [18 14 17 15 16]
```
---
Different approach, same byte count:
```
P_G5L)s+
```
[Try it onllne!](http://matl.tryitonline.net/#code=UF9HNUwpcys&input=WzE4ICAxOSAgMTcgIDIwICAxNl0)
Reversed and negated array plus the first and last entries of the original array.
```
P_     % Implicit inut. Reverse and negate
G      % Push input again
5L)s   % Sum of first and last entries
+      % Add to reversed and negated array. Implicitly display
```
[Answer]
# Japt, 8 bytes
```
Ô®nUÌ+Ug
```
[Run it online](https://ethproductions.github.io/japt/?v=1.4.6&code=1K5uVcwrVWc=&input=WzE4LCAxOSwgMTcsIDIwLCAxNl0KCi1R)
[Answer]
# Pyth - 10 bytes
```
sM._+hQ_.+
```
[Test Suite](http://pyth.herokuapp.com/?code=sM._%2BhQ_.%2B&test_suite=1&test_suite_input=1%2C+2%2C+3%2C+4%2C+5%0A18%2C++19%2C++17%2C++20%2C++16%0A5%2C+9%2C+1%2C+3%2C+8%2C+7%2C+8%0A6%2C+5%2C+4%2C+1%2C+2%2C+3&debug=0).
[Answer]
# [아희(Aheui)](http://esolangs.org/wiki/Aheui), 3 \* 21 chars + 2 "\n" = 65 bytes
```
빪쑥쌳텆슉폎귁삯씬희
뿓팤팧쎢싺솎
싺싹삭당뽔
```
Assumes input in stack 아. The output will be stored in stack 안.
**If you want to try this code:**
At the end of the first line of this code, add the character `벙` length(n)-times (i.e. if the input is 7 integers, insert it 7 times). For each prompt, type one integer:
```
어우
우어
빪쑥쌳텆슉폎귁삯씬희
뿓팤팧쎢싺솎
싺싹삭당뽔
```
[Try it here! (copy and paste the code)](http://jinoh.3owl.com/aheui/jsaheui_en.html)
**Example**
For `1, 2, 3, 4, 5`:
```
어우벙벙벙벙벙
우어
빪쑥쌳텆슉폎귁삯씬희
뿓팤팧쎢싺솎
싺싹삭당뽔
```
and then type `1`, `2`, `3`, `4`, and `5` (there will be 5 prompts).
**Alternative Version (65 bytes)**
```
빠쑥쌳터슉펴ㅇ삯씬희
뿌파파쎢싺솎
싺싹삭다뽀
```
[Answer]
## C# 42 bytes
Takes an `int[]` and returns an `IEnumerable<int>`.
```
a=>a.Select(v=>a[0]+a.Last()-v).Reverse();
```
(This is actually just a ported version of JHM's version..)
[Answer]
# TSQL, 200 bytes
Table variable used as input
```
DECLARE @ table(a int, b int identity)
INSERT @ values(5),(9),(1),(3),(8),(7),(8);
WITH c as(SELECT*,rank()over(order by b desc)z FROM @)SELECT g+isnull(sum(-f)over(order
by b),0)FROM(SELECT sum(iif(c.b=1,c.a,0))over()g,d.a-lead(d.a)over(order by d.b)f,c.b
FROM c,c d WHERE c.b=d.z)d
```
**[Try it out](https://data.stackexchange.com/stackoverflow/query/590898/reverse-deltas-of-an-array)**
[Answer]
# PHP, ~~60~~ ~~56~~ 52 bytes
-4 bytes thanks to @user59178
```
for($a=$argv;--$argc;)echo$a[1]+end($a)-$a[$argc],_;
```
operates on command line arguments, uses underscore as separator. Run with  
`php -r '<code>' <space separated numbers>`
[Answer]
# [Perl 6](https://perl6.org), ~~48 33~~ 30 bytes
```
{[\+] .[0],|.reverse.rotor(2=>-1).map({[-] @_})}
```
```
{.reverse.map: {.[0]+.[*-1]-$^a}}
```
```
{[R,] .map: {.[0]+.[*-1]-$^a}}
```
[Try it](https://tio.run/nexus/perl6#dZBNboMwEIX3PsVbpA3/iRMgtDS0B@iq6g5SCYErIQFBMVSNIk7UW/RidHAgu1oay37zzfOMOynw5TtZyKoz7rNjLrAfLvGbdYBTpc0jLk68PphObNj8YC8@0r4fiHxphWyxR1nUQmr6hDKgWtEGLJ6KuunaaDzvoWFpL5@R5CZ0E3dIpKmoRBqUiZZ0gDHVie9GZK3Io3/rViFtmvn7Mz@iO6@FbK1JuxlcZdYz1tGQ79RwyJoyrWGq7kP2eTxNg9gRtESZWUhmA10NVEg7F6Ipzxg/R1PQ/OBMWlCy04hTyfqBY4MtXHhQi8xvCuMB@AP4Dps1uK9ypLijwj1SmAdKExxgRzECHnwKTvyGLAI23tzJ8mrvK3ZUt38 "Perl 6 – TIO Nexus")
## Expanded:
```
{  # bare block lambda with implicit parameter ｢$_｣
  [R,]               # reduce the following using the comma operator [R]eversed
                     # (short way to do the same thing as ｢reverse｣)
    .map:            # map the input (implicit method call on ｢$_｣
      {              # bare block lambda with placeholder parameter ｢$a｣
          .[     0 ] # the first value of ｢$_｣ (implicit “method” call)
        + .[ * - 1 ] # add the last value of ｢$_｣ (implicit “method” call)
        -     $^a    # declare the parameter and subtract it from the above
      }
}
```
The `*-1` is also a lambda expression of type WhateverCode, where the `*` is the only positional parameter.
[Answer]
# [Desmos](https://desmos.com/calculator), 34 bytes
```
f(l)=l[1]+l[k]-l[k...1]
k=l.length
```
Uses the trick from the [Mathematica answer](https://codegolf.stackexchange.com/questions/102139/reverse-deltas-of-an-array/102142#102142). Go check that answer out too!
[Try It On Desmos!](https://www.desmos.com/calculator/wodvmoq0df)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/jdkanjddtq)
[Answer]
# [Factor](https://factorcode.org/), 39 bytes
```
[| s | s first s last + s reverse n-v ]
```
[Try it online!](https://tio.run/##PYxLCsJAEET3c4rai8GJ@RkPIG7ciCtxMYQOBvJzegxIzNnHjhgLqqp5FF2awnXWX87H0yEH0@NJbUGMxrj7N4KB5gWj7gpTM3pLzr16W7UOe6VGBdEIjRBbRIgxLSSD3kGnCDfQyR/HECjTDKl4oYnw6PdkUpPy1zcYs8vKspOujdRKDksDWSa06wE335gegf8A "Factor – Try It Online")
A rare problem where local variables win out over stack shuffling. Note that `s` is the only variable; `n-v` is the name of a word that subtracts a vector from a number. Uses the same logic as JungHwan Min's [Mathematica answer](https://codegolf.stackexchange.com/a/102142/97916).
[Answer]
# [Julia 0.4](http://julialang.org/), 32 bytes
```
!x=[x[];x|>diff|>flipud]|>cumsum
```
[Try it online!](https://tio.run/nexus/julia#LYzBCoMwEETvfsUoCAorNG1NLaWh/5HmVBsIaCpaIYf8e7pKB5aBNzOb8nDXQZtbiKp31kZlBzetvYnqtY7LOib7mRHgPCotCEfCiXAmtIagRUcQV74LJwd2udGWsLG9yQXOug1LHu3T/xtTZ2A9ptn5r62KshFyQaNQLk9fEAIhD3X29n36AQ "Julia 0.4 – TIO Nexus")
[Answer]
# BASH, 71 bytes
```
s=$1
echo $s
for i in `seq ${#@} -1 2`;{
echo $[s=s+${!i}-${@:i-1:1}]
}
```
[Answer]
# C++14, 103 bytes
As unnamed lambda, requiring its input to have `rbegin`, `rend`, `back` and `push_back` like the containers `vector`, `deque` or `list`.
Using the approach from Glen O's [Julia answer](https://codegolf.stackexchange.com/a/102162/53667)
```
[](auto c){decltype(c)d;for(auto i=c.rbegin()-1;++i!=c.rend();)d.push_back(c[0]+c.back()-*i);return d;}
```
Ungolfed and usage:
```
#include<iostream>
#include<vector>
//declare generic function, return is deduced automatically
auto f=[](auto c){
  //create fresh container of the same type as input
  decltype(c)d;
  
  //iterate through the reverse container
  for(auto i=c.rbegin()-1;++i!=c.rend();)
    //add the first and last element minus the negative reverse
    d.push_back(c[0]+c.back()-*i);
  return d;
}
;
int main(){
  std::vector<int> a={18,  19,  17,  20,  16};
  auto b = f(a);
  for(auto&x:b)
    std::cout << x << ", ";
  std::cout<<"\n";
}
```
[Answer]
# Haskell, 33 bytes
Uses the same logic as JHM:
```
f a=map(head a+last a-)$reverse a
```
Quite readable as well.
[Answer]
# [Convex](http://github.com/GamrCorps/Convex), 10 [bytes](https://en.wikipedia.org/wiki/Windows-1252)
```
_î\(@¥+¡p;
```
[Try it online!](http://convex.tryitonline.net/#code=X8OuXChAwqUrwqFwOw&input=&args=WzE4IDE5IDE3IDIwIDE2XQ)
[Answer]
**Clojure, 101 bytes**
```
(fn[c](conj(map #(-(first c)%)(reductions +(reverse(map #(apply - %)(partition 2 1 c)))))(first c))))
```
Pretty much follows the description:
```
(def f (fn[c]
         (conj
           (->> c
                (partition 2 1)
                (map #(apply - %))
                reverse
                (reductions +)
                (map #(-(first c)%)))
           (first c))))
```
[Answer]
# Java 7, 96 bytes
```
int[]c(int[]a){int l=a.length,i=1,r[]=a.clone();for(;i<l;r[i]=r[i-1]+a[l-i]-a[l-++i]);return r;}
```
**Explanation:**
```
int[] c(int[] a){     // Method with integer-array parameter and integer-array return-type
  int l=a.length,     //  Length of input array
      i=1,            //  Index (starting at 1, although Java is 0-indexed)
      r[]=a.clone();  //  Copy of input array
  for(; i<l;          //  Loop over the array
    r[i] =            //   Replace the value at the current index in the copied array with:
      r[i-1]          //    The previous value in this copied array
      + a[l - i]      //    plus the opposite value in the input array
      - a[l - ++i])   //    minus the value before the opposite value in the input array (and increase the index)
  ;                   //  End the loop (implicit / no body)
  return r;           //  Return the result array
}                     // End of method
```
**Test code:**
[Try it here.](https://tio.run/nexus/java-openjdk#rY5BTsMwEEX3OcUsbWVi1YW0QW4WHIBVl5EXJoRi5DqVMymqopw9DC3iAnTjL3lm3vtLG9wwwMuUAQzkyLfgIzW2FddwcuKEUDsVunigD/S1xtRY/mhDHzshzXufhPG7YFLjbc1PoW3umlB4W/xEnnsrTepoTBGSmTNWncbXwKpf47n3b3B0Poo9JR8PjQUW8xrA/jJQd1T9SOrEIwpRfLqzUyP5oJ5TcpdBUX87E62I3det/wS6Qv2EeovrFeoNzFJK818krvEBH7G8C61Erse8CrdY3YW4wZLbXVv@8eZsXpZv)
```
class M{
  static int[]c(int[]a){int l=a.length,i=1,r[]=a.clone();for(;i<l;r[i]=r[i-1]+a[l-i]-a[l-++i]);return r;}
  public static void main(String[] a){
    System.out.println(java.util.Arrays.toString(c(new int[]{ 18,19,17,20,16 })));
    System.out.println(java.util.Arrays.toString(c(new int[]{ 1,2,3,4,5 })));
    System.out.println(java.util.Arrays.toString(c(new int[]{ 5,9,1,3,8,7,8 })));
    System.out.println(java.util.Arrays.toString(c(new int[]{ 6,5,4,1,2,3 })));
  }
}
```
**Output:**
```
[18, 14, 17, 15, 16]
[1, 2, 3, 4, 5]
[5, 6, 5, 10, 12, 4, 8]
[6, 7, 8, 5, 4, 3]
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 11 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous tacit prefix function.
```
+\⊃,∘⌽2-⍨/⊢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///XzvmUVezzqOOGY969hrpPupdof@oa9H/tEdtEx719j3qm@rpD5Q/tN74UdtEIC84yBlIhnh4Bv9PUzBUMFIwVjBRMOUCsi0UDC0VDM0VjAwUDM2AAqYKQC5Q2kLBXMECyDcDiphAtAAA "APL (Dyalog Unicode) – Try It Online")
`+\` cumulative sum of
`⊃` the first element of the argument
`,` followed  
`∘` by  
`⌽` the reversal of
`2-⍨/` the pairwise difference of
`⊢` the argument
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
```
m`-§+←→¹↔
```
[Try it online!](https://tio.run/##ASkA1v9odXNr//9tYC3CpyvihpDihpLCueKGlP///1s1LDksMSwzLDgsNyw4XQ "Husk – Try It Online")
]