Skip to main content
2 of 3
added 208 characters in body
nimi
  • 36k
  • 4
  • 35
  • 100

Haskell, 47 57 bytes

e#(a:b)|e==a= -2*a:b|1<2=e:a:b
e#_=[e]
map abs.foldr(#)[]

Uses reduce (or fold as it is called in Haskell). Usage example: map. abs.foldr(#)[] $ [2,2,2,4,4,8] -> [2,4,8,8].

Edit: +10 bytes to make it work for unsorted arrays, too. Merged numbers are inserted as negative values to prevent a second merge. They are corrected by a final map abs.

nimi
  • 36k
  • 4
  • 35
  • 100