THE PUZZLET PAGE

PUZZLET 067 - THE SOLUTION


' Puzzlet #067
' A driver makes a journey and  returns
' by a different route.  The speeds for
' the outward and return journies  were
' different,  but both averaged between
' 50 and 60 mph, taking between 2 and 3
' hours  each way.  All speeds are  odd
' integers, and the times are exact odd
' numbers of minutes.  By  coincidence,
' the total mileage turns out be 300
' exactly. What is the speed
and time for
' each part of the trip?

' By Dave Ellis.

declare PrintResult()
def speed1, speed2: int
def time1, time2: int
def sum: int

openconsole
print "      Outbound           Return"
print
print "spd  mins  miles   spd  mins  miles"
print

for speed1 = 51 to 57 #2
    for speed2 = speed1 + 2 to 59 #2
        for time1 = 121 to 177 #2
            for time2 = time1 + 2 to 179 #2
                sum = speed1*time1 + speed2*time2
                if sum = 18000
                    PrintResult()
                endif
            next time2
        next time1
    next speed2
next speed1

print: print "No More!"
print
: print "Press a key to exit... ",
do: until inkey$ <> ""
closeconsole
end


sub
PrintResult
' pretty printer
def miles1, miles2: float
miles1 = speed1 * time1/60
miles2 = speed2 * time2/60
print speed1, "  ", time1, " ", miles1,
print "  ", speed2, "  ", time2, " ", miles2
return
       

PROGRAM NOTES


Let's start by looking at the speed range. Both speeds average between 50 and 60 mph, and both are odd. Therefore, all possible combinatiobns will be covered by the nested loops:

for speed1 = 51 to 57 #2
    for speed2 = speed1 + 2 to 59 #2


The time range can be treated in a similar way. Both were between two and three hours. Working in minutes, all possible combinations will be covered by the nested loops:

for time1 = 121 to 177 #2
    for time2 = time1 + 2 to 179 #2

Next, we need to remind ourselves that distance = time x speed. Since we are working with minutes rather than hours, the distance value will be 60 times too large. Thus, instead of looking for a 300 mile total, we need to look for an 18,000 mile total. This is all calculated and stored in variable sum:

sum = speed1*time1 + speed2*time2

All that's needed now is to test sum:

if sum = 18000
     PrintResult()
endif


That's all there is to it!  One of our simpler Puzzlets.

When you run the program, it will generate the inset screen. 

There are two solutions, one on each of the two lines.

      Outbound         Return

spd  mins  miles   spd  mins  miles

51   169   143.65  53   177   156.35
57   145   137.75  59   165   162.25

No more!

Press any key to exit ...



MAIN MENU
DOWNLOAD CODE
ARCHIVES


Site design/maintenance: Dave Ellis E-mail me!
Last Updated: February 22nd, 2004.