In math class, you learned to "solve" equations by doing algebra.
Algebra is complex and difficult and
requires clever thinking skills to do correctly. Computers are
certainly not "clever". Computers do things
by following specific commands, not by "thinking" and certainly not by
doing algebra (well, there
actually are artificial intelligence systems
that can do algebra, but these are not very common).
Computers ARE good at performing calculations quickly and
accurately. Combined with human
cleverness, they can be used to solved difficult problems, even problems
involving very large numbers
and complex calculations.
A common method for solving problems is GUESS
and CHECK. The human tries to guess the
answer, and the computer checks whether the guess was correct or
not. In the example program above,
the numbers 8 and -4 weren't actually "guesses", but they were the
result of some algebra.
Still, the computer did the calculations to check the answers, and one
of them was wrong.
Consider a more difficult problem - find a number X so that 2X
- X = 100 .
We could guess X = 7, which gives 27 - 7 = 128 -
7 = 121. So we would try a smaller number.
Here is a program that makes guessing and checking quicker.
float x = 7;Try it
println( Math.pow(2,x) - x );