This is an application to Faraday's and Lenz' laws of electromagnetic induction. So as the magnet moves into the coil, the magnetic field from the magnet moves through the coil, therefore there is a change in flux linkage through the coil. It can then be seen from Faraday's law that an emf, with its magnitude being directly proportional to the rate of change of flux, is induced. Then we can use Lenz' law to work out the direction of our current, which states that the direction of the emf is such that if a current was able to flow then that current will generate a magnetic field that opposes it. Since the coil is in a closed circuit an emf, and therefore a current is produced where if we look through the side of the coil the magnet is entering, the current will be in an anti-clockwise direction. Then as the magnet leaves, there is still a change of magnetic flux which again, the magnitude of the emf is proportional to the rate of change of flux. But as Lenz' law still applies, the magnetic field produced by the current must be such that it still opposes the change. Therefore the magnetic field is now reversed, thus the current must also be reversed. So looking from the same end of the coil as before, the current is now in the clockwise direction.