THE PUZZLET PAGE

PUZZLET 071 - THE SOLUTION


' Puzzlet #071
' A quadratic equation has the form ax^2 + bx + c = 0.
' a is a 1-digit integer.
' b is a 2-digit integer.
' c is a 3-digit integer.
' The discriminator (b^2 - 4ac) equals 8464.
' The roots of the equation are both integers.
' Find the roots.
' By Dave Ellis.

declare PrintResult()
def a, b, c: int
def disc, root1, root2: int

openconsole
print "Searching ...": print
print "Root1  Root2  a   b   c": print

for a = 1 to 9
    for b = 10 to 99
        for c = 100 to 999
            disc = b^2 - 4*a*c
            if disc = 8464
                root1 = -b/2 - 46
                root2 = -b/2 + 46
                PrintResult()
            endif
        next c
    next b
next a

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


sub 
PrintResult
' pretty printer
print " ", root1, "    ", root2,
print "  ", a, " ", b, " ", c
return



PROGRAM NOTES

The three constants a, b, and c are represented directly by variables a, b, and c.  The discriminant is reperesented by variable disc

By using three nested loops for
a, b, and c, and using the ranges for them given in the question itself, we can easily search though all possible combinations. For each one of these combinations, the discriminat is calculated.  If it comes out to 8464, we have a result.

Before printing the result, we need to work out the roots of the equation.  This is easily derived from the well-known fomula solution to quadratics:


formula

At this stage, we've come up with values for a, b, and c to make the discriminator equal to 8464.  Half the square root of this is 92/2 = 46.  So the roots will be -b/2 ± 46, and these are the values calculated and then printed out by the subroutine PrintResult().
When you run the program, it generates the inset screen. 

So there are, in fact, 2 possible answers, each one from a different generating equation.


Searching ...

Root1  Root2  a    b    c

 - 94       - 2     1   96  188
 - 95       - 3     1   98  285

No more!

Press any key to exit ...


Taking the two answers to the Puzzlet, (-2, -94) and (-3, -95)., and working back to the original equations, you get:

Solution
Equation
Products
Roots
#1
x^2 + 96x + 188 = 0
(x + 2)(x + 94) = 0 -2, -94
#2
x^2 + 98x + 285 = 0
(x + 3)(x + 95) = 0 -3, -95



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