---
# System prepended metadata

title: Untitled

---

find the final state of a system of asteroids (an array) after all possible collisions
if asteroids with
- negative values are moving left
- postive values are moving right
- absolute value of asteroid is its weight (will always be >0)

```go
a1 := []int{ 5, 1, -5, 6 }
```

in the above example the system a1 has 4 asteroids
1. an asteroid of size 5 moving right (5)
2. an asteroid of size 1 moving right (1)
3. an asteroid of size 5 moving left (-5)
4. an asteroid of size 6 moving right (6)


when two asteroids collide
1. if they are of same size, both are destroyed
2. if they are of unequal size, the larger survives in its entirety

so
```go
// end result for a1
a1FinalState := []int{ 6 }
```
1. asteroid -5 collides with asteroid 1
    -  asteroid 1 is destroyed
    -  asteroid -5 continues its leftward journey
3. asteroid -5 collides with asteroid 5
    - both asteroid 5 and asteroid -5 are destroyed


more examples -
```go
a2 := []int{ -3, 4, -2, 1 }
a2FinalState := []int { -3, 4, 1 }

a3 := []int { 7, -4, -4, -8 }
a3FinalState := []int{ -8 }
```