Sum of neighbours

Python, 25 bytes

lambda a:sum((a*3)[1:-1])

To see why this works, rotate the expansion in the OP by 45 degrees:

             1 + 2                        
           + 1 + 2 + 3                            2 + 3 + 4 + 5
               + 2 + 3 + 4          =       + 1 + 2 + 3 + 4 + 5
                   + 3 + 4 + 5              + 1 + 2 + 3 + 4.
                       + 4 + 5

Python 2, 28 bytes

lambda a:sum(a)*3-a[0]-a[-1]

Just 3 times the sum and minus one of each end element


MATL, 5 bytes

7BZ+s

Try it online!

Explanation

7B  % Push array [1, 1, 1], obtained as 7 in binary
Z+  % Take input implicitly. Convolve with [1, 1, 1], keeping size
s   % Sum of resulting array. Display implicitly

Tags:

Code Golf