[Question]
  [
Your task today is to apply a wave to an array of numbers. A wave looks like this: `[1, 0, -1, 0, 1, 0, -1, 0, 1...]` Applying it to a given array means adding together the first elements, the second elements, etc.
More precisely:
Your program or function will receive an array of integers. It must print or return an equally sized array with `1` added to the 1st, 5th, 9th, etc. element of the original array, `-1` added to the 3rd, 7th, 11th, etc. element of the original array, and the rest of the elements should be left untouched.
The input array is guaranteed to have at least one element. 
Test cases: 
```
Input                               | Output
[0]                                 | [1]
[-1]                                | [0]
[-4, 3, 0, 1, 7, 9, 8, -2, 11, -88] | [-3, 3, -1, 1, 8, 9, 7, -2, 12, -88]
[0, 0, 0, 0, 0]                     | [1 ,0 ,-1 ,0 ,1]
[1, 1]                              | [2, 1]
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest code wins!
  
[Answer]
# [LOGO](https://sourceforge.net/projects/fmslogo/), 18 bytes
```
[map[?+sin 90*#]?]
```
There is no "Try it online!" link because all online LOGO interpreter does not support template-list.
That is a template-list (equivalent of lambda function in other languages).
Usage:
```
pr invoke [map[?+sin 90*#]?] [-4 3 0 1 7 9 8 -2 11 -88]
```
(`invoke` calls the function, `pr` prints the result)
prints `[-3 3 -1 1 8 9 7 -2 12 -88]`.
Explanation (already pretty understandable):
```
 map[?+sin 90*#]?       map a function over all the items of the input
              #         the 1-based index of the element in the input
       sin 90*#         equal to the required wave
     ?                  looping variable
     ?+sin 90*#         add the wave to the input
```
[Answer]
# [Haskell](https://www.haskell.org/), 26 bytes
```
zipWith(+)$cycle[1,0,-1,0]
```
[Try it online!](https://tio.run/##LYpNCsIwGESvMosulE4gsQXjoufoImQR@kODaQ3aTb18/BRheDDzZgmv@5RSKXP3jrmP@3Kqz9VwDGlyhppK4Msa4oYO4wP5GbcdFdaQMcM57emU@aIlGkIThrgSN8IS6iJdBmWtfPTP/yNdhPG@fAA "Haskell – Try It Online") (runs all test cases)
Explanation:
```
zipWith(+)$cycle[1,0,-1,0]  -- anonymous tacit function
zipWith(+)                  -- pairwise addition between input list
          $cycle[1,0,-1,0]  -- and an infinitely-cycling "wave" list
```
[Answer]
## JavaScript (ES6), 28 bytes
```
a=>a.map((x,i)=>x-(i%4-1)%2)
```
The calculation goes like this:
```
i%4  -1  %2
0    -1  -1
1     0   0
2     1   1
3     2   0
```
The last bit taking advantage of the fact that in JS, a negative number when modulated will retain its negative sign (i.e. `-5 % 3 -> -2`, instead of `1` as it would be in Python).
[Answer]
# Mathematica, ~~26~~ ~~23~~ 22 bytes
```
Im[I^Range@Tr[1^#]]+#&
```
[Try it online!](https://tio.run/##y00sychMLv6fZvvfMzfaMy4oMS891cEnNS@9JMNBOVZbWe1/QFFmXolDmkO1romOgrGOgoGOgqGOgrmOgqWOgoWOgq4RkA8U0LWwqP0PAA "Mathics – Try It Online") (Mathics)
Note: The TIO link is for the 23-byte version, the 22-byte version is not Mathics-compatible.
[Answer]
# [Python 2](https://docs.python.org/2/), 40 bytes
```
i=2
for x in input():print~-x+i%5%3;i*=2
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P9PWiCstv0ihQiEzD4gKSks0NK0KijLzSup0K7QzVU1Vja0ztWyBKqN1TXQUjHUUDHQUDHUUzHUULHUULHQUdI2AfKCAroVFLAA "Python 2 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
Jı*Ċ+
```
[Try it online!](https://tio.run/##y0rNyan8/9/ryEatI13a////j9Y10VEw1lEw0FEw1FEw11Gw1FGw0FHQNQLygQK6FhaxAA "Jelly – Try It Online")
### How it works
```
Jı*Ċ+  Main link. Argument: A (array)
J      Indices; yield [1, ..., len(A)].
 ı*    Elevate the imaginary unit to the power 1, ..., len(A), yielding
       [0+1i, -1+0i, 0-1i, 1+0i, ...].
   Ċ   Take the imaginary part of each result.
    +  Add the results to the corresponding elements of A.
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~11~~ 8 bytes
```
Jyn:^Yj+
```
Try it at [**MATL Online!**](https://matl.io/?code=Jyn%3A%5EYj%2B&inputs=%5B-4%2C+3%2C+0%2C+1%2C+7%2C+9%2C+8%2C+-2%2C+11%2C+-88%5D&version=20.2.2)
### Explanation
```
J     % Push 1j (imaginary unit)
      % STACK; 1j
y     % Implicit input. Duplicate from below
      % STACK: [-4 3 0 1 7 9 8 -2 11 -88], 1j, [-4 3 0 1 7 9 8 -2 11 -88]
n     % Number of elements
      % STACK: [-4 3 0 1 7 9 8 -2 11 -88], 1j, 10
:     % Range
      % STACK: [-4 3 0 1 7 9 8 -2 11 -88], 1j, [1 2 3 4 5 6 7 8 9 10]
^     % Power, element-wise
      % STACK: [-4 3 0 1 7 9 8 -2 11 -88], [1j -1 -1j 1 1j -1 -1j 1 1j -1]
Yj    % Imaginary part
      % STACK: [-4 3 0 1 7 9 8 -2 11 -88], [1 0 -1 0 1 0 -1 0 1 0]
+     % Add, element-wise. Implicit display
      % STACK: [-3 3 -1 1 8 9 7 -2 12 -88]
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 16 bytes
```
-1Jm2$$¦+2Jm4$$¦
```
[Try it online!](https://tio.run/##y0rNyan8/1/X0CvXSEXl0DJtI69cExDj////0QY6UBgLAA "Jelly – Try It Online")
heh I'm sure this is too long
# Edit
I know a 5 byte solution is possible but my wifi appears to be starting to cut me off so I'll golf this tomorrow. If someone posts the short Jelly solution before I can golf this, that's fine with me; I'll just keep this here for reference as to ~~how bad I am at Jelly lol~~ another way of doing it. I mean, I *could* just look at the link Phoenix posted in the comments, but since I'm still learning, I don't want to look at the solution until I've figured it out myself. This might cost me reputation but the learning is what I'm here for :)))
[Answer]
# [R](https://www.r-project.org/), ~~29~~ 24 bytes
```
(l=scan())+Im(1i^seq(l))
```
[Try it online!](https://tio.run/##K/r/XyPHtjg5MU9DU1PbM1fDMDOuOLVQI0dT87@hgpGCsYKJgqmCmYK5goWCpYKhwX8A)
[Answer]
# [Python 2](https://docs.python.org/2/), ~~50~~ 42 bytes
Saved 8 bytes thanks to @Sisyphus!
```
lambda l:map(sum,zip(l,[1,0,-1,0]*len(l)))
```
[Try it online!](https://tio.run/##jZJRa4MwEMff/RT3ljguRdtBneBgL4PBHvZug7g20kBMxMTBtu6zd0m0DAajEzHJ/373v/PI8O6ORq/P3Wh6aJpuctMomgZkP5jRwTBK7byq904anXTV7qza/vXQgir7dqB26vFDDlRhnWOGzH/4jRKaqjRNz05YZ6ECQkhSZxyuPSeoc57ULOf/ILNA3iJsEDKEHGGLcIdQILC1P3uBFQUPJNtEyjcXsCJi2wVbz5hvL9osL/@zPcAM/G/GJfQaPPnVXkMlnoQxJJ0ZQUktQGqI81nZQUlHyU6TtExCQgxXcbkETySNIdmBNi6G/ABK2BvtpJ7EnHcMwxZvraILMCeNv/T8oougd9TnzcLQWhs18uJ3JQnlIlRFD6GsAPL48PRckpkPt4POWRjKIxDG7gkupv4YPS6@P8azVQn2aCZ1gFcBn19k5WfTt476Wv7yfAM "Python 2 – Try It Online")
### 53 bytes
```
lambda l:[int(x+(1j**i).real)for i,x in enumerate(l)]
```
[Try it online!](https://tio.run/##jZJRS8MwFIXf@yvuW5KZjHYTVgsVfBEEH3zv8tC5lEWydDSZTJy/veYmHYIgsxTSnPvdcy@HHj78rrfLsavXo2n3m20Lpmq09fR0Q4u32Uyz@aBaw7p@AM1PoC0oe9yrofWKGiZHr5x3UAMhJGtyCdeeMzSFzBpRyH@QOZK3HJYccg4FhxWHOw4lB7EI9yCIspRIimWkRBGxMmKrCVskLKwXbaZX/rke8By4SAfuip7y6q44SWYYQ4ZhGW0VphXzmbuD0Z6StSWsyrAhlut4XIpnwmJJd2B7H0shgApee@u1ParUt8Ow1Xtr6ASkpuGXXlx0hXpHQ18SDq1zUSMv4asiOC5CdfRQxikgjw9PzxVJ/IB/Q@riOJ4DEeKe8Mk0XKPHxffHOFlV4Hb90Wxho@Dzi8xDNvvW0zCLsfEb)
[Answer]
# [Haskell](https://www.haskell.org/), 26 bytes
*@Mego beat me to this solution*
```
zipWith(+)$cycle[1,0,-1,0]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P822KrMgPLMkQ0NbUyW5MjknNdpQx0BHF0jE/s9NzMyzLSjKzCtRSQMKG@kY65jomOqYxf4HAA "Haskell – Try It Online")
This is what Haskell is great at. This declares a point-free function that zips the input with an infinite list.
# [Haskell](https://www.haskell.org/), 56 bytes
Here's a solution that uses complex numbers. Not very competitive because of the import but never the less pretty cool.
```
import Data.Complex
zipWith((+).realPart.((0:+1)^))[0..]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRzzk/tyAntYKrKrMgPLMkQ0NDW1OvKDUxJyCxqERPQ8PASttQM05TM9pATy/2f25iZp5tQVFmXokKMeqjdU10FIx1FAx0FAx1FMx1FCx1FCx0FHSNgHyggK6FRex/AA "Haskell – Try It Online")
[Answer]
# Mathematica, 19 bytes
```
i=1;#+Im[i*=I]&/@#&
```
### Explanation
```
i=1;#+Im[i*=I]&/@#&
i=1;                 (* set variable i to 1 *)
               /@#   (* iterate through the input: *)
    #+Im[i   ]&      (* add the imaginary component of i... *)
          *=I        (* multiplying i by the imaginary unit each iteration *)
```
Note: `i=1` appears outside of the function, which is okay [per this meta consensus](https://codegolf.meta.stackexchange.com/q/5532/60043).
[Answer]
# J, 12 bytes
```
+1 0 _1 0$~#
```
[Try it online!](https://tio.run/##y/r/P03BVk9B21DBQCEeSKjUKXOlJmfkK6QpxJsoGANFDRXMFSwVLBTijRQMDRXiLSz@/wcA "J – Try It Online")
Because J's shape operator `$` fills cyclically, when we shape it to the length `#` of the input, it does exactly what we want, and we can just add it to the input `]`
[Answer]
## C++, ~~93~~ ~~85~~ ~~83~~ 63 bytes
```
auto w=[](auto&i){for(int j=0;j<i.size();j+=2)i[j]+=j%4?-1:1;};
```
-8 bytes, thanks to [this answer](https://codegolf.stackexchange.com/a/135262/72535), i discovered that lambda parameters can be `auto` and you can pass with the correct parameter, it will work
-2 bytes thanks to Nevay
-2 bytes thanks to Zacharý
I removed the `vector` include. You will need to pass as argument to w a container that respect the following conditions :   
* Have a method called `size` with no arguments
* Have overloaded the subscript operator
STL Containers that respect the following conditions are `array`, `vector`, `string`, `map`, `unordered_map`, and maybe others
If outputting by modifying arguments arguments is not allowed, then :
## C++, ~~112~~ 110 bytes
```
#include<vector>
std::vector<int>w(std::vector<int>i){for(int j=0;j<i.size();j+=2)i[j]+=(j%4)?-1:1;return i;}
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 30 bytes
```
a->[a[x]+imag(I^x)|x<-[1..#a]]
```
[Try it online!](https://tio.run/##LYrBCsIwEER/ZaiXBHdLo4IRtHe/Iaywl5aASig9RPDfY1KEYZg3M0mXyHMqE25FeQwasuzjS2dzf2T7zVcOru93KlI0pefHKHhEWuJ7rbFr0GEyai0hhEGqs9v8RDgSBoIjnAkXgifwoXIt2Pt2GrbDX62okxOx5Qc "Pari/GP – Try It Online")
[Answer]
# Dyalog APL, 13 bytes
```
⊢+1 0 ¯1 0⍴⍨≢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24RHXYu0DRUMFA6tB5KPerc86l3xqHMRUA4oYqJgDJQxVDBXsFSwAPKNFAwNgZSFBQA)
**How?**
`1 0 ¯1 0` - the array [1, 0, -1, 0]
`⍴⍨≢` - reshape to the length of the input, cyclic
`⊢+` - vectorized sum with the input
[Answer]
# [Ruby](https://www.ruby-lang.org/), 38 bytes
```
->a{a.zip([1,0,-1,0].cycle).map &:sum}
```
[Try it online!](https://tio.run/##KypNqvxfnlhm@1/XLrE6Ua8qs0Aj2lDHQEcXSMTqJVcm56Rq6uUmFiioWRWX5tb@LygtKVYAaoiONoiN1cvMKy5ITS7hQojqGmIXNtFRMNZRMNBRMNRRMNdRsNRRsNBR0DUC8oECuhYWCF0KSNoMwFqgCEkJGkDSATQNyQX/AQ "Ruby – Try It Online")
[Answer]
# D, 56 bytes
```
void w(T)(T[]i){for(T j;j<i.length;j+=2)i[j]+=j%4?-1:1;}
```
[Try it online!](https://tio.run/##HYtBCoMwFETX9RR/U0jwR6oVaptKL@EuZCFo6w@aFBvqQjx7mroYhveY6UL4OupgYQ1njdLE16ebWQNGmjtlY29ffpAmrQtOyui0NsfyIfJbLrdkP04tWcZhTQ40vd3s4eO7LIacjMp6paGFGpQoEc4IJ4Qc4YJwRagQRBE5ClFVOu4X1vJ/zeT70e6whfAD)
This is a port of [HatsuPointerKun's C++ answer](https://codegolf.stackexchange.com/a/135186/55550), so don't forget about them!
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), ~~11~~ 10 bytes
Takes advantage of Japt's index wrapping.
```
Ë+[1TJT]gE
```
[Test it](https://ethproductions.github.io/japt/?v=1.4.5&code=yytbMVRKVF1nRQ==&input=Wy00LCAzLCAwLCAxLCA3LCA5LCA4LCAtMiwgMTEsIC04OF0=)
---
## Explanation
Implicit input of array `U`.
```
Ë
```
Map over the array.
```
+
```
To the current element add...
```
gE
```
The element at the current index (`E`)...
```
[1TJT]
```
In the array `[1,0,-1,0]`.
[Answer]
# [Perl 6](http://perl6.org/), ~~28~~ 22 bytes
~~{((1+0i,*×i...*)Z+$\_)».re}~~
```
(*Z-(i*i,*i...*))».re
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPtfQytKVyNTK1NHK1NPT09LU/PQbr2i1P/WCsWJlQppGnGGBpr/AQ "Perl 6 – Try It Online")
`i*i, *i ... *` produces an infinite list of the numbers `-1, -i, 1, i` repeateded in a cycle. Those numbers are zipped with subtraction (`Z-`) with the input list (`*`), and then the real components of the resulting complex numbers are extracted (`».re`).
[Answer]
# [Actually](https://github.com/Mego/Seriously), 11 bytes
```
;r⌠╦½*C≈⌡M¥
```
[Try it online!](https://tio.run/##S0wuKU3Myan8/6hnwX/rIiD5aOqyQ3u1nB91djzqWeh7aOl/EJX5PzraIFYnWtcQRJjoKBjrKBjoKBjqKJjrKFjqKFjoKOgaAflAAV0LC6AaA7A8FAH5QAnD2FgA "Actually – Try It Online") (runs all test cases)
Explanation:
```
;r⌠╦½*C≈⌡M¥
;r           range(len(input))
  ⌠╦½*C≈⌡M   for each value in range:
   ╦½*C      cos(pi/2*value)
       ≈     floor to integer
          ¥  pairwise addition of the input and the new list
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 11 bytes
```
.e+bss^.j)k
```
[Try it online!](https://pyth.herokuapp.com/?code=.e%2Bbss%5E.j%29k&input=%5B-4%2C+3%2C+0%2C+1%2C+7%2C+9%2C+8%2C+-2%2C+11%2C+-88%5D&debug=0)
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 15 bytes
```
l~_,,[1TW0]f=.+
```
[Try it online!](https://tio.run/##S85KzP3/P6cuXkcn2jAk3CA2zVZP@///aAMFKIwFAA "CJam – Try It Online")
[Answer]
# [Math.JS](http://mathjs.org/), 34 bytes
```
f(k)=k.map(j(x,y,z)=x+im(i^y[1]))
```
## Explained
```
f(k)=k.map(j(x,y,z)=x+im(i^y[1]))
f(k)=                               # Define a function f, which takes argument k.
     k.map(                     )   # Map k to a function
           j(x,y,z)=                # Function j. Takes arguments x, y, and z. Where x is the item, y is the index in the form [i], and z is the original list.
                      im(      )    # The imaginary component of...
                         i^y[1]     # i to the power of the index.
                    x+              # x +, which gives our wave.
```
[Try it Online!](https://a-ta.co/math/&ZihrKT1rLm1hcChqKHgseSx6KT14K2ltKGleeVsxXSkpCnByaW50KAogICAgZihbMSwyLDMsNCw1XSkKKQo=)
[Answer]
# [8th](http://8th-dev.com/), ~~96~~ 63 bytes
**Code**
```
a:new swap ( swap 90 * deg>rad n:cos int + a:push ) a:each drop
```
This code leaves resulting array on TOS
**Usage and examples**
```
ok> [0,0,0,0,0] a:new swap ( swap 90 n:* deg>rad n:cos n:int n:+ a:push ) a:each drop .
[1,0,-1,0,1]
ok> [-4,3,0,1,7,9,8,-2,11,-88] a:new swap ( swap 90 * deg>rad n:cos int + a:push ) a:each drop .
[-3,3,-1,1,8,9,7,-2,12,-88]
```
**Explanation**
We use cos(x) in order get the right sequence [1,0,-1,0]. Each array element's index is multiplied by 90 degrees and then it is passed to cos() function to get the desired "wave factor" to be added to the corresponding item.
```
: f \ a -- a
  a:new    \ create output array
  swap     \ put input array on TOS
  \ array element's index is passed to cos in order to compute
  \ the "wave factor" to add to each item
  ( swap 90 n:* deg>rad n:cos n:int n:+ 
  a:push ) \ push new item into output array 
  a:each
  drop     \ get rid of input array and leave ouput array on TOS
;
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 50 bytes
```
n=>{for(int i=0;i<n.Length;i+=2)n[i]+=i%4<1?1:-1;}
```
[Try it online!](https://tio.run/##VY3BagIxFEX3@YqHIEwwEccKjmZiKd22qy66EBchxpk36AudpJYS8u3T4K7Le@CeY4O0fnTTd0Dq4OM3RHdTzF5NCPCVWIgmooW7xzO8G6SKJ/ZiI3pqkeLxdIBOT6QP6eLHqhBAvVLY0vLNURd7hQu95nTE00LjfNPWz/Ve1ipPit3NCIMm9wMPUZIbAU8CVgJqAVsBOwGNALkuuwDZNFmxrhq4YiXljO0fub68YeDp1VPwV7f8HDG6qufqP5gJmHGVWc7THw "C# (.NET Core) – Try It Online")
Uses a simple lambda. Modifies the original array and returns the output through reference.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 16 bytes
```
vy3L2.SR0¸«Nè+})
```
[Try it online!](https://tio.run/##MzBNTDJM/f@/rNLYx0gvOMjg0I5Dq/0Or9Cu1fz/P9pABwxjAQ "05AB1E – Try It Online")
---
`3L2.SR0¸«` is the shortest thing I can think of for `sin(x % 4)` in 05AB1E.
[Answer]
# [Arturo](https://arturo-lang.io), 33 bytes
```
$=>[i:0map&=>[&-((i%4)-1)%2'i+1]]
```
[Try it](http://arturo-lang.io/playground?mAebjN)
Port of ETHproductions' [JavaScript answer](https://codegolf.stackexchange.com/a/135135/97916).
[Answer]
# [Zsh](https://www.zsh.org/), 34 bytes
```
for i;echo $[++j%2*(j%4>2?-1:1)+i]
```
[Try it online!](https://tio.run/##NYrBDoIwGIPvPEUPkIDLEv45dbBEeQ/iyTDYDpIwvYg8@/w5mKZNv7SfOCVXVuv7GYcXPIIdmZKbF3g7PKYZeS9EKNShDIW@qpuklirh72mzI/Luu8Qtyxw0TjjjAoOGqWZL2kPjiBrES8ObVCCCNGb//MWdQOkH "Zsh – Try It Online")
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 9 bytes
```
ĐŁřπ*₂šƖ+
```
[Try it online!](https://tio.run/##K6gs@f//yISjjUdnnm/QetTUdHThsWna//9H65roKBjrKBjoKBjqKJjrKFjqKFjoKOgaAflAAV0Li1gA "Pyt – Try It Online")
```
Đ            implicit input; Đuplicate
 Ł           get Łength
  ř          řangify
   π*₂       multiply by pi/2
      š      take šin
       Ɩ     cast to Ɩnteger
        +    add the two arrays element-wise
```
]