I see that both Soroban and Mr. Fantastic are assuming the two towns are on the same side of the river. With that, it follows that distance "along the river" from A to B (from the point where the perpendicular from A meets the river to the point where the perpendicular is 12 miles.
But I would do this in a completely different way (especially if you are cannot use "Calculus"): using a "reflection". That is, imagine that B' is 6 miles from the river but on the
opposite side of the river from B. Obviously (I hope it is obvious!) the shortest distance from A to B' is a straight line. We can determine where that line crosses the river by "similar triangles"- the triangle formed by A, foot of perpendicular from A to the river, point where the straight line from A to B' crosses the river is similar to the corresponding B' triangle. That follows from the "vertical angles" theorem- where lines cross (the line from A to B' and the river) angles across from one another are congruent.
If we let the distance from where the perpendicular from A hits the river to the point where the line AB' crosses the river be "x" then the distance from that point to where the perpendicular from B hits the river is 12- x. So we have

so 11(12- x)= 132- 11x= 6x or 5x= 132 and x= 132/5= 26.4 miles.
Now you can show that this point is also correct for the shortest total distance between A and B. The two triangles, with B' and B are congruent so the distance from that crossing point on the river to B' is the same as from that point to B.