
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.