The time difference between driving at 60 mph and 40 mph is 45 minutes, which is 3/4 of an hour. So, the equation for the time you spent driving is:

time = (rate * time_difference) / (rate - new_rate)

Plugging in the known values, we get:

time = (40 mph * 3/4 hours) / (40 mph - 25 mph)

time = 7.5 hours

Since the rate is in miles per hour and the time is in hours, the distance traveled is simply the product of the two:

distance = rate * time

distance = 40 mph * 7.5 hours

distance = 300 miles

Therefore, you drove 300 miles to the beach.