Give the provided information, we can't know the speed of the swimmer, but let's suppose the swimmer swims at a speed of $v$ miles per hour. That is, if the water would not flow, she swims at $v$ miles per hour. Since the hat flows with the water, that means that as the swimmer swims upstream, the distance between the hat and the swimmer increases at exactly that $v$ miles per hour. So, swimming back, the swimmer decreases the distance with exactly $v$ miles per hour as well. So, if she swam upstream for one hour, it'll take that one hour to catch back up.
The key to solving this puzzle is therefore to look at the movement of the swimmer relative to the river as a 'whole'. That is, if we look at the movement of the swimmer relative to all of space, the swimmer goes through space at an enormous speed, since the swimmer is located n planet Earth, which hurtles through space at a good clip ... and our solar system moves at great speed relative to the center of our galaxy, etc. etc. So thinking about these kinds of things, we recognize that 'speed' is always relative to something. Now, here on Earth, and for day to day purposes, most of the time we think of and measure speed relative to the 'surface' of the Earth. Indeed, that's is exactly the perspective you are asked to take when asked the speed of the river: that's relative to the river bank, or bridge, or river bed, or anything that's in a 'fixed' position as far as the earth surface goes.
OK, but for solving this puzzle, it is better to take think about the movement of the hat and swimmer relative to the river as a whole. That is, we can think of the river as a kind of 'snake' that moves, as a whole, relative to the Earth's surface. However, how does the hat and swimmer move relative to this 'snake'? Well, relative to the river, the hat remains at a fixed position; it's as if it is 'attached' to the snake. The swimmer, however, moves with a certain speed relative to this river; think of it as 'crawling' along the skin of the snake. And we can assume that is the same relative speed as if the swimmer is in standing water, i.e. in a lake or pool. And, when the swimmer turns around, the swimmer moves at exactly that same speed relative to the river again, just in the opposite direction. So, thinking about it that way, it really is analogous to the situation where she would dive in a lake, lose the hat right where she dove in, swim for an hour into the lake, and then turns around: how long does it take to get back to the hat? An hour of course!
The book is making a mistake. That entire second half is nonsense, and the formula is incorrect.
In particular, it’s impossible to determine the speed of the river since there is no unit of distance in the original problem. For example, doubling all (non-specified) velocities and distances will give the exact same times.
This does give one nice way to solve the problem. You can choose any nice value of the distance (or do as they did by making up a nonsensical formula to get some random $x$), and then use that to solve for the time.
Here’s an example using that method with different numbers. $120$ is a nice number since $15$ and $20$ divide it and the ratios are even. Let’s define a mile as $1/120$ the distance, so by definition, they are $120$ miles apart. Then, it moves at $120/20=6$ mph against the river and $120/15=8$ mph with the river, so the boat moves $(6+8)/2=7$ mph and the river travels at $(8-6)/2=1$ mph. Thus, without current the trip takes $120/7=17.1428\dots$ hours as desired.
Note that the original problem from Henry Dudeney (compiled by Martin Gardner) specifies the speed, so the exact distances could be computed and were relevant. I suspect that the writer removed them when he saw they weren’t essential to the core of the problem but didn’t properly fix his solution.
Best Answer
Your math is correct. Here's an illustration I made to go with it: