I don't understand this idea. My terxtbook says that Fermat's principle is that light travels by the path that takes the least amount of time. Does that mean that light will go in crazy, curved paths if those are faster? How does it "know" which path will be the fastest? For example, let's say I'm shining a flashlight towards a block of some medium with a really high index of refraction, so light traveling in this medium goes really slowly. If light is going in a straight line from the flashlight to a point directly behind the medium, it's going to take a long time to get there. On the other hand, if it follows a curved path up and over the medium, then down behind it, the total time would be much less. Is that what happens?