Apply a wave to an array
LOGO, 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
Haskell, 26 bytes
zipWith(+)$cycle[1,0,-1,0]
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
Mathematica, 26 23 22 bytes
Im[I^Range@Tr[1^#]]+#&
Try it online! (Mathics)
Note: The TIO link is for the 23-byte version, the 22-byte version is not Mathics-compatible.