Shifting and adding the columns of two lists
a = {{-2, 1}, {-1, 2}, {0, 1}, {1, 0}, {2, 0}}
before = a[[All, 2]];
a[[All, 2]] = RotateLeft[a[[All, 2]], 3];
a[[All, 2]] = a[[All, 2]] + before;
Now a
is your c
Step-By-Step
(a = {{-2, 1}, {-1, 2}, {0, 1}, {1, 0}, {2, 0}}) // MatrixForm
before = a[[All, 2]];
a[[All, 2]] = RotateLeft[a[[All, 2]], 3];
(b = a) // MatrixForm
b[[All, 2]] = b[[All, 2]] + before;
(c = b) // MatrixForm
SubsetMap[RotateRight[#,2]&, a, {All,2}]
{{-2, 0}, {-1, 0}, {0, 1}, {1, 2}, {2, 1}}
%==b
True
For Part 2, see this recent question
'Borrowing from the neat answer given by David Keith:
Transpose[{a[[All,1]],(a+b)[[All,2]]}]==c
True
Alternatively:
a+ArrayFlatten[{{0, List/@b[[All,2]]}}]==c
True
SubsetMap[Reverse, a, {All, 2}] == b
True
SubsetMap[# + Reverse @ #&, a, {All, 2}] == c
True
Or get b
and c
in a single step:
Rest @ FoldList[SubsetMap[#2, #, {All, 2}] &, a, {Reverse, # + Reverse @ # &}] == {b, c}
True