17
1
Inverse Deltas of an Array
Your task is to, given an array of signed 32 bit integers, recompile it with its inverse deltas. For example, the list
1 3 4 2 8
holds the deltas:
2 1 -2 6
which are then negated, yielding:
-2 -1 2 -6
and recompiled, yielding:
1 -1 -2 0 -6
as the final result.
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 inversion method.
You will receive N inputs where 0 < N < 10
where each number falls within the range -1000 < X < 1000
Test Cases
5 6 7 8 -> 5 4 3 2
1 3 4 2 8 -> 1 -1 -2 0 -6
32 18 25 192 199 -> 32 46 39 -128 -135
Notes
- You are not restricted to the delta based method: if you can work out the easier method (which shouldn't be too hard), you're free to use it.
- As stated in above, you will always receive at least 1 input, and no more than 9.
- The first number of the output must always be the first number of the input, if this is not the case, your method is incorrect.
- Only Standard Input Output is accepted
- Standard loopholes apply
- This is code-golf, so the lowest byte-count wins!
- Have fun!
We have a winner.
Dennis's Jelly Answer at a Tiny 3 Bytes has taken home the gold, due to the fact that I am under the impression it cannot be beaten.
I was mildly disappointed I didn't get to see an answer based on the original spec, however, I may later put a bounty on precisely that.
1I don't understand the recompile step? How do you get from -2, -1, 2, -6 to 1, -1, -2, 0, -6?? – Fogmeister – 2016-11-25T07:45:40.433
@Fogmeister you start from the same initial value and then apply these differences instead of the original ones. – Martin Ender – 2016-11-25T07:59:49.490
Standard Input Output - I haven't heard that used in a challenge before, but I infer that it does NOT mean stdin/stdout, since otherwise all replies here seem to be wrong. I guess it means that you can't take input as Church numerals or something? Anyway, if that's what it means, it should probably be called something else since standard output/input has another meaning as well. – Harald Korneliussen – 2016-11-25T08:16:32.050
@MartinEnder 1+0=1, 3-2=-1?, 4-1=-2?? That's what I thought but those numbers don't add up. Oh! Never mind. I just saw it. You create a new array starting at the original value but with the new differences. So 1 with a diff of -2 goes to -1, then with a diff of -1 this goes to -2 and so on. – Fogmeister – 2016-11-25T08:19:57.747
1
@HaraldKorneliussen It's probably referring to this (and that's likely what everyone is assuming)
– Martin Ender – 2016-11-25T08:37:17.180@Fogmeister You start from
1 3 4 2 8
. Then3 - 1 = 2, 4 - 3 = 1, 2 - 4 = -2, 8 - 2 = 6
, gives2 1 -2 6
. You negate those to get-2 -1 2 -6
. Then you start from1
and apply these differences:1 + (-2) = -1, -1 + (-1) = -2, -2 + 2 = 0, 0 + (-6) = -6
, so you end up with1 -1 -2 0 -6
. – Martin Ender – 2016-11-25T08:39:30.477does "any acceptable format" include outputting backwards? – FlipTack – 2016-11-25T21:12:07.913
also, you said the input would be signed integers at the beginning, and unsigned integers later on. – FlipTack – 2016-11-25T22:20:24.107
All these questions use one function sxs->s in list... – RosLuP – 2016-11-26T17:09:17.440
@Flp.Tkc Missed that, sorry. Signed was the intention, although none of the test cases have signed inputs. – ATaco – 2016-11-27T22:12:02.690