Challenge
Given a list of integers, return the list of these integers after repeatedly removing all pairs of adjacent equal items.
Note that if you have an odd-length run of equal numbers, one of them will remain, not being part of a pair.
Example:
[0, 0, 0, 1, 2, 4, 4, 2, 1, 1, 0]
First, you should remove 0, 0
, 4, 4
, and 1, 1
to get:
[0, 1, 2, 2, 0]
Now, you should remove 2, 2
:
[0, 1, 0]
And this is the final result.
Test Cases
[] -> [] [1] -> [1] [1, 1] -> [] [1, 2] -> [1, 2] [11, 11, 11] -> [11] [1, 22, 1] -> [1, 22, 1] [-31, 46, -31, 46] -> [-31, 46, -31, 46] [1, 0, 0, 1] -> [] [5, 3, 10, 10, 5] -> [5, 3, 5] [5, 3, 3, 3, 5] -> [5, 3, 5] [0, -2, 4, 4, -2, 0] -> [] [0, 2, -14, -14, 2, 0, -1] -> [-1] [0, 0, 0, 1, 2, 4, 4, 2, 1, 1, 0] -> [0, 1, 0] [3, 5, 4, 4, 8, 26, 26, 8, 5] -> [3] [-89, 89, -87, -8, 8, 88] -> [-89, 89, -87, -8, 8, 88]
Scoring
This is code-golf, so the shortest answer in each language wins!
[14, 14, 14]
collapses to[14]
\$\endgroup\$1,2
,11,12
, etc.) \$\endgroup\$-89,89,-87,-8,-88
? Both my (unposted) Japt solution and Fry's Retina solution fail there, outputting--87,8
. \$\endgroup\$