I used the equation because this is a simple case and I know the equation.
For all general type of simulations, what you need to do is make dt become negative value and you can reverse the time.
You can add code to ask the program to stop at any point you want.
So you can change direction of time when you program the simulation - You are the GOD of your simulation - you can do whatever you want with your simulation : You just need to figure a way to do it! (It is how we use our mind to make it work -- this is more important than always depend on library from others.)