The physics
On a smooth track, no outside force pushes along the track. So the total momentum of the carts stays the same through a hit.
m₁u₁ + m₂u₂ = m₁v₁ + m₂v₂
Kinetic energy is a different story. The bumpers squeeze, then push back. Only part of the energy comes back. The rest turns into heat and sound.
The coefficient of restitution e says how much comes back. Separation speed = e × approach speed.
v₂ − v₁ = e (u₁ − u₂)
With e = 1 the hit is elastic, and no KE is lost. With e = 0 the carts stick and move on together. That loses the most KE.
Two equal masses in an elastic hit swap their velocities. A light spring between two blocks squeezes the most at one moment. At that moment both blocks move at the same speed.
most squeeze: ½kx² = ½ μ (u₁ − u₂)², with μ = m₁m₂ / (m₁ + m₂)
Take right as +. A cart moving left has a negative velocity, and negative momentum.