THE PUZZLET PAGE

PUZZLET 062 - THE SOLUTION


' Puzzlet #062
' A triangle has integer sides of consecutive
' lengths  If a line is drawn at right angles
' from the medium-length side to the opposite
' vertice, it will have an integer value one
' less than the shortest side's length.
' What are the least lengths of the sides and
' line of the triangle as described?
' By Dave Ellis.

def flag, side: int
def sideA, sideB: float
openconsole
side = 3
flag = 0

do
    sideA = sqrt(6*side - 3)
    sideB = sqrt(2*side - 3)
    if sideA + sideB = side
        flag = -1
        print "Sides: ",
        print side -1, side, side + 1
        print: print "Line: ",
        print side - 2
    else
        side = side + 1
    endif
until flag

print: print "Press a key ... ",
do: until inkey$ <> ""
closeconsole
end


PROGRAM NOTES


The base of the triangle is bisected by the vertical.  For convenience, I'm going to call the two parts Side A and Side B, as shown in the sketch below.

Triangle_2

This gives us two right-angled triangles, with a common vertical. Using pythagorus, we can say:

SideA = (Side + 1)2 - (Side - 2)2
            = Side2 + 2*Side + 1 - Side2 + 4*Side - 4
            = 6*Side - 3

Similarly,

SideB = (Side - 1)2 - (Side - 2)2
            = Side2 - 2*Side + 1 - Side2 + 4*Side - 4
            = 2*Side - 3

We now have a method of finding both Side A and Side B in terms of Side.  All me have to do is try practical values of Side to obtain simultaneous values for Side A and Side B.  If the sum of these values is also Side, we've solved the Puzzlet.

What are "practical" values for Side? Firstly, they must be integers as stated in the problem.  Secondly, the minimum value will be 3, since we know the vertical is an integer and 2 less than Side. We don't need to worry about a maximum value for Side, just keep incrementing it from 3 until the solution pops out.

The bit of code that does all this is:

do
    sideA = sqrt(6*side - 3)
    sideB = sqrt(2*side - 3)
    if sideA + sideB = side

When the "if" line is satisfied, variable flag is set to -1 (TRUE) and the results printed out.  At the end of the DO loop, flag is examined.  If it's still FALSE, variable side is incremented and the loop executed again. If it's TRUE, the loop is exited and the program stops.

When you run the code, it generates the screen shown inset.  You could probably have solved this by trial and error, but the coded solution is satisfyingly elegant!

Sides: 13 14 15

Line: 12

Press a key ...


MAIN MENU
DOWNLOAD CODE
ARCHIVES


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