Step-by-step explanation:
So if two magnets are pointing with unlike-poles together (north pole to a south pole), then bringing them closer together decreases the energy stored up in the magnetic field. They will be pushed in the direction that decreases the amount of stored-up energy.