Task
Your task is to take an array of numbers as input, and produce a new one where each number has been shifted both right and left, leaving 0
s if no number fills a spot. This process can be represented graphically like this:
[x]
/ | \
[x, 0, x]
This is done with every number in the list, with overlapping numbers being added. A list with two numbers would look like this:
[x, y]
/ \/ \
/ /\ \
[x, y, x, y]
With three numbers, you start to get overlaps, and addition:
[x, y, z]
/ \/ \/ \
/ /\ /\ \
[x, y, x+z, y, z]
Example
A simple example is [1]
gives [1, 0, 1]
because
[1]
/ \
/ \
[1, 0, 1]
Another example
[1, 2]
/\ /\
/ X \
/ / \ \
[1, 2, 1, 2]
Another example
[1, 2, 3]
/\ /\ /\
/ X X \
/ / \/ \ /\
[1, 2, 4, 2, 3]
Image:
Test cases
[1,2,3] => [1,2,4,2,3]
[4,2] => [4,2,4,2]
[1] => [1,0,1]
[7,4,5,6] => [7,4,12,10,5,6]
[1,2,4,2,1] => [1,2,5,4,5,2,1]
[1,0,1] => [1,0,2,0,1]
[1,0,2,0,1] => [1,0,3,0,3,0,1]
[8,7,6,5,4] => [8,7,14,12,10,5,4]
[1,4,9,16] => [1,4,10,20,9,16]
[1,2] => [1,2,1,2]