You will see in the image above, on the first square of the grid, the outer dice add up to 5, on the square ahead, the middle dice is 5, so you need to go to that middle dice.
Once on the second square, the outer dice add up to 1, and the square straight ahead again has a middle dice with a number 1.
Keep following this pattern, adding up the outer dice and finding a middle dice that matches, eventually the path will take you all the way to the exit door, that will hopefully still be open!
Most of the routes will go through the whole room, using most of the squares to make the route, you may miss out 2 or 4 squares, you will never use the same square twice (as this would just create a loop).
If the door closes on you, it is best to finish your route til you get to the door anyway to learn it before starting again. The route will be the same until you reset the puzzle with the lever by Simons desk or exit the dungeon. So you can keep trying with the same route until you are fast enough to make it to the door at the end and loot the chest!
Here is a video of a math puzzle run..