19
\$\begingroup\$

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 , 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.

\$\endgroup\$
10
  • 1
    \$\begingroup\$ I don't understand the recompile step? How do you get from -2, -1, 2, -6 to 1, -1, -2, 0, -6?? \$\endgroup\$
    – Fogmeister
    Nov 25, 2016 at 7:45
  • 1
    \$\begingroup\$ @Fogmeister you start from the same initial value and then apply these differences instead of the original ones. \$\endgroup\$ Nov 25, 2016 at 7:59
  • \$\begingroup\$ 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. \$\endgroup\$
    – user61264
    Nov 25, 2016 at 8:16
  • \$\begingroup\$ @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. \$\endgroup\$
    – Fogmeister
    Nov 25, 2016 at 8:19
  • 1
    \$\begingroup\$ @HaraldKorneliussen It's probably referring to this (and that's likely what everyone is assuming) \$\endgroup\$ Nov 25, 2016 at 8:37

32 Answers 32

1
2
0
\$\begingroup\$

J, 7 bytes

-~+:@{.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Desmos, 12 bytes

f(l)=2l[1]-l

Try It On Desmos!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.