I have a list of ordered pairs:
{{1, 1}, {1, 2}, {2, 4}, {1, 2}, {1, 2}, {2, 4}, {2, 4}, {2, 4}, {4, 4}}
If two pairs {x_1, y_1}
and {x_2, y_2}
are such that y_1 = y_2
, then I want to "combine" them by adding x_1 + x_2
to create the pair {x_1 + x_2, y_1}
.
For the 9 ordered pairs above, the desired final result would be:
{{1, 1}, {3, 2}, {12, 4}}
I have tried using Sort
and Tally
but without success.